StyleguidePageTest.php in Simple Style Guide 8
File
src/Tests/StyleguidePageTest.php
View source
<?php
namespace Drupal\simple_styleguide\Tests;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class StyleguidePageTest extends BrowserTestBase {
protected $strictConfigSchema = FALSE;
public static $modules = [
'simple_styleguide',
];
protected $user;
protected function setUp() {
parent::setUp();
$this->user = $this
->drupalCreateUser([
'administer site configuration',
'access style guide',
]);
$this
->drupalLogin($this->user);
}
public function testStyleGuidePageEmpty() {
$this
->drupalGet(Url::fromRoute('simple_styleguide.controller'));
$this
->assertSession()
->statusCodeEquals(200);
$no_styleguide_patterns_text = $this
->xpath($this
->cssSelectToXpath('.simple-styleguide--site-styles .site-styles--shortcuts > p'));
$this
->assertEquals('You have not selected or created any styleguide patterns.', $no_styleguide_patterns_text[0]
->getText());
$configure_link = Url::fromRoute('simple_styleguide.styleguide_settings')
->toString();
$this
->assertSession()
->linkExists('Configure Simple Styleguide');
$this
->assertSession()
->linkByHrefExists($configure_link);
}
public function testStyleGuidePageFunctional() {
$simple_style_guide_config = [
'default_patterns[headings]' => TRUE,
];
$this
->drupalPostForm('admin/config/styleguide/settings', $simple_style_guide_config, t('Save'));
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->checkboxChecked('default_patterns[headings]');
$this
->drupalGet(Url::fromRoute('simple_styleguide.controller'));
$this
->assertSession()
->statusCodeEquals(200);
$styleguide_section_headings = $this
->xpath($this
->cssSelectToXpath('.simple-styleguide--site-styles .sections > h3'));
$this
->assertEquals('headings', $styleguide_section_headings[0]
->getText());
}
}