simple_multistep-8.x-1.x-dev/tests/src/Functional/CreateArticleWithStepGroups.php

tests/src/Functional/CreateArticleWithStepGroups.php
<?php

declare(strict_types=1);

namespace Drupal\Tests\simple_multistep\Functional;

use Drupal\Tests\BrowserTestBase;

/**
 * Tests for creating an article with step groups.
 *
 * @group simple_multistep
 */
class CreateArticleWithStepGroups extends BrowserTestBase {

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * Modules to install.
   *
   * @var array
   */
  protected static $modules = ['simple_multistep_test'];

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();

    // Create a new admin user.
    $admin_user = $this->drupalCreateUser([
      'access content',
      'create article content',
    ]);
    // Login the user.
    $this->drupalLogin($admin_user);
  }

  /**
   * Test adding an article with multistep.
   */
  public function testCreateArticleWithStepGroups() {
    // Visit the create article form.
    $this->drupalGet('node/add/article');
    $this->assertSession()->statusCodeEquals(200);

    // Test step 1.
    $this->assertSession()->pageTextContains('Title');
    $this->assertSession()->pageTextContains('Step 1');
    $this->assertSession()->pageTextContains('Step 2');
    $this->assertSession()->buttonNotExists('Back');
    $title = $this->assertSession()->fieldExists('edit-title-0-value');
    $title->setValue('Test title');
    $next = $this->assertSession()->buttonExists('Next');
    $next->press();

    // Test step 2.
    $title_wrapper = $this->assertSession()->elementExists('css', '#edit-title-wrapper');
    $title_wrapper->hasAttribute('hidden');
    $this->assertSession()->pageTextContains('Body');
    $this->assertSession()->buttonNotExists('Next');
    $body = $this->assertSession()->fieldExists('edit-body-0-value');
    $body->setValue('Test body.');
    $back = $this->assertSession()->buttonExists('Back');
    $back->press();

    // Back to test of step 1.
    $this->assertSession()->fieldValueEquals('edit-title-0-value', 'Test title');
    $next->press();

    // Back to test of step 2.
    $this->assertSession()->fieldValueEquals('edit-body-0-value', 'Test body.');

    // Save the article and test.
    $save = $this->assertSession()->buttonExists('Save');
    $save->press();
    $this->assertSession()->pageTextContains('Test title');
    $this->assertSession()->pageTextContains('Test body.');
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc