comparison core/tests/Drupal/FunctionalJavascriptTests/Tests/JSWebAssertTest.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children a9cd425dd02b
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
1 <?php
2
3 namespace Drupal\FunctionalJavascriptTests\Tests;
4
5 use Behat\Mink\Element\NodeElement;
6 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
7
8 /**
9 * Tests for the JSWebAssert class.
10 *
11 * @group javascript
12 */
13 class JSWebAssertTest extends JavascriptTestBase {
14
15 /**
16 * Required modules.
17 *
18 * @var array
19 */
20 public static $modules = ['js_webassert_test'];
21
22 /**
23 * Tests that JSWebAssert assertions work correctly.
24 */
25 public function testJsWebAssert() {
26 $this->drupalGet('js_webassert_test_form');
27
28 $session = $this->getSession();
29 $assert_session = $this->assertSession();
30 $page = $session->getPage();
31
32 $test_button = $page->findButton('Add button');
33 $test_link = $page->findButton('Add link');
34 $test_field = $page->findButton('Add field');
35 $test_id = $page->findButton('Add ID');
36 $test_wait_on_ajax = $page->findButton('Test assertWaitOnAjaxRequest');
37 $test_wait_on_element_visible = $page->findButton('Test waitForElementVisible');
38
39 // Test the wait...() methods by first checking the fields aren't available
40 // and then are available after the wait method.
41 $result = $page->findButton('Added button');
42 $this->assertEmpty($result);
43 $test_button->click();
44 $result = $assert_session->waitForButton('Added button');
45 $this->assertNotEmpty($result);
46 $this->assertTrue($result instanceof NodeElement);
47
48 $result = $page->findLink('Added link');
49 $this->assertEmpty($result);
50 $test_link->click();
51 $result = $assert_session->waitForLink('Added link');
52 $this->assertNotEmpty($result);
53 $this->assertTrue($result instanceof NodeElement);
54
55 $result = $page->findField('added_field');
56 $this->assertEmpty($result);
57 $test_field->click();
58 $result = $assert_session->waitForField('added_field');
59 $this->assertNotEmpty($result);
60 $this->assertTrue($result instanceof NodeElement);
61
62 $result = $page->findById('js_webassert_test_field_id');
63 $this->assertEmpty($result);
64 $test_id->click();
65 $result = $assert_session->waitForId('js_webassert_test_field_id');
66 $this->assertNotEmpty($result);
67 $this->assertTrue($result instanceof NodeElement);
68
69 // Test waitOnAjaxRequest. Verify the element is available after the wait
70 // and the behaviors have run on completing by checking the value.
71 $result = $page->findField('test_assert_wait_on_ajax_input');
72 $this->assertEmpty($result);
73 $test_wait_on_ajax->click();
74 $assert_session->assertWaitOnAjaxRequest();
75 $result = $page->findField('test_assert_wait_on_ajax_input');
76 $this->assertNotEmpty($result);
77 $this->assertTrue($result instanceof NodeElement);
78 $this->assertEquals('js_webassert_test', $result->getValue());
79
80 $result = $page->findButton('Added WaitForElementVisible');
81 $this->assertEmpty($result);
82 $test_wait_on_element_visible->click();
83 $result = $assert_session->waitForElementVisible('named', ['button', 'Added WaitForElementVisible']);
84 $this->assertNotEmpty($result);
85 $this->assertTrue($result instanceof NodeElement);
86 $this->assertEquals(TRUE, $result->isVisible());
87 }
88
89 }