View source
<?php
namespace Drupal\Tests\render_example\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class RenderExampleTest extends BrowserTestBase {
protected $defaultTheme = 'bartik';
public static $modules = [
'render_example',
];
public $profile = 'standard';
public function testRenderExample() {
$web_user = $this
->createUser([
'access content',
]);
$this
->drupalLogin($web_user);
$session = $this
->assertSession();
$altering_url = Url::fromRoute('render_example.altering');
$this
->drupalGet($altering_url);
$session
->pageTextContains('Install the Devel module (https://www.drupal.org/project/devel) to enable additional demonstration features.');
$breadcrumb_xpath = "//main[@id='content']//div[contains(@class, 'block-system-breadcrumb-block')]";
$this
->assertEmpty($this
->xpath($breadcrumb_xpath));
$this
->drupalPostForm($altering_url, [
'render_example_move_breadcrumbs' => TRUE,
'render_example_reverse_sidebar' => FALSE,
'render_example_wrap_blocks' => FALSE,
], 'Save configuration');
$this
->assertNotEmpty($this
->xpath($breadcrumb_xpath));
$breadcrumb_xpath = "//div[contains(@class,'region-sidebar-first')]/*";
$elements = $this
->xpath($breadcrumb_xpath);
$this
->assertEquals('div', $elements[0]
->getTagName());
$this
->assertTrue($elements[0]
->hasClass('block-search'));
$this
->assertEquals('nav', $elements[1]
->getTagName());
$this
->drupalPostForm($altering_url, [
'render_example_move_breadcrumbs' => FALSE,
'render_example_reverse_sidebar' => TRUE,
'render_example_wrap_blocks' => FALSE,
], 'Save configuration');
$elements = $this
->xpath($breadcrumb_xpath);
$this
->assertEquals('nav', $elements[0]
->getTagName());
$this
->assertEquals('div', $elements[1]
->getTagName());
$this
->assertTrue($elements[1]
->hasClass('block-search'));
$xpath = "//div[contains(@class,'block')]//div[@class='content']/div[@class='block-prefix']";
$this
->assertEmpty($this
->xpath($xpath));
$this
->drupalPostForm($altering_url, [
'render_example_move_breadcrumbs' => FALSE,
'render_example_reverse_sidebar' => FALSE,
'render_example_wrap_blocks' => TRUE,
], 'Save configuration');
$this
->assertNotEmpty($this
->xpath($xpath));
$this
->drupalGet(Url::fromRoute('render_example.arrays'));
$xpath_array = [
'foof' => 'Hello ' . $web_user
->getAccountName() . ', welcome to the #cache example.',
];
foreach ($xpath_array as $value) {
$session
->pageTextContains($value);
}
}
}