You are here

public function DevelGenerateBrowserTest::testDevelGenerateTerms in Devel 8.3

Same name and namespace in other branches
  1. 4.x devel_generate/tests/src/Functional/DevelGenerateBrowserTest.php \Drupal\Tests\devel_generate\Functional\DevelGenerateBrowserTest::testDevelGenerateTerms()

Tests generating terms.

File

devel_generate/tests/src/Functional/DevelGenerateBrowserTest.php, line 183

Class

DevelGenerateBrowserTest
Tests the logic to generate data.

Namespace

Drupal\Tests\devel_generate\Functional

Code

public function testDevelGenerateTerms() {

  // Generate terms.
  $edit = [
    'vids[]' => $this->vocabulary
      ->id(),
    'num' => 5,
    'title_length' => 12,
  ];
  $this
    ->drupalPostForm('admin/config/development/generate/term', $edit, 'Generate');
  $this
    ->assertSession()
    ->pageTextContains('Created the following new terms: ');
  $this
    ->assertSession()
    ->pageTextNotContains('translations');
  $this
    ->assertSession()
    ->pageTextContains('Generate process complete.');
  $this
    ->assertCount(5, \Drupal::entityQuery('taxonomy_term')
    ->execute());

  // Generate terms with translations.
  $edit = [
    'vids[]' => $this->vocabulary
      ->id(),
    'num' => 3,
    'add_language[]' => [
      'en',
    ],
    'translate_language[]' => [
      'ca',
    ],
  ];
  $this
    ->drupalPostForm('admin/config/development/generate/term', $edit, 'Generate');
  $this
    ->assertSession()
    ->pageTextContains('Created 3 term translations');

  // Not using 'kill' so there should be 8 terms.
  $terms = \Drupal::entityQuery('taxonomy_term')
    ->execute();
  $this
    ->assertCount(8, $terms);

  // Check the translations created (and not created).
  $term = Term::load(end($terms));
  $this
    ->assertTrue($term
    ->hasTranslation('ca'));
  $this
    ->assertFalse($term
    ->hasTranslation('de'));
  $this
    ->assertFalse($term
    ->hasTranslation('fr'));
}