public function SchedulerHooksTest::testHideDateField in Scheduler 2.x
Tests the hooks which allow hiding of scheduler input fields.
This test covers: hook_scheduler_hide_publish_date() hook_scheduler_hide_unpublish_date() hook_scheduler_{type}_hide_publish_date() hook_scheduler_{type}_hide_unpublish_date()
@dataProvider dataStandardEntityTypes()
File
- tests/
src/ Functional/ SchedulerHooksTest.php, line 425
Class
- SchedulerHooksTest
- Tests the API hook functions of the Scheduler module.
Namespace
Drupal\Tests\scheduler\FunctionalCode
public function testHideDateField($entityTypeId, $bundle) {
$this
->drupalLogin($this->schedulerUser);
// Create test entities.
$entity1 = $this
->createEntity($entityTypeId, $bundle, [
'title' => "Red {$entityTypeId} will have neither field hidden",
]);
$entity2 = $this
->createEntity($entityTypeId, $bundle, [
'title' => "Orange {$entityTypeId} will have the publish-on field hidden",
]);
$entity3 = $this
->createEntity($entityTypeId, $bundle, [
'title' => "Yellow {$entityTypeId} will have the unpublish-on field hidden",
]);
$entity4 = $this
->createEntity($entityTypeId, $bundle, [
'title' => "Green {$entityTypeId} will have both Scheduler fields hidden",
]);
// Set the scheduler fieldset to always expand, for ease during development.
$bundle_field_name = $entity1
->getEntityType()
->get('entity_keys')['bundle'];
$entity1->{$bundle_field_name}->entity
->setThirdPartySetting('scheduler', 'expand_fieldset', 'always')
->save();
/** @var \Drupal\Tests\WebAssert $assert */
$assert = $this
->assertSession();
// Entity 1 'Red' should have both fields displayed.
$this
->drupalGet($entity1
->toUrl('edit-form'));
$assert
->ElementExists('xpath', '//input[@id = "edit-publish-on-0-value-date"]');
$assert
->ElementExists('xpath', '//input[@id = "edit-unpublish-on-0-value-date"]');
// Entity 2 'Orange' should have only the publish-on field hidden.
$this
->drupalGet($entity2
->toUrl('edit-form'));
$assert
->ElementNotExists('xpath', '//input[@id = "edit-publish-on-0-value-date"]');
$assert
->ElementExists('xpath', '//input[@id = "edit-unpublish-on-0-value-date"]');
// Entity 3 'Yellow' should have only the unpublish-on field hidden.
$this
->drupalGet($entity3
->toUrl('edit-form'));
$assert
->ElementExists('xpath', '//input[@id = "edit-publish-on-0-value-date"]');
$assert
->ElementNotExists('xpath', '//input[@id = "edit-unpublish-on-0-value-date"]');
// Entity 4 'Green' should have both publish-on and unpublish-on hidden.
$this
->drupalGet($entity4
->toUrl('edit-form'));
$assert
->ElementNotExists('xpath', '//input[@id = "edit-publish-on-0-value-date"]');
$assert
->ElementNotExists('xpath', '//input[@id = "edit-unpublish-on-0-value-date"]');
}