annotate core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php @ 4:a9cd425dd02b

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