Namespace
Drupal\Tests\rules\FunctionalJavascript
File
-
tests/src/FunctionalJavascript/EventBundleTest.php
View source
<?php
namespace Drupal\Tests\rules\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class EventBundleTest extends WebDriverTestBase {
protected static $modules = [
'rules',
'taxonomy',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this->createContentType([
'type' => 'page',
'name' => 'Basic page',
]);
$this->createContentType([
'type' => 'article',
'name' => 'Article',
]);
}
public function testEventBundleSelection() {
$account = $this->createUser([
'administer rules',
]);
$this->drupalLogin($account);
$this->drupalGet('admin/config/workflow/rules/reactions/add');
$assert = $this->assertSession();
$assert->pageTextContains('Event selection');
$assert->pageTextContains('React on event');
$page = $this->getSession()
->getPage();
$page->fillField('label', 'Test bundle selection Ajax rule');
$assert->waitForElementVisible('css', '.machine-name-value');
$page->findField('events[0][event_name]')
->selectOption('rules_entity_insert:taxonomy_term');
$assert->assertWaitOnAjaxRequest();
$assert->pageTextContains('Restrict by type');
$field = $page->findField('bundle');
$this->assertNotEmpty($field);
$this->assertEquals('notselected', $field->getValue());
$page->findField('events[0][event_name]')
->selectOption('rules_system_cron');
$assert->assertWaitOnAjaxRequest();
$assert->pageTextNotContains('Restrict by type');
$field = $page->findField('bundle');
$this->assertEmpty($field);
$page->findField('events[0][event_name]')
->selectOption('rules_entity_insert:node');
$assert->assertWaitOnAjaxRequest();
$assert->pageTextContains('Restrict by type');
$field = $page->findField('events[0][event_name]');
$this->assertNotEmpty($field);
$this->assertEquals('rules_entity_insert:node', $field->getValue());
if ($page->findField('bundle')) {
$page->findField('bundle')
->selectOption('page');
$field = $page->findField('bundle');
$this->assertNotEmpty($field);
$this->assertEquals('page', $field->getValue());
$page->findField('bundle')
->selectOption('article');
$field = $page->findField('bundle');
$this->assertNotEmpty($field);
$this->assertEquals('article', $field->getValue());
}
else {
$bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo('node');
$assert->pageTextNotContains('Restrict by type');
$assert->assertEmpty($bundles, 'Restrict by type field is not shown and there are no bundles.');
}
$page->pressButton('Save');
$this->drupalGet('admin/config/workflow/rules');
$assert->pageTextContains('Test bundle selection Ajax rule');
$assert->pageTextContains('After saving a new content item entity of type Article');
$assert->pageTextContains('Machine name: test_bundle_selection_ajax_rule');
$this->drupalGet('admin/config/workflow/rules/reactions/edit/test_bundle_selection_ajax_rule');
$assert->pageTextContains('After saving a new content item entity of type Article');
$assert->pageTextContains('Machine name: rules_entity_insert:node--article');
}
}
Classes
| Title |
Deprecated |
Summary |
| EventBundleTest |
|
Tests the Ajax behavior of the Add Reaction Rule UI. |