MetatagViewsTokenTest.php in Metatag 8
File
metatag_views/tests/src/Functional/MetatagViewsTokenTest.php
View source
<?php
namespace Drupal\Tests\metatag_views\Functional;
use Drupal\Tests\BrowserTestBase;
class MetatagViewsTokenTest extends BrowserTestBase {
use \Drupal\Tests\metatag\Functional\MetatagHelperTrait;
protected static $modules = [
'block',
'field',
'field_ui',
'help',
'node',
'user',
'views',
'views_ui',
'token',
'metatag',
'metatag_views',
];
protected $defaultTheme = 'bartik';
public function testTokenization() {
$this
->loginUser1();
$page_path = $this
->randomMachineName();
$this
->drupalGet('/admin/structure/views/add');
$edit = [
'label' => $this
->randomString(),
'id' => 'test',
'page[create]' => 1,
'page[path]' => $page_path,
'page[style][row_plugin]' => 'titles',
];
$this
->submitForm($edit, 'Save and edit');
$title_prefix = $this
->updateView(TRUE);
$node_title = $this
->randomString();
$this
->createContentTypeNode($node_title);
$this
->drupalGet("/{$page_path}");
$this
->assertSession()
->titleEquals("{$title_prefix} {$node_title}");
$title_prefix = $this
->updateView();
$this
->drupalGet("/{$page_path}");
$this
->assertSession()
->titleEquals("{$title_prefix} {$node_title}");
$this
->drupalGet("/{$page_path}");
$this
->assertSession()
->titleEquals("{$title_prefix} {$node_title}");
}
protected function updateView(bool $assert_ui = FALSE) : string {
$title_prefix = $this
->randomMachineName();
$edit = [
'title' => $title_prefix . ' {{ title }}',
'tokenize' => 1,
];
$metatag_settings_path = '/admin/structure/views/nojs/display/test/page_1/metatags';
$this
->drupalGet($metatag_settings_path);
$this
->submitForm($edit, 'Apply');
if ($assert_ui) {
$this
->drupalGet($metatag_settings_path);
$actual = $this
->getSession()
->getPage()
->find('css', '#edit-title')
->getAttribute('value');
$this
->assertSame($edit['title'], $actual);
}
$this
->drupalGet('/admin/structure/views/view/test');
$this
->submitForm([], 'Save');
return $title_prefix;
}
}