Chris@0: drupalCreateContentType(['type' => 'page']); Chris@0: Chris@0: $account = $this->drupalCreateUser(['create page content', 'edit own page content']); Chris@0: $this->drupalLogin($account); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Helper to test toggling the summary area. Chris@0: */ Chris@0: protected function assertSummaryToggle() { Chris@0: $this->drupalGet('node/add/page'); Chris@0: $widget = $this->getSession()->getPage()->findById('edit-body-wrapper'); Chris@0: $summary_field = $widget->findField('edit-body-0-summary'); Chris@0: Chris@0: $this->assertEquals(FALSE, $summary_field->isVisible(), 'Summary field is hidden by default.'); Chris@0: $this->assertEquals(FALSE, $widget->hasButton('Hide summary'), 'No Hide summary link by default.'); Chris@0: Chris@0: $widget->pressButton('Edit summary'); Chris@0: $this->assertEquals(FALSE, $widget->hasButton('Edit summary'), 'Edit summary link is removed after clicking.'); Chris@0: $this->assertEquals(TRUE, $summary_field->isVisible(), 'Summary field is shown.'); Chris@0: Chris@0: $widget->pressButton('Hide summary'); Chris@0: $this->assertEquals(FALSE, $widget->hasButton('Hide summary'), 'Hide summary link is removed after clicking.'); Chris@0: $this->assertEquals(FALSE, $summary_field->isVisible(), 'Summary field is hidden again.'); Chris@0: $this->assertEquals(TRUE, $widget->hasButton('Edit summary'), 'Edit summary link is visible again.'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the textSummary javascript behavior. Chris@0: */ Chris@0: public function testTextSummaryBehavior() { Chris@0: // Test with field defaults. Chris@0: $this->assertSummaryToggle(); Chris@0: Chris@0: // Repeat test with non-empty field description. Chris@0: $body_field = FieldConfig::loadByName('node', 'page', 'body'); Chris@0: $body_field->set('description', 'Text with Summary field description.'); Chris@0: $body_field->save(); Chris@0: Chris@0: $this->assertSummaryToggle(); Chris@0: Chris@0: // Test summary is shown when non-empty. Chris@0: $node = $this->createNode([ Chris@0: 'body' => [ Chris@0: [ Chris@0: 'value' => $this->randomMachineName(32), Chris@0: 'summary' => $this->randomMachineName(32), Chris@0: 'format' => filter_default_format(), Chris@0: ], Chris@0: ], Chris@0: ]); Chris@0: Chris@0: $this->drupalGet('node/' . $node->id() . '/edit'); Chris@0: $page = $this->getSession()->getPage(); Chris@0: $summary_field = $page->findField('edit-body-0-summary'); Chris@0: Chris@0: $this->assertEquals(TRUE, $summary_field->isVisible(), 'Non-empty summary field is shown by default.'); Chris@0: } Chris@0: Chris@0: }