Chris@17: getSession(); Chris@17: $page = $this->getSession()->getPage(); Chris@17: Chris@17: $form_path = 'ajax_forms_test_ajax_commands_form'; Chris@17: $web_user = $this->drupalCreateUser(['access content']); Chris@17: $this->drupalLogin($web_user); Chris@17: $this->drupalGet($form_path); Chris@17: Chris@17: // Tests the 'add_css' command. Chris@17: $page->pressButton("AJAX 'add_css' command"); Chris@17: $this->assertWaitPageContains('my/file.css'); Chris@17: Chris@17: // Tests the 'after' command. Chris@17: $page->pressButton("AJAX 'After': Click to put something after the div"); Chris@17: $this->assertWaitPageContains('
Something can be inserted after this
This will be placed after'); Chris@17: Chris@17: // Tests the 'alert' command. Chris@17: $page->pressButton("AJAX 'Alert': Click to alert"); Chris@17: // Wait for the alert to appear. Chris@17: $page->waitFor(10, function () use ($session) { Chris@17: try { Chris@17: $session->getDriver()->getWebDriverSession()->getAlert_text(); Chris@17: return TRUE; Chris@17: } Chris@17: catch (\Exception $e) { Chris@17: return FALSE; Chris@17: } Chris@17: }); Chris@17: $alert_text = $this->getSession()->getDriver()->getWebDriverSession()->getAlert_text(); Chris@17: $this->assertEquals('Alert', $alert_text); Chris@17: $this->getSession()->getDriver()->getWebDriverSession()->accept_alert(); Chris@17: Chris@18: $this->drupalGet($form_path); Chris@18: $page->pressButton("AJAX 'Announce': Click to announce"); Chris@18: $this->assertWaitPageContains('
Default announcement.
'); Chris@18: Chris@18: $this->drupalGet($form_path); Chris@18: $page->pressButton("AJAX 'Announce': Click to announce with 'polite' priority"); Chris@18: $this->assertWaitPageContains('
Polite announcement.
'); Chris@18: Chris@18: $this->drupalGet($form_path); Chris@18: $page->pressButton("AJAX 'Announce': Click to announce with 'assertive' priority"); Chris@18: $this->assertWaitPageContains('
Assertive announcement.
'); Chris@18: Chris@18: $this->drupalGet($form_path); Chris@18: $page->pressButton("AJAX 'Announce': Click to announce twice"); Chris@18: $this->assertWaitPageContains('
Assertive announcement.' . "\nAnother announcement.
"); Chris@18: Chris@17: // Tests the 'append' command. Chris@17: $page->pressButton("AJAX 'Append': Click to append something"); Chris@17: $this->assertWaitPageContains('
Append inside this divAppended text
'); Chris@17: Chris@17: // Tests the 'before' command. Chris@17: $page->pressButton("AJAX 'before': Click to put something before the div"); Chris@17: $this->assertWaitPageContains('Before text
Insert something before this.
'); Chris@17: Chris@17: // Tests the 'changed' command. Chris@17: $page->pressButton("AJAX changed: Click to mark div changed."); Chris@17: $this->assertWaitPageContains('
'); Chris@17: Chris@17: // Tests the 'changed' command using the second argument. Chris@17: // Refresh page for testing 'changed' command to same element again. Chris@17: $this->drupalGet($form_path); Chris@17: $page->pressButton("AJAX changed: Click to mark div changed with asterisk."); Chris@17: $this->assertWaitPageContains('
This div can be marked as changed or not. *
'); Chris@17: Chris@17: // Tests the 'css' command. Chris@17: $page->pressButton("Set the '#box' div to be blue."); Chris@17: $this->assertWaitPageContains('
'); Chris@17: Chris@17: // Tests the 'data' command. Chris@17: $page->pressButton("AJAX data command: Issue command."); Chris@17: $this->assertTrue($page->waitFor(10, function () use ($session) { Chris@17: return 'testvalue' === $session->evaluateScript('window.jQuery("#data_div").data("testkey")'); Chris@17: })); Chris@17: Chris@17: // Tests the 'html' command. Chris@17: $page->pressButton("AJAX html: Replace the HTML in a selector."); Chris@17: $this->assertWaitPageContains('
replacement text
'); Chris@17: Chris@17: // Tests the 'insert' command. Chris@17: $page->pressButton("AJAX insert: Let client insert based on #ajax['method']."); Chris@17: $this->assertWaitPageContains('
insert replacement textOriginal contents
'); Chris@17: Chris@17: // Tests the 'invoke' command. Chris@17: $page->pressButton("AJAX invoke command: Invoke addClass() method."); Chris@17: $this->assertWaitPageContains('
Original contents
'); Chris@17: Chris@17: // Tests the 'prepend' command. Chris@17: $page->pressButton("AJAX 'prepend': Click to prepend something"); Chris@17: $this->assertWaitPageContains('
prepended textSomething will be prepended to this div.
'); Chris@17: Chris@17: // Tests the 'remove' command. Chris@17: $page->pressButton("AJAX 'remove': Click to remove text"); Chris@17: $this->assertWaitPageContains('
'); Chris@17: Chris@17: // Tests the 'restripe' command. Chris@17: $page->pressButton("AJAX 'restripe' command"); Chris@17: $this->assertWaitPageContains('first row'); Chris@17: $this->assertWaitPageContains('second row'); Chris@17: Chris@17: // Tests the 'settings' command. Chris@17: $test_settings_command = <<' + settings.ajax_forms_test.foo + '
'); Chris@17: } Chris@17: }; Chris@17: JS; Chris@17: $session->executeScript($test_settings_command); Chris@17: // @todo: Replace after https://www.drupal.org/project/drupal/issues/2616184 Chris@17: $session->executeScript('window.jQuery("#edit-settings-command-example").mousedown();'); Chris@17: $this->assertWaitPageContains('
42
'); Chris@17: } Chris@17: Chris@17: /** Chris@17: * Asserts that page contains a text after waiting. Chris@17: * Chris@17: * @param string $text Chris@17: * A needle text. Chris@17: */ Chris@17: protected function assertWaitPageContains($text) { Chris@17: $page = $this->getSession()->getPage(); Chris@17: $page->waitFor(10, function () use ($page, $text) { Chris@17: return stripos($page->getContent(), $text) !== FALSE; Chris@17: }); Chris@17: $this->assertContains($text, $page->getContent()); Chris@17: } Chris@17: Chris@17: }