Mercurial > hg > isophonics-drupal-site
comparison core/modules/system/tests/src/FunctionalJavascript/OffCanvasTestBase.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\Tests\system\FunctionalJavascript; | 3 namespace Drupal\Tests\system\FunctionalJavascript; |
4 | 4 |
5 use Drupal\FunctionalJavascriptTests\JavascriptTestBase; | 5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase; |
6 | 6 |
7 /** | 7 /** |
8 * Base class contains common test functionality for the Off-canvas dialog. | 8 * Base class contains common test functionality for the Off-canvas dialog. |
9 */ | 9 */ |
10 abstract class OffCanvasTestBase extends JavascriptTestBase { | 10 abstract class OffCanvasTestBase extends WebDriverTestBase { |
11 | 11 |
12 /** | 12 /** |
13 * {@inheritdoc} | 13 * {@inheritdoc} |
14 */ | 14 */ |
15 protected function drupalGet($path, array $options = [], array $headers = []) { | 15 protected function drupalGet($path, array $options = [], array $headers = []) { |
58 $theme_config->save(); | 58 $theme_config->save(); |
59 } | 59 } |
60 | 60 |
61 /** | 61 /** |
62 * Waits for off-canvas dialog to open. | 62 * Waits for off-canvas dialog to open. |
63 * | |
64 * @param string $position | |
65 * The position of the dialog. | |
66 * | |
67 * @throws \Behat\Mink\Exception\ElementNotFoundException | |
63 */ | 68 */ |
64 protected function waitForOffCanvasToOpen() { | 69 protected function waitForOffCanvasToOpen($position = 'side') { |
65 $web_assert = $this->assertSession(); | 70 $web_assert = $this->assertSession(); |
66 // Wait just slightly longer than the off-canvas dialog CSS animation. | 71 // Wait just slightly longer than the off-canvas dialog CSS animation. |
67 // @see core/misc/dialog/off-canvas.motion.css | 72 // @see core/misc/dialog/off-canvas.motion.css |
68 $this->getSession()->wait(800); | 73 $this->getSession()->wait(800); |
69 $web_assert->assertWaitOnAjaxRequest(); | 74 $web_assert->assertWaitOnAjaxRequest(); |
70 $this->assertElementVisibleAfterWait('css', '#drupal-off-canvas'); | 75 $this->assertElementVisibleAfterWait('css', '#drupal-off-canvas'); |
76 // Check that the canvas is positioned on the side. | |
77 $web_assert->elementExists('css', '.ui-dialog-position-' . $position); | |
71 } | 78 } |
72 | 79 |
73 /** | 80 /** |
74 * Waits for off-canvas dialog to close. | 81 * Waits for off-canvas dialog to close. |
75 */ | 82 */ |
97 * (optional) Timeout in milliseconds, defaults to 10000. | 104 * (optional) Timeout in milliseconds, defaults to 10000. |
98 * | 105 * |
99 * @todo Remove in https://www.drupal.org/node/2892440. | 106 * @todo Remove in https://www.drupal.org/node/2892440. |
100 */ | 107 */ |
101 protected function waitForNoElement($selector, $timeout = 10000) { | 108 protected function waitForNoElement($selector, $timeout = 10000) { |
102 $condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)"; | 109 |
103 $this->assertJsCondition($condition, $timeout); | 110 $start = microtime(TRUE); |
111 $end = $start + ($timeout / 1000); | |
112 $page = $this->getSession()->getPage(); | |
113 | |
114 do { | |
115 $result = $page->find('css', $selector); | |
116 | |
117 if (empty($result)) { | |
118 return; | |
119 } | |
120 | |
121 usleep(100000); | |
122 } while (microtime(TRUE) < $end); | |
123 | |
124 $this->assertEmpty($result, 'Element was not on the page after wait.'); | |
104 } | 125 } |
105 | 126 |
106 /** | 127 /** |
107 * Get themes to test. | 128 * Get themes to test. |
108 * | 129 * |
123 * The selector locator. | 144 * The selector locator. |
124 * @param int $timeout | 145 * @param int $timeout |
125 * (Optional) Timeout in milliseconds, defaults to 10000. | 146 * (Optional) Timeout in milliseconds, defaults to 10000. |
126 */ | 147 */ |
127 protected function assertElementVisibleAfterWait($selector, $locator, $timeout = 10000) { | 148 protected function assertElementVisibleAfterWait($selector, $locator, $timeout = 10000) { |
149 $this->assertSession()->assertWaitOnAjaxRequest(); | |
128 $this->assertNotEmpty($this->assertSession()->waitForElementVisible($selector, $locator, $timeout)); | 150 $this->assertNotEmpty($this->assertSession()->waitForElementVisible($selector, $locator, $timeout)); |
129 } | 151 } |
130 | 152 |
153 /** | |
154 * Dataprovider that returns theme name as the sole argument. | |
155 */ | |
156 public function themeDataProvider() { | |
157 $themes = $this->getTestThemes(); | |
158 $data = []; | |
159 foreach ($themes as $theme) { | |
160 $data[$theme] = [ | |
161 $theme, | |
162 ]; | |
163 } | |
164 return $data; | |
165 } | |
166 | |
131 } | 167 } |