public function ContentTmgmtEntitySourceUiTest::testSourceOverview

Test the handling existing content with continuous jobs.

File

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

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
    ->assertSession()
    ->pageTextContains($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
    ->submitForm($edit, 'Check for continuous jobs');
  $this
    ->assertSession()
    ->pageTextContainsOnce("1 continuous job item has been created.");
  $items = $continuous_job
    ->getItems();
  $item = reset($items);
  $this
    ->assertSession()
    ->linkByHrefExists('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
    ->assertEquals($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
    ->assertSession()
    ->pageTextContains($second_node
    ->getTitle());

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

  // Test that no new job items are created.
  $this
    ->assertCount(1, $continuous_job
    ->getItems(), '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
    ->submitForm($add_all_edit, 'Check for continuous jobs');
  $this
    ->assertSession()
    ->pageTextContainsOnce('2 continuous job items have been created.');

  // Test that two new job items are created.
  $this
    ->assertCount(3, $continuous_job
    ->getItems(), '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
    ->submitForm($add_all_edit, 'Check for continuous jobs');
  $this
    ->assertSession()
    ->pageTextContainsOnce('None of the selected sources can be added to continuous jobs.');

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