Mercurial > hg > isophonics-drupal-site
comparison core/modules/quickedit/tests/src/FunctionalJavascript/FieldTest.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\quickedit\FunctionalJavascript; | |
4 | |
5 use Drupal\editor\Entity\Editor; | |
6 use Drupal\filter\Entity\FilterFormat; | |
7 use Drupal\FunctionalJavascriptTests\WebDriverTestBase; | |
8 use Drupal\node\Entity\Node; | |
9 use Drupal\node\Entity\NodeType; | |
10 use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait; | |
11 | |
12 /** | |
13 * Tests quickedit. | |
14 * | |
15 * @group quickedit | |
16 */ | |
17 class FieldTest extends WebDriverTestBase { | |
18 | |
19 use ContextualLinkClickTrait; | |
20 | |
21 /** | |
22 * {@inheritdoc} | |
23 */ | |
24 public static $modules = [ | |
25 'node', | |
26 'ckeditor', | |
27 'contextual', | |
28 'quickedit', | |
29 ]; | |
30 | |
31 /** | |
32 * {@inheritdoc} | |
33 */ | |
34 protected function setUp() { | |
35 parent::setUp(); | |
36 | |
37 // Create a text format and associate CKEditor. | |
38 $filtered_html_format = FilterFormat::create([ | |
39 'format' => 'filtered_html', | |
40 'name' => 'Filtered HTML', | |
41 'weight' => 0, | |
42 ]); | |
43 $filtered_html_format->save(); | |
44 | |
45 Editor::create([ | |
46 'format' => 'filtered_html', | |
47 'editor' => 'ckeditor', | |
48 ])->save(); | |
49 | |
50 // Create note type with body field. | |
51 $node_type = NodeType::create(['type' => 'page', 'name' => 'Page']); | |
52 $node_type->save(); | |
53 node_add_body_field($node_type); | |
54 | |
55 $account = $this->drupalCreateUser([ | |
56 'access content', | |
57 'administer nodes', | |
58 'edit any page content', | |
59 'use text format filtered_html', | |
60 'access contextual links', | |
61 'access in-place editing', | |
62 ]); | |
63 $this->drupalLogin($account); | |
64 | |
65 } | |
66 | |
67 /** | |
68 * Tests that quickeditor works correctly for field with CKEditor. | |
69 */ | |
70 public function testFieldWithCkeditor() { | |
71 $body_value = '<p>Sapere aude</p>'; | |
72 $node = Node::create([ | |
73 'type' => 'page', | |
74 'title' => 'Page node', | |
75 'body' => [['value' => $body_value, 'format' => 'filtered_html']], | |
76 ]); | |
77 $node->save(); | |
78 | |
79 $page = $this->getSession()->getPage(); | |
80 $assert = $this->assertSession(); | |
81 | |
82 $this->drupalGet('node/' . $node->id()); | |
83 | |
84 // Wait "Quick edit" button for node. | |
85 $this->assertSession()->waitForElement('css', '[data-quickedit-entity-id="node/' . $node->id() . '"] .contextual .quickedit'); | |
86 // Click by "Quick edit". | |
87 $this->clickContextualLink('[data-quickedit-entity-id="node/' . $node->id() . '"]', 'Quick edit'); | |
88 // Switch to body field. | |
89 $page->find('css', '[data-quickedit-field-id="node/' . $node->id() . '/body/en/full"]')->click(); | |
90 // Wait and click by "Blockquote" button from editor for body field. | |
91 $this->assertSession()->waitForElementVisible('css', '.cke_button.cke_button__blockquote')->click(); | |
92 // Wait and click by "Save" button after body field was changed. | |
93 $this->assertSession()->waitForElementVisible('css', '.quickedit-toolgroup.ops [type="submit"][aria-hidden="false"]')->click(); | |
94 // Wait until the save occurs and the editor UI disappears. | |
95 $this->waitForNoElement('.cke_button.cke_button__blockquote'); | |
96 // Ensure that the changes take effect. | |
97 $assert->responseMatches("|<blockquote>\s*$body_value\s*</blockquote>|"); | |
98 } | |
99 | |
100 /** | |
101 * Waits for an element to be removed from the page. | |
102 * | |
103 * @param string $selector | |
104 * CSS selector. | |
105 * @param int $timeout | |
106 * (optional) Timeout in milliseconds, defaults to 10000. | |
107 */ | |
108 protected function waitForNoElement($selector, $timeout = 10000) { | |
109 $condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)"; | |
110 $this->assertJsCondition($condition, $timeout); | |
111 } | |
112 | |
113 } |