View source
<?php
namespace Drupal\Tests\smart_title\Functional;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
class SmartTitleBasicTest extends SmartTitleBrowserTestBase {
public function testSmartTitleBasics() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('node');
$article_title = $this
->xpath($this
->cssSelectToXpath('article > h2'));
$this
->assertEquals($this->testPageNode
->label(), $article_title[0]
->getText());
$this
->drupalGet('node/' . $this->testPageNode
->id());
$article_title = $this
->xpath($this
->cssSelectToXpath('article > h2'));
$this
->assertEquals($article_title, []);
$this
->drupalLogout();
$this
->drupalGet('node');
$article_title = $this
->xpath($this
->cssSelectToXpath('article > h2'));
$this
->assertEquals($this->testPageNode
->label(), $article_title[0]
->getText());
$this
->drupalGet('node/' . $this->testPageNode
->id());
$article_title = $this
->xpath($this
->cssSelectToXpath('article > h2'));
$this
->assertEquals($article_title, []);
$this
->drupalLogin($this->adminUser);
$this
->drupalPostForm('admin/structure/types/manage/test_page/display', [
'smart_title__enabled' => TRUE,
], 'Save');
$this
->drupalPostForm(NULL, [
'fields[smart_title][weight]' => '-5',
'fields[smart_title][region]' => 'content',
], 'Save');
$display = $this->container
->get('entity_type.manager')
->getStorage('entity_view_display')
->load('node.' . $this->testPageNode
->getType() . '.default');
assert($display instanceof EntityViewDisplayInterface);
$smart_title_enabled = $display
->getThirdPartySetting('smart_title', 'enabled');
$saved_settings = $display
->getThirdPartySetting('smart_title', 'settings');
$this
->assertTrue($smart_title_enabled);
$this
->assertEquals($saved_settings, [
'smart_title__tag' => 'h2',
'smart_title__classes' => [
'node__title',
],
'smart_title__link' => TRUE,
]);
$this
->click('[name="smart_title_settings_edit"]');
$page = $this
->getSession()
->getPage();
$page
->selectFieldOption('fields[smart_title][settings_edit_form][settings][smart_title__tag]', 'span');
$page
->fillField('fields[smart_title][settings_edit_form][settings][smart_title__classes]', 'test classes');
$page
->uncheckField('fields[smart_title][settings_edit_form][settings][smart_title__link]');
$this
->drupalPostForm(NULL, [], 'Cancel');
$display = $this->container
->get('entity_type.manager')
->getStorage('entity_view_display')
->load('node.' . $this->testPageNode
->getType() . '.default');
assert($display instanceof EntityViewDisplayInterface);
$smart_title_enabled = $display
->getThirdPartySetting('smart_title', 'enabled');
$saved_settings = $display
->getThirdPartySetting('smart_title', 'settings');
$this
->assertTrue($smart_title_enabled);
$this
->assertEquals($saved_settings, [
'smart_title__tag' => 'h2',
'smart_title__classes' => [
'node__title',
],
'smart_title__link' => TRUE,
]);
$this
->drupalGet('node');
$web_assert = $this
->assertSession();
$web_assert
->elementExists('css', 'article > h2');
$web_assert
->elementNotExists('css', 'article > div > h2.node__title');
$this
->drupalLogout();
$this
->drupalGet($this->testPageNode
->toUrl());
$web_assert = $this
->assertSession();
$this
->assertTitle(strtr('@title | Drupal', [
'@title' => $this->testPageNode
->getTitle(),
]));
$web_assert
->elementExists('css', 'article > div > h2.node__title');
$web_assert
->elementExists('css', 'article > div > h2.node__title > a > span');
}
}