Chris@0: [], Chris@0: ]; Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function setUp() { Chris@0: parent::setUp(); Chris@0: Chris@0: $this->drupalPlaceBlock('local_actions_block', [ Chris@0: 'theme' => 'seven', Chris@17: 'region' => 'content', Chris@0: ]); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Test tour functionality. Chris@0: */ Chris@0: public function testTourFunctionality() { Chris@0: // Navigate to tour-test-1 and verify the tour_test_1 tip is found with appropriate classes. Chris@0: $this->drupalGet('tour-test-1'); Chris@0: Chris@0: // Test the TourTestBase class assertTourTips() method. Chris@0: $tips = []; Chris@0: $tips[] = ['data-id' => 'tour-test-1']; Chris@0: $tips[] = ['data-class' => 'tour-test-5']; Chris@0: $this->assertTourTips($tips); Chris@0: $this->assertTourTips(); Chris@0: Chris@0: $elements = $this->xpath('//li[@data-id=:data_id and @class=:classes and ./p//a[@href=:href and contains(., :text)]]', [ Chris@0: ':classes' => 'tip-module-tour-test tip-type-text tip-tour-test-1', Chris@0: ':data_id' => 'tour-test-1', Chris@18: ':href' => Url::fromRoute('', [], ['absolute' => TRUE])->toString(), Chris@0: ':text' => 'Drupal', Chris@0: ]); Chris@0: $this->assertEqual(count($elements), 1, 'Found Token replacement.'); Chris@0: Chris@0: $elements = $this->cssSelect("li[data-id=tour-test-1] h2:contains('The first tip')"); Chris@0: $this->assertEqual(count($elements), 1, 'Found English variant of tip 1.'); Chris@0: Chris@0: $elements = $this->cssSelect("li[data-id=tour-test-2] h2:contains('The quick brown fox')"); Chris@0: $this->assertNotEqual(count($elements), 1, 'Did not find English variant of tip 2.'); Chris@0: Chris@0: $elements = $this->cssSelect("li[data-id=tour-test-1] h2:contains('La pioggia cade in spagna')"); Chris@0: $this->assertNotEqual(count($elements), 1, 'Did not find Italian variant of tip 1.'); Chris@0: Chris@0: // Ensure that plugins work. Chris@0: $elements = $this->xpath('//img[@src="http://local/image.png"]'); Chris@0: $this->assertEqual(count($elements), 1, 'Image plugin tip found.'); Chris@0: Chris@0: // Navigate to tour-test-2/subpath and verify the tour_test_2 tip is found. Chris@0: $this->drupalGet('tour-test-2/subpath'); Chris@0: $elements = $this->cssSelect("li[data-id=tour-test-2] h2:contains('The quick brown fox')"); Chris@0: $this->assertEqual(count($elements), 1, 'Found English variant of tip 2.'); Chris@0: Chris@0: $elements = $this->cssSelect("li[data-id=tour-test-1] h2:contains('The first tip')"); Chris@0: $this->assertNotEqual(count($elements), 1, 'Did not find English variant of tip 1.'); Chris@0: Chris@0: // Enable Italian language and navigate to it/tour-test1 and verify italian Chris@0: // version of tip is found. Chris@0: ConfigurableLanguage::createFromLangcode('it')->save(); Chris@0: $this->drupalGet('it/tour-test-1'); Chris@0: Chris@0: $elements = $this->cssSelect("li[data-id=tour-test-1] h2:contains('La pioggia cade in spagna')"); Chris@0: $this->assertEqual(count($elements), 1, 'Found Italian variant of tip 1.'); Chris@0: Chris@0: $elements = $this->cssSelect("li[data-id=tour-test-2] h2:contains('The quick brown fox')"); Chris@0: $this->assertNotEqual(count($elements), 1, 'Did not find English variant of tip 1.'); Chris@0: Chris@0: // Programmatically create a tour for use through the remainder of the test. Chris@0: $tour = Tour::create([ Chris@0: 'id' => 'tour-entity-create-test-en', Chris@0: 'label' => 'Tour test english', Chris@0: 'langcode' => 'en', Chris@0: 'module' => 'system', Chris@0: 'routes' => [ Chris@0: ['route_name' => 'tour_test.1'], Chris@0: ], Chris@0: 'tips' => [ Chris@0: 'tour-test-1' => [ Chris@0: 'id' => 'tour-code-test-1', Chris@0: 'plugin' => 'text', Chris@0: 'label' => 'The rain in spain', Chris@0: 'body' => 'Falls mostly on the plain.', Chris@0: 'weight' => '100', Chris@0: 'attributes' => [ Chris@0: 'data-id' => 'tour-code-test-1', Chris@0: ], Chris@0: ], Chris@0: 'tour-code-test-2' => [ Chris@0: 'id' => 'tour-code-test-2', Chris@0: 'plugin' => 'image', Chris@0: 'label' => 'The awesome image', Chris@0: 'url' => 'http://local/image.png', Chris@0: 'weight' => 1, Chris@0: 'attributes' => [ Chris@17: 'data-id' => 'tour-code-test-2', Chris@0: ], Chris@0: ], Chris@0: ], Chris@0: ]); Chris@0: $tour->save(); Chris@0: Chris@0: // Ensure that a tour entity has the expected dependencies based on plugin Chris@0: // providers and the module named in the configuration entity. Chris@0: $dependencies = $tour->calculateDependencies()->getDependencies(); Chris@0: $this->assertEqual($dependencies['module'], ['system', 'tour_test']); Chris@0: Chris@0: $this->drupalGet('tour-test-1'); Chris@0: Chris@0: // Load it back from the database and verify storage worked. Chris@0: $entity_save_tip = Tour::load('tour-entity-create-test-en'); Chris@0: // Verify that hook_ENTITY_TYPE_load() integration worked. Chris@0: $this->assertEqual($entity_save_tip->loaded, 'Load hooks work'); Chris@0: // Verify that hook_ENTITY_TYPE_presave() integration worked. Chris@0: $this->assertEqual($entity_save_tip->label(), 'Tour test english alter'); Chris@0: Chris@0: // Navigate to tour-test-1 and verify the new tip is found. Chris@0: $this->drupalGet('tour-test-1'); Chris@0: $elements = $this->cssSelect("li[data-id=tour-code-test-1] h2:contains('The rain in spain')"); Chris@0: $this->assertEqual(count($elements), 1, 'Found the required tip markup for tip 4'); Chris@0: Chris@0: // Verify that the weight sorting works by ensuring the lower weight item Chris@0: // (tip 4) has the 'End tour' button. Chris@0: $elements = $this->cssSelect("li[data-id=tour-code-test-1][data-text='End tour']"); Chris@0: $this->assertEqual(count($elements), 1, 'Found code tip was weighted last and had "End tour".'); Chris@0: Chris@0: // Test hook_tour_alter(). Chris@0: $this->assertText('Altered by hook_tour_tips_alter'); Chris@0: Chris@0: // Navigate to tour-test-3 and verify the tour_test_1 tip is found with Chris@0: // appropriate classes. Chris@0: $this->drupalGet('tour-test-3/foo'); Chris@0: $elements = $this->xpath('//li[@data-id=:data_id and @class=:classes and ./h2[contains(., :text)]]', [ Chris@0: ':classes' => 'tip-module-tour-test tip-type-text tip-tour-test-1', Chris@0: ':data_id' => 'tour-test-1', Chris@0: ':text' => 'The first tip', Chris@0: ]); Chris@0: $this->assertEqual(count($elements), 1, 'Found English variant of tip 1.'); Chris@0: Chris@0: // Navigate to tour-test-3 and verify the tour_test_1 tip is not found with Chris@0: // appropriate classes. Chris@0: $this->drupalGet('tour-test-3/bar'); Chris@0: $elements = $this->xpath('//li[@data-id=:data_id and @class=:classes and ./h2[contains(., :text)]]', [ Chris@0: ':classes' => 'tip-module-tour-test tip-type-text tip-tour-test-1', Chris@0: ':data_id' => 'tour-test-1', Chris@0: ':text' => 'The first tip', Chris@0: ]); Chris@0: $this->assertEqual(count($elements), 0, 'Did not find English variant of tip 1.'); Chris@0: } Chris@0: Chris@0: }