diff --git a/core/modules/language/src/Tests/LanguageTourTest.php b/core/modules/language/src/Tests/LanguageTourTest.php index 7778367..06e449f 100644 --- a/core/modules/language/src/Tests/LanguageTourTest.php +++ b/core/modules/language/src/Tests/LanguageTourTest.php @@ -2,7 +2,7 @@ namespace Drupal\language\Tests; -use Drupal\tour\Tests\TourTestBase; +use Drupal\Tests\tour\Functional\TourTestBase; /** * Tests tour functionality. diff --git a/core/modules/locale/src/Tests/LocaleTranslateStringTourTest.php b/core/modules/locale/src/Tests/LocaleTranslateStringTourTest.php index 5c642f2..1c16ca4 100644 --- a/core/modules/locale/src/Tests/LocaleTranslateStringTourTest.php +++ b/core/modules/locale/src/Tests/LocaleTranslateStringTourTest.php @@ -2,7 +2,7 @@ namespace Drupal\locale\Tests; -use Drupal\tour\Tests\TourTestBase; +use Drupal\Tests\tour\Functional\TourTestBase; /** * Tests the Translate Interface tour. diff --git a/core/modules/tour/tests/src/Functional/TourCacheTagsTest.php b/core/modules/tour/tests/src/Functional/TourCacheTagsTest.php index c7048fb..087cf6f 100644 --- a/core/modules/tour/tests/src/Functional/TourCacheTagsTest.php +++ b/core/modules/tour/tests/src/Functional/TourCacheTagsTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\tour\Functional; use Drupal\Core\Url; -use Drupal\system\Tests\Cache\PageCacheTagsTestBase; +use Drupal\Tests\system\Functional\Cache\PageCacheTagsTestBase; use Drupal\tour\Entity\Tour; use Drupal\user\Entity\Role; use Drupal\user\RoleInterface; diff --git a/core/modules/tour/src/Tests/TourHelpPageTest.php b/core/modules/tour/tests/src/Functional/TourHelpPageTest.php similarity index 90% rename from core/modules/tour/src/Tests/TourHelpPageTest.php rename to core/modules/tour/tests/src/Functional/TourHelpPageTest.php index 8a41eb9..78b35d0 100644 --- a/core/modules/tour/src/Tests/TourHelpPageTest.php +++ b/core/modules/tour/tests/src/Functional/TourHelpPageTest.php @@ -1,15 +1,15 @@ assertText('Tours guide you through workflows'); } else { - $this->assertNoText('Tours guide you through workflows'); + $this->assertSession()->pageTextNotContains('Tours guide you through workflows'); } $titles = $this->getTourList(); @@ -87,7 +87,7 @@ protected function verifyHelp($tours_ok = TRUE) { $this->assertLink($title); } else { - $this->assertNoLink($title); + $this->assertSession()->linkNotExists($title); // Just test the first item in the list of links that should not // be there, because the second matches the name of a module that is // in the Module overviews section, so the link will be there and @@ -101,10 +101,10 @@ protected function verifyHelp($tours_ok = TRUE) { foreach ($titles[1] as $title) { if ($tours_ok) { $this->assertText($title); - $this->assertNoLink($title); + $this->assertSession()->linkNotExists($title); } else { - $this->assertNoText($title); + $this->assertSession()->pageTextNotContains($title); // Just test the first item in the list of text that should not // be there, because the second matches part of the name of a module // that is in the Module overviews section, so the text will be there @@ -135,7 +135,7 @@ protected function getModuleList() { * not 'translate interface'. */ protected function getTourList() { - return [['Adding languages', 'Language'], ['Editing languages', 'Translation']]; + return [['Adding languages', 'Language'], ['Editing languages']]; } } diff --git a/core/modules/tour/src/Tests/TourTest.php b/core/modules/tour/tests/src/Functional/TourTest.php similarity index 71% rename from core/modules/tour/src/Tests/TourTest.php rename to core/modules/tour/tests/src/Functional/TourTest.php index 78304c6..f500183 100644 --- a/core/modules/tour/src/Tests/TourTest.php +++ b/core/modules/tour/tests/src/Functional/TourTest.php @@ -1,7 +1,8 @@ array(), + 'tour-test-1' => array(), ); /** @@ -63,34 +65,34 @@ public function testTourFunctionality() { $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( + $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' => \Drupal::url('', [], ['absolute' => TRUE]), + ':href' => Url::fromRoute('', [], ['absolute' => TRUE])->toString(), ':text' => 'Drupal', - )); - $this->assertEqual(count($elements), 1, 'Found Token replacement.'); + ]); + $this->assertEquals(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.'); + $this->assertEquals(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.'); + $this->assertNotEquals(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.'); + $this->assertNotEquals(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.'); + $this->assertEquals(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.'); + $this->assertEquals(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.'); + $this->assertNotEquals(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. @@ -98,68 +100,68 @@ public function testTourFunctionality() { $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.'); + $this->assertEquals(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.'); + $this->assertNotEquals(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( + $tour = Tour::create([ '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( + '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' => array( + 'attributes' => [ 'data-id' => 'tour-code-test-1', - ), - ), - 'tour-code-test-2' => array( + ], + ], + 'tour-code-test-2' => [ 'id' => 'tour-code-test-2', 'plugin' => 'image', 'label' => 'The awesome image', 'url' => 'http://local/image.png', 'weight' => 1, - 'attributes' => array( + 'attributes' => [ '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->assertEquals($dependencies['module'], ['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'); + $this->assertEquals($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'); + $this->assertEquals($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'); + $this->assertEquals(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".'); + $this->assertEquals(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'); @@ -167,22 +169,22 @@ public function testTourFunctionality() { // 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( + $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->assertEqual(count($elements), 1, 'Found English variant of tip 1.'); + ]); + $this->assertEquals(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( + $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->assertEqual(count($elements), 0, 'Did not find English variant of tip 1.'); + ]); + $this->assertEquals(count($elements), 0, 'Did not find English variant of tip 1.'); } } diff --git a/core/modules/tour/src/Tests/TourTestBase.php b/core/modules/tour/tests/src/Functional/TourTestBase.php similarity index 66% rename from core/modules/tour/src/Tests/TourTestBase.php rename to core/modules/tour/tests/src/Functional/TourTestBase.php index 8383c99..c51a115 100644 --- a/core/modules/tour/src/Tests/TourTestBase.php +++ b/core/modules/tour/tests/src/Functional/TourTestBase.php @@ -1,17 +1,17 @@ assertTourTips($tips); * @endcode */ - public function assertTourTips($tips = array()) { + protected function assertTourTips($tips = []) { // Get the rendered tips and their data-id and data-class attributes. if (empty($tips)) { // Tips are rendered as
  • elements inside
      . $rendered_tips = $this->xpath('//ol[@id = "tour"]//li[starts-with(@class, "tip")]'); foreach ($rendered_tips as $rendered_tip) { - $attributes = (array) $rendered_tip->attributes(); - $tips[] = $attributes['@attributes']; + $tips[] = [ + 'data-id' => $rendered_tip->getAttribute('data-id'), + 'data-class' => $rendered_tip->getAttribute('data-class'), + ]; } } @@ -48,14 +50,15 @@ public function assertTourTips($tips = array()) { // Check for corresponding page elements. $total = 0; $modals = 0; + $raw_content = $this->getSession()->getPage()->getContent(); foreach ($tips as $tip) { if (!empty($tip['data-id'])) { - $elements = \PHPUnit_Util_XML::cssSelect('#' . $tip['data-id'], TRUE, $this->content, TRUE); - $this->assertTrue(!empty($elements) && count($elements) === 1, format_string('Found corresponding page element for tour tip with id #%data-id', array('%data-id' => $tip['data-id']))); + $elements = \PHPUnit_Util_XML::cssSelect('#' . $tip['data-id'], TRUE, $raw_content, TRUE); + $this->assertCount(1, $elements); } elseif (!empty($tip['data-class'])) { - $elements = \PHPUnit_Util_XML::cssSelect('.' . $tip['data-class'], TRUE, $this->content, TRUE); - $this->assertFalse(empty($elements), format_string('Found corresponding page element for tour tip with class .%data-class', array('%data-class' => $tip['data-class']))); + $elements = \PHPUnit_Util_XML::cssSelect('.' . $tip['data-class'], TRUE, $raw_content, TRUE); + $this->assertNotEmpty($elements); } else { // It's a modal. diff --git a/core/modules/tour/src/Tests/TourTestBasic.php b/core/modules/tour/tests/src/Functional/TourTestBasic.php similarity index 77% rename from core/modules/tour/src/Tests/TourTestBasic.php rename to core/modules/tour/tests/src/Functional/TourTestBasic.php index e79eb2b..2ed93a7 100644 --- a/core/modules/tour/src/Tests/TourTestBasic.php +++ b/core/modules/tour/tests/src/Functional/TourTestBasic.php @@ -1,6 +1,6 @@ array( - * array('data-id' => 'foo'), - * array('data-class' => 'bar'), - * ), - * ); + * protected $tips = [ + * '/foo/bar' => [ + * ['data-id' => 'foo'], + * ['data-class' => 'bar'], + * ], + * ]; * @endcode */ protected $tips = array(); @@ -37,14 +37,14 @@ * @var array * A list of permissions. */ - protected $permissions = array('access tour'); + protected $permissions = ['access tour']; protected function setUp() { parent::setUp(); - // Make sure we are using distinct default and administrative themes for - // the duration of these tests. - $this->container->get('theme_handler')->install(array('bartik', 'seven')); + // Make sure we are using distinct default and administrative themes for the + // duration of these tests. + $this->container->get('theme_handler')->install(['bartik', 'seven']); $this->config('system.theme') ->set('default', 'bartik') ->set('admin', 'seven') diff --git a/core/modules/tour/tests/src/Kernel/TourPluginTest.php b/core/modules/tour/tests/src/Kernel/TourPluginTest.php index 9278e2e..835c8b6 100644 --- a/core/modules/tour/tests/src/Kernel/TourPluginTest.php +++ b/core/modules/tour/tests/src/Kernel/TourPluginTest.php @@ -16,7 +16,7 @@ class TourPluginTest extends KernelTestBase { * * @var array */ - public static $modules = array('tour'); + public static $modules = ['tour']; /** * Stores the tour plugin manager. @@ -28,7 +28,7 @@ class TourPluginTest extends KernelTestBase { protected function setUp() { parent::setUp(); - $this->installConfig(array('tour')); + $this->installConfig(['tour']); $this->pluginManager = $this->container->get('plugin.manager.tour.tip'); } @@ -36,7 +36,7 @@ protected function setUp() { * Test tour plugins. */ public function testTourPlugins() { - $this->assertIdentical(count($this->pluginManager->getDefinitions()), 1, 'Only tour plugins for the enabled modules were returned.'); + $this->assertSame(count($this->pluginManager->getDefinitions()), 1, 'Only tour plugins for the enabled modules were returned.'); } } diff --git a/core/modules/tour/tests/src/Unit/Entity/TourTest.php b/core/modules/tour/tests/src/Unit/Entity/TourTest.php index 2c71aa9..de847bc 100644 --- a/core/modules/tour/tests/src/Unit/Entity/TourTest.php +++ b/core/modules/tour/tests/src/Unit/Entity/TourTest.php @@ -29,7 +29,7 @@ class TourTest extends UnitTestCase { public function testHasMatchingRoute($routes, $route_name, $route_params, $result) { $tour = $this->getMockBuilder('\Drupal\tour\Entity\Tour') ->disableOriginalConstructor() - ->setMethods(array('getRoutes')) + ->setMethods(['getRoutes']) ->getMock(); $tour->expects($this->any()) @@ -45,94 +45,94 @@ public function testHasMatchingRoute($routes, $route_name, $route_params, $resul * Provides sample routes for testing. */ public function routeProvider() { - return array( + return [ // Simple match. - array( - array( - array('route_name' => 'some.route'), - ), + [ + [ + ['route_name' => 'some.route'], + ], 'some.route', array(), TRUE, - ), + ], // Simple non-match. - array( - array( - array('route_name' => 'another.route'), - ), + [ + [ + ['route_name' => 'another.route'], + ], 'some.route', array(), FALSE, - ), + ], // Empty params. - array( - array( - array( + [ + [ + [ 'route_name' => 'some.route', - 'route_params' => array('foo' => 'bar'), - ), - ), + 'route_params' => ['foo' => 'bar'], + ], + ], 'some.route', array(), FALSE, - ), + ], // Match on params. - array( - array( - array( + [ + [ + [ 'route_name' => 'some.route', - 'route_params' => array('foo' => 'bar'), - ), - ), + 'route_params' => ['foo' => 'bar'], + ], + ], 'some.route', - array('foo' => 'bar'), + ['foo' => 'bar'], TRUE, - ), + ], // Non-matching params. - array( - array( - array( + [ + [ + [ 'route_name' => 'some.route', - 'route_params' => array('foo' => 'bar'), - ), - ), + 'route_params' => ['foo' => 'bar'], + ], + ], 'some.route', - array('bar' => 'foo'), + ['bar' => 'foo'], FALSE, - ), + ], // One matching, one not. - array( - array( - array( + [ + [ + [ 'route_name' => 'some.route', - 'route_params' => array('foo' => 'bar'), - ), - array( + 'route_params' => ['foo' => 'bar'], + ], + [ 'route_name' => 'some.route', - 'route_params' => array('bar' => 'foo'), - ), - ), + 'route_params' => ['bar' => 'foo'], + ], + ], 'some.route', - array('bar' => 'foo'), + ['bar' => 'foo'], TRUE, - ), + ], // One matching, one not. - array( - array( - array( + [ + [ + [ 'route_name' => 'some.route', - 'route_params' => array('foo' => 'bar'), - ), - array( + 'route_params' => ['foo' => 'bar'], + ], + [ 'route_name' => 'some.route', - 'route_params' => array('foo' => 'baz'), - ), - ), + 'route_params' => ['foo' => 'baz'], + ], + ], 'some.route', - array('foo' => 'baz'), + ['foo' => 'baz'], TRUE, - ), - ); + ], + ]; } } diff --git a/core/modules/tour/tests/tour_test/src/Controller/TourTestController.php b/core/modules/tour/tests/tour_test/src/Controller/TourTestController.php index 87b817d..56505aa 100644 --- a/core/modules/tour/tests/tour_test/src/Controller/TourTestController.php +++ b/core/modules/tour/tests/tour_test/src/Controller/TourTestController.php @@ -18,56 +18,56 @@ class TourTestController { * Array of markup. */ public function tourTest1($locale = 'foo') { - return array( - 'tip-1' => array( + return [ + 'tip-1' => [ '#type' => 'container', - '#attributes' => array( + '#attributes' => [ 'id' => 'tour-test-1', - ), + ], '#children' => t('Where does the rain in Spain fail?'), - ), - 'tip-3' => array( + ], + 'tip-3' => [ '#type' => 'container', - '#attributes' => array( + '#attributes' => [ 'id' => 'tour-test-3', - ), + ], '#children' => t('Tip created now?'), - ), - 'tip-4' => array( + ], + 'tip-4' => [ '#type' => 'container', - '#attributes' => array( + '#attributes' => [ 'id' => 'tour-test-4', - ), + ], '#children' => t('Tip created later?'), - ), - 'tip-5' => array( + ], + 'tip-5' => [ '#type' => 'container', - '#attributes' => array( - 'class' => array('tour-test-5'), - ), + '#attributes' => [ + 'class' => ['tour-test-5'], + ], '#children' => t('Tip created later?'), - ), - 'code-tip-1' => array( + ], + 'code-tip-1' => [ '#type' => 'container', - '#attributes' => array( + '#attributes' => [ 'id' => 'tour-code-test-1', - ), + ], '#children' => t('Tip created now?'), - ), - ); + ], + ]; } /** * Outputs some content for testing tours. */ public function tourTest2() { - return array( + return [ '#type' => 'container', - '#attributes' => array( + '#attributes' => [ 'id' => 'tour-test-2', - ), + ], '#children' => t('Pangram example'), - ); + ]; } diff --git a/core/modules/views_ui/src/Tests/ViewsUITourTest.php b/core/modules/views_ui/src/Tests/ViewsUITourTest.php index ccc0f29..6655b87 100644 --- a/core/modules/views_ui/src/Tests/ViewsUITourTest.php +++ b/core/modules/views_ui/src/Tests/ViewsUITourTest.php @@ -2,8 +2,8 @@ namespace Drupal\views_ui\Tests; -use Drupal\tour\Tests\TourTestBase; use Drupal\language\Entity\ConfigurableLanguage; +use Drupal\Tests\tour\Functional\TourTestBase; /** * Tests the Views UI tour.