You are here

public function ContentTmgmtEntitySourceUiTest::testSourceOverview in Translation Management Tool 8

Test the handling existing content with continuous jobs.

File

sources/content/tests/src/Functional/ContentTmgmtEntitySourceUiTest.php, line 944

Class

ContentTmgmtEntitySourceUiTest
Content entity source UI tests.

Namespace

Drupal\Tests\tmgmt_content\Functional

Code

public function testSourceOverview() {

  // Create translatable node.
  $node = $this
    ->createTranslatableNode('article', 'en');
  $this
    ->drupalGet('admin/tmgmt/sources');
  $this
    ->assertText($node
    ->getTitle());

  // Test that there are no "Add to continuous jobs" button and checkbox.
  $this
    ->assertSession()
    ->elementNotExists('css', '#edit-add-to-continuous-jobs');
  $this
    ->assertSession()
    ->elementNotExists('css', '#edit-add-all-to-continuous-jobs');

  // Create two additional nodes.
  $this
    ->createTranslatableNode('article', 'en');
  $this
    ->createTranslatableNode('article', 'en');

  // Continuous settings configuration.
  $continuous_settings = [
    'content' => [
      'node' => [
        'enabled' => 1,
        'bundles' => [
          'article' => 1,
          'page' => 0,
        ],
      ],
    ],
  ];

  // Create continuous job.
  $continuous_job = $this
    ->createJob('en', 'de', 0, [
    'label' => 'Continuous job',
    'job_type' => 'continuous',
    'continuous_settings' => $continuous_settings,
    'translator' => $this->default_translator
      ->id(),
  ]);

  // Test that there is now "Add to continuous jobs" button and checkbox.
  $this
    ->drupalGet('admin/tmgmt/sources');
  $this
    ->assertSession()
    ->elementExists('css', '#edit-add-to-continuous-jobs');
  $this
    ->assertSession()
    ->elementExists('css', '#edit-add-all-to-continuous-jobs');

  // Select node for adding to continuous job.
  $edit = [
    'items[' . $node
      ->id() . ']' => TRUE,
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Check for continuous jobs'));
  $this
    ->assertUniqueText(t("1 continuous job item has been created."));
  $items = $continuous_job
    ->getItems();
  $item = reset($items);
  $this
    ->assertLinkByHref('admin/tmgmt/items/' . $item
    ->id());

  // Test that continuous job item is created for selected node.
  $continuous_job_items = $continuous_job
    ->getItems();
  $continuous_job_item = reset($continuous_job_items);
  $this
    ->assertEqual($node
    ->label(), $continuous_job_item
    ->label(), 'Continuous job item is created for selected node.');

  // Create another translatable node.
  $second_node = $this
    ->createTranslatableNode('page', 'en');
  $this
    ->drupalGet('admin/tmgmt/sources');
  $this
    ->assertText($second_node
    ->getTitle());

  // Select second node for adding to continuous job.
  $second_edit = [
    'items[' . $second_node
      ->id() . ']' => TRUE,
  ];
  $this
    ->drupalPostForm(NULL, $second_edit, t('Check for continuous jobs'));
  $this
    ->assertUniqueText(t("None of the selected sources can be added to continuous jobs."));

  // Test that no new job items are created.
  $this
    ->assertEqual(count($continuous_job
    ->getItems()), 1, 'There are no new job items for selected node.');
  $this
    ->drupalGet('admin/tmgmt/sources');

  // Select all nodes for adding to continuous job.
  $add_all_edit = [
    'add_all_to_continuous_jobs' => TRUE,
  ];
  $this
    ->drupalPostForm(NULL, $add_all_edit, t('Check for continuous jobs'));
  $this
    ->assertUniqueText(t("2 continuous job items have been created."));

  // Test that two new job items are created.
  $this
    ->assertEqual(count($continuous_job
    ->getItems()), 3, 'There are two new job items for selected nodes.');
  $this
    ->drupalGet('admin/tmgmt/sources');

  // Select all nodes for adding to continuous job.
  $add_all_edit = [
    'add_all_to_continuous_jobs' => TRUE,
  ];
  $this
    ->drupalPostForm(NULL, $add_all_edit, t('Check for continuous jobs'));
  $this
    ->assertUniqueText(t("None of the selected sources can be added to continuous jobs."));

  // Test that no new job items are created.
  $this
    ->assertEqual(count($continuous_job
    ->getItems()), 3, 'There are no new job items for selected nodes.');
}