You are here

public function SchedulerApiTest::testHideField in Scheduler 8

Test the hooks which allow hiding of scheduler input fields.

This covers hook_scheduler_hide_publish_on_field and hook_scheduler_hide_unpublish_on_field.

File

tests/src/Functional/SchedulerApiTest.php, line 386

Class

SchedulerApiTest
Tests the API of the Scheduler module.

Namespace

Drupal\Tests\scheduler\Functional

Code

public function testHideField() {
  $this
    ->drupalLogin($this->schedulerUser);

  // Create test nodes.
  $node1 = $this
    ->drupalCreateNode([
    'type' => $this->type,
    'title' => 'Red will not have either field hidden',
  ]);
  $node2 = $this
    ->drupalCreateNode([
    'type' => $this->type,
    'title' => 'Orange will have the publish-on field hidden',
  ]);
  $node3 = $this
    ->drupalCreateNode([
    'type' => $this->type,
    'title' => 'Yellow will have the unpublish-on field hidden',
  ]);
  $node4 = $this
    ->drupalCreateNode([
    'type' => $this->type,
    'title' => 'Green will have both Scheduler fields hidden',
  ]);

  /** @var \Drupal\Tests\WebAssert $assert */
  $assert = $this
    ->assertSession();

  // Node 1 'red' should have both fields displayed.
  $this
    ->drupalGet('node/' . $node1
    ->id() . '/edit');
  $assert
    ->ElementExists('xpath', '//input[@id = "edit-publish-on-0-value-date"]');
  $assert
    ->ElementExists('xpath', '//input[@id = "edit-unpublish-on-0-value-date"]');

  // Node 2 'orange' should have only the publish-on field hidden.
  $this
    ->drupalGet('node/' . $node2
    ->id() . '/edit');
  $assert
    ->ElementNotExists('xpath', '//input[@id = "edit-publish-on-0-value-date"]');
  $assert
    ->ElementExists('xpath', '//input[@id = "edit-unpublish-on-0-value-date"]');

  // Node 3 'yellow' should have only the unpublish-on field hidden.
  $this
    ->drupalGet('node/' . $node3
    ->id() . '/edit');
  $assert
    ->ElementExists('xpath', '//input[@id = "edit-publish-on-0-value-date"]');
  $assert
    ->ElementNotExists('xpath', '//input[@id = "edit-unpublish-on-0-value-date"]');

  // Node 4 'green' should have both publish-on and unpublish-on hidden.
  $this
    ->drupalGet('node/' . $node4
    ->id() . '/edit');
  $assert
    ->ElementNotExists('xpath', '//input[@id = "edit-publish-on-0-value-date"]');
  $assert
    ->ElementNotExists('xpath', '//input[@id = "edit-unpublish-on-0-value-date"]');
}