View source
<?php
namespace Drupal\Tests\tour\Functional;
use Drupal\Core\Url;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\tour\Entity\Tour;
class TourTest extends TourTestBasic {
public static $modules = [
'block',
'tour',
'locale',
'language',
'tour_test',
];
protected $defaultTheme = 'stark';
protected $permissions = [
'access tour',
'administer languages',
];
protected $tips = [
'tour-test-1' => [],
];
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('local_actions_block', [
'theme' => 'seven',
'region' => 'content',
]);
}
public function testTourFunctionality() {
$this
->drupalGet('tour-test-1');
$tips = [];
$tips[] = [
'data-id' => 'tour-test-1',
];
$tips[] = [
'data-class' => 'tour-test-5',
];
$this
->assertTourTips($tips);
$this
->assertTourTips();
$elements = $this
->xpath('//li[@data-id=:data_id and @class=:classes and ./p//a[@href=:href and contains(., :text)]]', [
':classes' => 'tip-module-tour-test tip-type-text tip-tour-test-1',
':data_id' => 'tour-test-1',
':href' => Url::fromRoute('<front>', [], [
'absolute' => TRUE,
])
->toString(),
':text' => 'Drupal',
]);
$this
->assertCount(1, $elements, 'Found Token replacement.');
$elements = $this
->cssSelect("li[data-id=tour-test-1] h2:contains('The first tip')");
$this
->assertCount(1, $elements, 'Found English variant of tip 1.');
$elements = $this
->cssSelect("li[data-id=tour-test-2] h2:contains('The quick brown fox')");
$this
->assertNotCount(1, $elements, 'Did not find English variant of tip 2.');
$elements = $this
->cssSelect("li[data-id=tour-test-1] h2:contains('La pioggia cade in spagna')");
$this
->assertNotCount(1, $elements, 'Did not find Italian variant of tip 1.');
$elements = $this
->xpath('//img[@src="http://local/image.png"]');
$this
->assertCount(1, $elements, 'Image plugin tip found.');
$this
->drupalGet('tour-test-2/subpath');
$elements = $this
->cssSelect("li[data-id=tour-test-2] h2:contains('The quick brown fox')");
$this
->assertCount(1, $elements, 'Found English variant of tip 2.');
$elements = $this
->cssSelect("li[data-id=tour-test-1] h2:contains('The first tip')");
$this
->assertNotCount(1, $elements, 'Did not find English variant of tip 1.');
ConfigurableLanguage::createFromLangcode('it')
->save();
$this
->drupalGet('it/tour-test-1');
$elements = $this
->cssSelect("li[data-id=tour-test-1] h2:contains('La pioggia cade in spagna')");
$this
->assertCount(1, $elements, 'Found Italian variant of tip 1.');
$elements = $this
->cssSelect("li[data-id=tour-test-2] h2:contains('The quick brown fox')");
$this
->assertNotCount(1, $elements, 'Did not find English variant of tip 1.');
$tour = Tour::create([
'id' => 'tour-entity-create-test-en',
'label' => 'Tour test english',
'langcode' => 'en',
'module' => 'system',
'routes' => [
[
'route_name' => 'tour_test.1',
],
],
'tips' => [
'tour-test-1' => [
'id' => 'tour-code-test-1',
'plugin' => 'text',
'label' => 'The rain in spain',
'body' => 'Falls mostly on the plain.',
'weight' => '100',
'attributes' => [
'data-id' => 'tour-code-test-1',
],
],
'tour-code-test-2' => [
'id' => 'tour-code-test-2',
'plugin' => 'image',
'label' => 'The awesome image',
'url' => 'http://local/image.png',
'weight' => 1,
'attributes' => [
'data-id' => 'tour-code-test-2',
],
],
],
]);
$tour
->save();
$dependencies = $tour
->calculateDependencies()
->getDependencies();
$this
->assertEqual($dependencies['module'], [
'system',
'tour_test',
]);
$this
->drupalGet('tour-test-1');
$entity_save_tip = Tour::load('tour-entity-create-test-en');
$this
->assertEqual($entity_save_tip->loaded, 'Load hooks work');
$this
->assertEqual($entity_save_tip
->label(), 'Tour test english alter');
$this
->drupalGet('tour-test-1');
$elements = $this
->cssSelect("li[data-id=tour-code-test-1] h2:contains('The rain in spain')");
$this
->assertCount(1, $elements, 'Found the required tip markup for tip 4');
$elements = $this
->cssSelect("li[data-id=tour-code-test-1][data-text='End tour']");
$this
->assertCount(1, $elements, 'Found code tip was weighted last and had "End tour".');
$this
->assertText('Altered by hook_tour_tips_alter');
$this
->drupalGet('tour-test-3/foo');
$elements = $this
->xpath('//li[@data-id=:data_id and @class=:classes and ./h2[contains(., :text)]]', [
':classes' => 'tip-module-tour-test tip-type-text tip-tour-test-1',
':data_id' => 'tour-test-1',
':text' => 'The first tip',
]);
$this
->assertCount(1, $elements, 'Found English variant of tip 1.');
$this
->drupalGet('tour-test-3/bar');
$elements = $this
->xpath('//li[@data-id=:data_id and @class=:classes and ./h2[contains(., :text)]]', [
':classes' => 'tip-module-tour-test tip-type-text tip-tour-test-1',
':data_id' => 'tour-test-1',
':text' => 'The first tip',
]);
$this
->assertCount(0, $elements, 'Did not find English variant of tip 1.');
}
}