EventBundleTest.php in Rules 8.3
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
->assertWaitOnAjaxRequest();
$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());
$assert
->assertWaitOnAjaxRequest();
if ($page
->findField('bundle')) {
$page
->findField('bundle')
->selectOption('page');
$assert
->assertWaitOnAjaxRequest();
$field = $page
->findField('bundle');
$this
->assertNotEmpty($field);
$this
->assertEquals('page', $field
->getValue());
$page
->findField('bundle')
->selectOption('article');
$assert
->assertWaitOnAjaxRequest();
$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
->assert(empty($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 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 of type Article');
$assert
->pageTextContains('Machine name: rules_entity_insert:node--article');
}
}