/** * Tests install profile config changes. */ function testInstallProfileConfigOverwrite() { $config_name = 'system.cron'; // The expected configuration from the system module. $expected_original_data = array('threshold' => array('autorun' => 0, 'requirements_warning' => 172800, 'requirements_error' => 1209600)); // The expected active configuration altered by the install profile. $expected_profile_data = array('threshold' => array('autorun' => 0, 'requirements_warning' => 259200, 'requirements_error' => 1209600)); // Verify that the original data matches. We have to read the module config // file directly, because the install profile default system.cron.yml // configuration file was used to create the active configuration. $config_dir = drupal_get_path('module', 'system') . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY; $this->assertTrue(is_dir($config_dir)); $source_storage = new FileStorage($config_dir); $data = $source_storage->read($config_name); $this->assertIdentical($data, $expected_original_data); // Verify that active configuration matches the expected data, which was // created from the testing install profile's system.cron.yml file. $config = $this->config($config_name); $this->assertIdentical($config->get(), $expected_profile_data); // Ensure that the configuration entity has the expected dependencies and // overrides. $action = Action::load('user_block_user_action'); $this->assertEqual($action->label(), 'Overridden block the selected user(s)'); $action = Action::load('user_cancel_user_action'); $this->assertEqual($action->label(), 'Cancel the selected user account(s)', 'Default configuration that is not overridden is not affected.'); // Ensure that optional configuration can be overridden. $tour = Tour::load('language'); $this->assertEqual(count($tour->getTips()), 1, 'Optional configuration can be overridden. The language tour only has one tip'); $tour = Tour::load('language-add'); $this->assertEqual(count($tour->getTips()), 3, 'Optional configuration that is not overridden is not affected.'); // Ensure that optional configuration from a profile is created if // dependencies are met. $this->assertEqual(Tour::load('testing_config_overrides')->label(), 'Config override test'); // Ensure that optional configuration from a profile is not created if // dependencies are not met. Cannot use the entity system since the entity // type does not exist. $optional_dir = drupal_get_path('module', 'testing_config_overrides') . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY; $optional_storage = new FileStorage($optional_dir); foreach (['config_test.dynamic.dotted.default', 'config_test.dynamic.override', 'config_test.dynamic.override_unmet'] as $id) { $this->assertTrue(\Drupal::config($id)->isNew(), "The config_test entity {$id} contained in the profile's optional directory does not exist."); // Make that we don't get false positives from the assertion above. $this->assertTrue($optional_storage->exists($id), "The config_test entity {$id} does exist in the profile's optional directory."); } // Install the config_test module and ensure that the override from the // install profile is not used. Optional configuration can not override // configuration in a modules config/install directory. $this->container->get('module_installer')->install(['config_test']); $this->rebuildContainer(); $config_test_storage = \Drupal::entityManager()->getStorage('config_test'); $this->assertEqual($config_test_storage->load('dotted.default')->label(), 'Default', 'The config_test entity is not overridden by the profile optional configuration.'); // Test that override of optional configuration does work. $this->assertEqual($config_test_storage->load('override')->label(), 'Override', 'The optional config_test entity is overridden by the profile optional configuration.'); // Test that override of optional configuration which introduces an unmet // dependency does not get created. $this->assertNull($config_test_storage->load('override_unmet'), 'The optional config_test entity with unmet dependencies is not created.'); // Installing dblog creates the optional configuration. $this->container->get('module_installer')->install(['dblog']); $this->rebuildContainer(); $this->assertEqual($config_test_storage->load('override_unmet')->label(), 'Override', 'The optional config_test entity is overridden by the profile optional configuration and is installed when its dependencies are met.'); }
/** * Tests cache tags presence and invalidation of the Tour entity. * * Tests the following cache tags: * - 'tour:<tour ID>' */ public function testRenderedTour() { $path = 'tour-test-1'; // Prime the page cache. $this->verifyPageCache($path, 'MISS'); // Verify a cache hit, but also the presence of the correct cache tags. $expected_tags = array('theme:stark', 'theme_global_settings', 'tour:tour-test', 'rendered'); $this->verifyPageCache($path, 'HIT', $expected_tags); // Verify that after modifying the tour, there is a cache miss. $this->pass('Test modification of tour.', 'Debug'); Tour::load('tour-test')->save(); $this->verifyPageCache($path, 'MISS'); // Verify a cache hit. $this->verifyPageCache($path, 'HIT', $expected_tags); // Verify that after deleting the tour, there is a cache miss. $this->pass('Test deletion of tour.', 'Debug'); Tour::load('tour-test')->delete(); $this->verifyPageCache($path, 'MISS'); // Verify a cache hit. $this->verifyPageCache($path, 'HIT', array('rendered', 'theme:stark', 'theme_global_settings')); }
/** * Tests cache tags presence and invalidation of the Tour entity. * * Tests the following cache tags: * - 'tour:<tour ID>' */ public function testRenderedTour() { $url = Url::fromRoute('tour_test.1'); // Prime the page cache. $this->verifyPageCache($url, 'MISS'); // Verify a cache hit, but also the presence of the correct cache tags. $expected_tags = ['config:tour.tour.tour-test', 'config:user.role.anonymous', 'rendered']; $this->verifyPageCache($url, 'HIT', $expected_tags); // Verify that after modifying the tour, there is a cache miss. $this->pass('Test modification of tour.', 'Debug'); Tour::load('tour-test')->save(); $this->verifyPageCache($url, 'MISS'); // Verify a cache hit. $this->verifyPageCache($url, 'HIT', $expected_tags); // Verify that after deleting the tour, there is a cache miss. $this->pass('Test deletion of tour.', 'Debug'); Tour::load('tour-test')->delete(); $this->verifyPageCache($url, 'MISS'); // Verify a cache hit. $expected_tags = ['config:user.role.anonymous', 'rendered']; $this->verifyPageCache($url, 'HIT', $expected_tags); }
/** * Test tour functionality. */ public function testTourFunctionality() { // Navigate to tour-test-1 and verify the tour_test_1 tip is found with appropriate classes. $this->drupalGet('tour-test-1'); // Test the TourTestBase class assertTourTips() method. $tips = array(); $tips[] = array('data-id' => 'tour-test-1'); $tips[] = array('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)]]', array(':classes' => 'tip-module-tour-test tip-type-text tip-tour-test-1', ':data_id' => 'tour-test-1', ':href' => \Drupal::url('<front>', [], ['absolute' => TRUE]), ':text' => 'Drupal')); $this->assertEqual(count($elements), 1, 'Found Token replacement.'); $elements = $this->cssSelect("li[data-id=tour-test-1] h2:contains('The first tip')"); $this->assertEqual(count($elements), 1, 'Found English variant of tip 1.'); $elements = $this->cssSelect("li[data-id=tour-test-2] h2:contains('The quick brown fox')"); $this->assertNotEqual(count($elements), 1, '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->assertNotEqual(count($elements), 1, 'Did not find Italian variant of tip 1.'); // Ensure that plugins work. $elements = $this->xpath('//img[@src="http://local/image.png"]'); $this->assertEqual(count($elements), 1, 'Image plugin tip found.'); // Navigate to tour-test-2/subpath and verify the tour_test_2 tip is found. $this->drupalGet('tour-test-2/subpath'); $elements = $this->cssSelect("li[data-id=tour-test-2] h2:contains('The quick brown fox')"); $this->assertEqual(count($elements), 1, 'Found English variant of tip 2.'); $elements = $this->cssSelect("li[data-id=tour-test-1] h2:contains('The first tip')"); $this->assertNotEqual(count($elements), 1, 'Did not find English variant of tip 1.'); // Enable Italian language and navigate to it/tour-test1 and verify italian // version of tip is found. 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->assertEqual(count($elements), 1, 'Found Italian variant of tip 1.'); $elements = $this->cssSelect("li[data-id=tour-test-2] h2:contains('The quick brown fox')"); $this->assertNotEqual(count($elements), 1, 'Did not find English variant of tip 1.'); // Programmatically create a tour for use through the remainder of the test. $tour = Tour::create(array('id' => 'tour-entity-create-test-en', 'label' => 'Tour test english', 'langcode' => 'en', 'module' => 'system', 'routes' => array(array('route_name' => 'tour_test.1')), 'tips' => array('tour-test-1' => array('id' => 'tour-code-test-1', 'plugin' => 'text', 'label' => 'The rain in spain', 'body' => 'Falls mostly on the plain.', 'weight' => '100', 'attributes' => array('data-id' => 'tour-code-test-1')), 'tour-code-test-2' => array('id' => 'tour-code-test-2', 'plugin' => 'image', 'label' => 'The awesome image', 'url' => 'http://local/image.png', 'weight' => 1, 'attributes' => array('data-id' => 'tour-code-test-2'))))); $tour->save(); // Ensure that a tour entity has the expected dependencies based on plugin // providers and the module named in the configuration entity. $dependencies = $tour->calculateDependencies()->getDependencies(); $this->assertEqual($dependencies['module'], array('system', 'tour_test')); $this->drupalGet('tour-test-1'); // Load it back from the database and verify storage worked. $entity_save_tip = Tour::load('tour-entity-create-test-en'); // Verify that hook_ENTITY_TYPE_load() integration worked. $this->assertEqual($entity_save_tip->loaded, 'Load hooks work'); // Verify that hook_ENTITY_TYPE_presave() integration worked. $this->assertEqual($entity_save_tip->label(), 'Tour test english alter'); // Navigate to tour-test-1 and verify the new tip is found. $this->drupalGet('tour-test-1'); $elements = $this->cssSelect("li[data-id=tour-code-test-1] h2:contains('The rain in spain')"); $this->assertEqual(count($elements), 1, 'Found the required tip markup for tip 4'); // Verify that the weight sorting works by ensuring the lower weight item // (tip 4) has the 'End tour' button. $elements = $this->cssSelect("li[data-id=tour-code-test-1][data-text='End tour']"); $this->assertEqual(count($elements), 1, 'Found code tip was weighted last and had "End tour".'); // Test hook_tour_alter(). $this->assertText('Altered by hook_tour_tips_alter'); // Navigate to tour-test-3 and verify the tour_test_1 tip is found with // appropriate classes. $this->drupalGet('tour-test-3/foo'); $elements = $this->xpath('//li[@data-id=:data_id and @class=:classes and ./h2[contains(., :text)]]', array(':classes' => 'tip-module-tour-test tip-type-text tip-tour-test-1', ':data_id' => 'tour-test-1', ':text' => 'The first tip')); $this->assertEqual(count($elements), 1, 'Found English variant of tip 1.'); // Navigate to tour-test-3 and verify the tour_test_1 tip is not found with // appropriate classes. $this->drupalGet('tour-test-3/bar'); $elements = $this->xpath('//li[@data-id=:data_id and @class=:classes and ./h2[contains(., :text)]]', array(':classes' => 'tip-module-tour-test tip-type-text tip-tour-test-1', ':data_id' => 'tour-test-1', ':text' => 'The first tip')); $this->assertEqual(count($elements), 0, 'Did not find English variant of tip 1.'); }