You are here

protected function EmbeddedScheduledUpdateTypeTestBase::checkRunningTitleUpdates in Scheduled Updates 8

Checking adding and running updates for title.

Hardcoded for node 'title' property now.

Parameters

string $bundle:

string $reference_field_label:

string $reference_field_name:

Throws

\Behat\Mink\Exception\DriverException

\Behat\Mink\Exception\ElementNotFoundException

\Behat\Mink\Exception\ExpectationException

\Behat\Mink\Exception\ResponseTextException

\Behat\Mink\Exception\UnsupportedDriverActionException

\Drupal\Core\Entity\EntityStorageException

1 call to EmbeddedScheduledUpdateTypeTestBase::checkRunningTitleUpdates()
EmbeddedScheduledUpdateTypeTestBase::checkAfterTypeCreated in tests/src/FunctionalJavascript/EmbeddedScheduledUpdateTypeTestBase.php

File

tests/src/FunctionalJavascript/EmbeddedScheduledUpdateTypeTestBase.php, line 215
Contains \Drupal\Tests\scheduled_updates\EmbeddedScheduledUpdateTypeTestBase.

Class

EmbeddedScheduledUpdateTypeTestBase
Base test class for embedded update types.

Namespace

Drupal\Tests\scheduled_updates\FunctionalJavascript

Code

protected function checkRunningTitleUpdates($bundle, $reference_field_name, $reference_field_label) {
  foreach ([
    'ui',
    'cron',
  ] as $run_updates_via) {
    $update_node = $this
      ->createNodeWithUpdate('Title to be updated', '-1 year', $bundle, $reference_field_name, $reference_field_label);
    $no_update_node = $this
      ->createNodeWithUpdate('Title NOT to be updated', '+1 year', $bundle, $reference_field_name, $reference_field_label);
    if ($run_updates_via == 'cron') {

      // Because the update type is UpdateRunnerInterface::USER_UPDATE_RUNNER
      // the update should switch to user #1 during cron. Trigger validation
      // error.
      \Drupal::state()
        ->set('constraint_uid', UserIdConstraintValidator::CONSTRAINT_USER_1);
      $this
        ->cronRun();

      // Reset to avoid trigger validation error.
      \Drupal::state()
        ->set('constraint_uid', UserIdConstraintValidator::CONSTRAINT_NONE);
    }
    else {
      $this
        ->runUpdatesUI();
    }
    $this
      ->drupalGet("node/" . $update_node
      ->id());

    // 'Update title appears on past update'
    $this
      ->assertSession()
      ->pageTextContains('Title to be updated:updated');
    $this
      ->drupalGet("node/" . $no_update_node
      ->id());

    // 'Original node title appears on future update'
    $this
      ->assertSession()
      ->pageTextContains("Title NOT to be updated");

    // , 'Update title does not appear on future update'
    $this
      ->assertSession()
      ->pageTextNotContains("Title NOT to be updated:updated");
    $update_node
      ->delete();
    $no_update_node
      ->delete();
  }

  // Make sure that the user is switched to user #1 when updates are run with
  // cron and UpdateRunnerInterface::USER_UPDATE_RUNNER was used.
  // @see \Drupal\scheduled_updates_tests\Plugin\Validation\Constraint\UserIdConstraintValidator
  $invalid_update = $this
    ->createNodeWithUpdate('Title to be updated', '-1 year', $bundle, $reference_field_name, $reference_field_label);
  \Drupal::state()
    ->set('constraint_uid', UserIdConstraintValidator::CONSTRAINT_ANONYMOUS);
  $this
    ->cronRun();
  \Drupal::state()
    ->set('constraint_uid', UserIdConstraintValidator::CONSTRAINT_NONE);
  $this
    ->drupalGet("node/" . $invalid_update
    ->id());

  // 'Title not updated with validation error'
  $this
    ->assertSession()
    ->pageTextNotContains('Title to be updated:updated');
  $invalid_update
    ->delete();
}