You are here

public function SchedulerFieldsDisplayTest::testHideSeconds in Scheduler 2.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/SchedulerFieldsDisplayTest.php \Drupal\Tests\scheduler\Functional\SchedulerFieldsDisplayTest::testHideSeconds()

Test the option to hide the seconds on the time input fields.

@dataProvider dataStandardEntityTypes()

File

tests/src/Functional/SchedulerFieldsDisplayTest.php, line 237

Class

SchedulerFieldsDisplayTest
Tests the display of date entry fields and form elements.

Namespace

Drupal\Tests\scheduler\Functional

Code

public function testHideSeconds($entityTypeId, $bundle) {
  $this
    ->drupalLogin($this->schedulerUser);
  $config = $this
    ->config('scheduler.settings');
  $titleField = $entityTypeId == 'media' ? 'name' : 'title';

  // Check that the default is to show the seconds on the input fields.
  $add_url = $this
    ->entityAddUrl($entityTypeId, $bundle);
  $this
    ->drupalGet($add_url);
  $publish_time_field = $this
    ->xpath('//input[@id="edit-publish-on-0-value-time"]');
  $unpublish_time_field = $this
    ->xpath('//input[@id="edit-unpublish-on-0-value-time"]');
  $this
    ->assertEquals(1, $publish_time_field[0]
    ->getAttribute('step'), 'The input time step for publish-on is 1, so the seconds will be visible and usable.');
  $this
    ->assertEquals(1, $unpublish_time_field[0]
    ->getAttribute('step'), 'The input time step for unpublish-on is 1, so the seconds will be visible and usable.');

  // Set the config option to hide the seconds and thus set the input fields
  // to the granularity of one minute.
  $config
    ->set('hide_seconds', TRUE)
    ->save();

  // Get the node-add page and check the input fields.
  $this
    ->drupalGet($add_url);
  $publish_time_field = $this
    ->xpath('//input[@id="edit-publish-on-0-value-time"]');
  $unpublish_time_field = $this
    ->xpath('//input[@id="edit-unpublish-on-0-value-time"]');
  $this
    ->assertEquals(60, $publish_time_field[0]
    ->getAttribute('step'), 'The input time step for publish-on is 60, so the seconds will be hidden and not usable.');
  $this
    ->assertEquals(60, $unpublish_time_field[0]
    ->getAttribute('step'), 'The input time step for unpublish-on is 60, so the seconds will be hidden and not usable.');

  // @todo How can we check that the seconds element is not shown?
  // Save with both dates entered, including seconds in the times.
  $edit = [
    "{$titleField}[0][value]" => 'Hide the seconds',
    'publish_on[0][value][date]' => date('Y-m-d', strtotime('+1 day', $this->requestTime)),
    'publish_on[0][value][time]' => '01:02:03',
    'unpublish_on[0][value][date]' => date('Y-m-d', strtotime('+1 day', $this->requestTime)),
    'unpublish_on[0][value][time]' => '04:05:06',
  ];
  $this
    ->submitForm($edit, 'Save');
  $entity = $this
    ->getEntityByTitle($entityTypeId, 'Hide the seconds');

  // Edit and check that the seconds have been set to zero.
  $this
    ->drupalGet($entity
    ->toUrl('edit-form'));
  $this
    ->assertSession()
    ->FieldValueEquals('publish_on[0][value][time]', '01:02:00');
  $this
    ->assertSession()
    ->FieldValueEquals('unpublish_on[0][value][time]', '04:05:00');
}