diff --git a/core/modules/system/lib/Drupal/system/Tests/Module/ExtendTourTest.php b/core/modules/system/lib/Drupal/system/Tests/Module/ExtendTourTest.php index 9523943..46950ab 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Module/ExtendTourTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Module/ExtendTourTest.php @@ -13,19 +13,20 @@ * Tests tour functionality. */ class ExtendTourTest extends TourTestBase { + /** - * An admin user with administrative permissions for extends. + * Permissions to grant the admin. * - * @var \Drupal\user\UserInterface + * @var array */ - protected $adminUser; + protected $adminPermissions = array('administer modules'); /** * Modules to enable * * @var array */ - public static $modules = array('user', 'tour'); + public static $modules = array('user', 'tour', 'update', 'block', 'help'); public static function getInfo() { return array( @@ -35,12 +36,6 @@ public static function getInfo() { ); } - protected function setUp() { - parent::setUp(); - $this->adminUser = $this->drupalCreateUser(array('access tour', 'administer modules')); - $this->drupalLogin($this->adminUser); - } - /** * Tests extends tour tip availability. */ diff --git a/core/modules/tour/lib/Drupal/tour/Tests/TourTestBase.php b/core/modules/tour/lib/Drupal/tour/Tests/TourTestBase.php index 0beb7f0..dedc812 100644 --- a/core/modules/tour/lib/Drupal/tour/Tests/TourTestBase.php +++ b/core/modules/tour/lib/Drupal/tour/Tests/TourTestBase.php @@ -12,7 +12,38 @@ /** * Tests tour functionality. */ -class TourTestBase extends WebTestBase { +abstract class TourTestBase extends WebTestBase { + + /** + * An admin user with administrative permissions for extends. + * + * @var \Drupal\user\UserInterface + */ + protected $adminUser; + + /** + * An array of permissions to grant an admin user to test tour output. + * + * Note \Drupal\tour\Tests\TourTestBase::setUp() will add 'access tour' and + * 'view the administration theme' to this list. + * + * @var array + */ + protected $adminPermissions = array(); + + /** + * Set the admin theme to seven for testing tour markup. + */ + protected function setUp() { + parent::setUp(); + // Set seven as the admin theme. + \Drupal::service('theme_handler')->enable(array('seven')); + \Drupal::config('system.theme')->set('admin', 'seven')->save(); + \Drupal::config('node.settings')->set('use_admin_theme', '1')->save(); + // Login an admin user. + $this->adminUser = $this->drupalCreateUser(array_merge($this->adminPermissions, array('access tour', 'view the administration theme'))); + $this->drupalLogin($this->adminUser); + } /** * Assert function to determine if tips rendered to the page @@ -56,10 +87,24 @@ public function assertTourTips($tips = array()) { foreach ($tips as $tip) { if (!empty($tip['data-id'])) { $elements = \PHPUnit_Util_XML::cssSelect('#' . $tip['data-id'], TRUE, $this->content, TRUE); + if ($elements == 0) { + // Could be a html5 element that \PHPUnit_Util_XML::cssSelect() does + // not support, fallback to xpath. + $elements = $this->xpath('//*[@id = :id]', array( + ':id' => $tip['data-id'], + )); + } $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']))); } else if (!empty($tip['data-class'])) { $elements = \PHPUnit_Util_XML::cssSelect('.' . $tip['data-class'], TRUE, $this->content, TRUE); + if ($elements == 0) { + // Could be a html5 element that \PHPUnit_Util_XML::cssSelect() does + // not support, fallback to xpath. + $elements = $this->xpath('//*[@class = :class]', array( + ':class' => $tip['data-class'], + )); + } $this->assertFalse(empty($elements), format_string('Found corresponding page element for tour tip with class .%data-class', array('%data-class' => $tip['data-class']))); } else {