comparison core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.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\Tests\text\FunctionalJavascript;
4
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
7
8 /**
9 * Tests the JavaScript functionality of the text_textarea_with_summary widget.
10 *
11 * @group text
12 */
13 class TextareaWithSummaryTest extends JavascriptTestBase {
14
15 /**
16 * {@inheritdoc}
17 */
18 public static $modules = ['text', 'node'];
19
20 /**
21 * {@inheritdoc}
22 */
23 protected function setUp() {
24 parent::setUp();
25
26 $this->drupalCreateContentType(['type' => 'page']);
27
28 $account = $this->drupalCreateUser(['create page content', 'edit own page content']);
29 $this->drupalLogin($account);
30 }
31
32 /**
33 * Helper to test toggling the summary area.
34 */
35 protected function assertSummaryToggle() {
36 $this->drupalGet('node/add/page');
37 $widget = $this->getSession()->getPage()->findById('edit-body-wrapper');
38 $summary_field = $widget->findField('edit-body-0-summary');
39
40 $this->assertEquals(FALSE, $summary_field->isVisible(), 'Summary field is hidden by default.');
41 $this->assertEquals(FALSE, $widget->hasButton('Hide summary'), 'No Hide summary link by default.');
42
43 $widget->pressButton('Edit summary');
44 $this->assertEquals(FALSE, $widget->hasButton('Edit summary'), 'Edit summary link is removed after clicking.');
45 $this->assertEquals(TRUE, $summary_field->isVisible(), 'Summary field is shown.');
46
47 $widget->pressButton('Hide summary');
48 $this->assertEquals(FALSE, $widget->hasButton('Hide summary'), 'Hide summary link is removed after clicking.');
49 $this->assertEquals(FALSE, $summary_field->isVisible(), 'Summary field is hidden again.');
50 $this->assertEquals(TRUE, $widget->hasButton('Edit summary'), 'Edit summary link is visible again.');
51 }
52
53 /**
54 * Tests the textSummary javascript behavior.
55 */
56 public function testTextSummaryBehavior() {
57 // Test with field defaults.
58 $this->assertSummaryToggle();
59
60 // Repeat test with non-empty field description.
61 $body_field = FieldConfig::loadByName('node', 'page', 'body');
62 $body_field->set('description', 'Text with Summary field description.');
63 $body_field->save();
64
65 $this->assertSummaryToggle();
66
67 // Test summary is shown when non-empty.
68 $node = $this->createNode([
69 'body' => [
70 [
71 'value' => $this->randomMachineName(32),
72 'summary' => $this->randomMachineName(32),
73 'format' => filter_default_format(),
74 ],
75 ],
76 ]);
77
78 $this->drupalGet('node/' . $node->id() . '/edit');
79 $page = $this->getSession()->getPage();
80 $summary_field = $page->findField('edit-body-0-summary');
81
82 $this->assertEquals(TRUE, $summary_field->isVisible(), 'Non-empty summary field is shown by default.');
83 }
84
85 }