Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / action / tests / src / FunctionalJavascript / ActionFormAjaxTest.php
1 <?php
2
3 namespace Drupal\Tests\action\FunctionalJavascript;
4
5 use Drupal\Core\Url;
6 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
7 use Drupal\system\Entity\Action;
8
9 /**
10  * Tests action plugins using Javascript.
11  *
12  * @group action
13  */
14 class ActionFormAjaxTest extends WebDriverTestBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   protected static $modules = ['action', 'action_form_ajax_test'];
20
21   /**
22    * {@inheritdoc}
23    */
24   protected function setUp() {
25     parent::setUp();
26     $user = $this->drupalCreateUser(['administer actions']);
27     $this->drupalLogin($user);
28   }
29
30   /**
31    * Tests action plugins with AJAX save their configuration.
32    */
33   public function testActionConfigurationWithAjax() {
34     $url = Url::fromRoute('action.admin_add', ['action_id' => 'action_form_ajax_test']);
35     $this->drupalGet($url);
36     $page = $this->getSession()->getPage();
37
38     $id = 'test_plugin';
39     $this->assertSession()->waitForElementVisible('named', ['button', 'Edit'])->press();
40     $this->assertSession()->waitForElementVisible('css', '[name="id"]')->setValue($id);
41
42     $page->find('css', '[name="having_a_party"]')
43       ->check();
44     $this->assertSession()->waitForElementVisible('css', '[name="party_time"]');
45
46     $party_time = 'Evening';
47     $page->find('css', '[name="party_time"]')
48       ->setValue($party_time);
49
50     $page->find('css', '[value="Save"]')
51       ->click();
52
53     $url = Url::fromRoute('entity.action.collection');
54     $this->assertSession()->pageTextContains('The action has been successfully saved.');
55     $this->assertSession()->addressEquals($url);
56
57     // Check storage.
58     $instance = Action::load($id);
59     $configuration = $instance->getPlugin()->getConfiguration();
60     $this->assertEquals(['party_time' => $party_time], $configuration);
61
62     // Configuration should be shown in edit form.
63     $this->drupalGet($instance->toUrl('edit-form'));
64     $this->assertSession()->checkboxChecked('having_a_party');
65     $this->assertSession()->fieldValueEquals('party_time', $party_time);
66   }
67
68 }