summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLee Rowlands2017-09-13 20:30:08 (GMT)
committerLee Rowlands2017-09-13 20:30:08 (GMT)
commita739c2183f4fce921708a734410a5bf1bd43ad6f (patch)
tree22a1bbc913076a60c694db2501d711e1b0f40cd3
parent8cec5c8b907ba3090d8c0e50849d8825793b5020 (diff)
Issue #2864088 by jonathan1055, GoZ, naveenvalecha: Convert web tests to browser tests for shortcut module
-rw-r--r--core/modules/shortcut/src/Tests/ShortcutTestBase.php7
-rw-r--r--core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php (renamed from core/modules/shortcut/src/Tests/ShortcutLinksTest.php)13
-rw-r--r--core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php (renamed from core/modules/shortcut/src/Tests/ShortcutSetsTest.php)4
-rw-r--r--core/modules/shortcut/tests/src/Functional/ShortcutTestBase.php133
-rw-r--r--core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php (renamed from core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php)2
5 files changed, 151 insertions, 8 deletions
diff --git a/core/modules/shortcut/src/Tests/ShortcutTestBase.php b/core/modules/shortcut/src/Tests/ShortcutTestBase.php
index 1e3196c..584a615 100644
--- a/core/modules/shortcut/src/Tests/ShortcutTestBase.php
+++ b/core/modules/shortcut/src/Tests/ShortcutTestBase.php
@@ -2,6 +2,8 @@
namespace Drupal\shortcut\Tests;
+@trigger_error(__NAMESPACE__ . '\ShortcutTestBase is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\shortcut\Functional\ShortcutTestBase, see https://www.drupal.org/node/2906736.', E_USER_DEPRECATED);
+
use Drupal\shortcut\Entity\Shortcut;
use Drupal\shortcut\Entity\ShortcutSet;
use Drupal\shortcut\ShortcutSetInterface;
@@ -9,6 +11,11 @@ use Drupal\simpletest\WebTestBase;
/**
* Defines base class for shortcut test cases.
+ *
+ * @deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0.
+ * Use \Drupal\Tests\shortcut\Functional\ShortcutTestBase.
+ *
+ * @see https://www.drupal.org/node/2906736
*/
abstract class ShortcutTestBase extends WebTestBase {
diff --git a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php b/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php
index cf4ae0f..e39f652 100644
--- a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php
+++ b/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php
@@ -1,6 +1,6 @@
<?php
-namespace Drupal\shortcut\Tests;
+namespace Drupal\Tests\shortcut\Functional;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\Component\Utility\SafeMarkup;
@@ -8,6 +8,7 @@ use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Url;
use Drupal\shortcut\Entity\Shortcut;
use Drupal\shortcut\Entity\ShortcutSet;
+use Drupal\Tests\block\Functional\AssertBlockAppearsTrait;
use Drupal\views\Entity\View;
/**
@@ -17,6 +18,8 @@ use Drupal\views\Entity\View;
*/
class ShortcutLinksTest extends ShortcutTestBase {
+ use AssertBlockAppearsTrait;
+
/**
* Modules to enable.
*
@@ -368,15 +371,15 @@ class ShortcutLinksTest extends ShortcutTestBase {
$this->drupalLogin($this->drupalCreateUser(['access toolbar', 'access shortcuts', 'access content overview', 'administer content types']));
$this->drupalGet(Url::fromRoute('<front>'));
$shortcuts = $this->cssSelect('#toolbar-item-shortcuts-tray .toolbar-menu a');
- $this->assertEqual((string) $shortcuts[0], 'Add content');
- $this->assertEqual((string) $shortcuts[1], 'All content');
+ $this->assertEqual($shortcuts[0]->getText(), 'Add content');
+ $this->assertEqual($shortcuts[1]->getText(), 'All content');
foreach ($this->set->getShortcuts() as $shortcut) {
$shortcut->setWeight($shortcut->getWeight() * -1)->save();
}
$this->drupalGet(Url::fromRoute('<front>'));
$shortcuts = $this->cssSelect('#toolbar-item-shortcuts-tray .toolbar-menu a');
- $this->assertEqual((string) $shortcuts[0], 'All content');
- $this->assertEqual((string) $shortcuts[1], 'Add content');
+ $this->assertEqual($shortcuts[0]->getText(), 'All content');
+ $this->assertEqual($shortcuts[1]->getText(), 'Add content');
}
/**
diff --git a/core/modules/shortcut/src/Tests/ShortcutSetsTest.php b/core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php
index e34518e..b897df7 100644
--- a/core/modules/shortcut/src/Tests/ShortcutSetsTest.php
+++ b/core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php
@@ -1,6 +1,6 @@
<?php
-namespace Drupal\shortcut\Tests;
+namespace Drupal\Tests\shortcut\Functional;
use Drupal\shortcut\Entity\ShortcutSet;
@@ -68,7 +68,7 @@ class ShortcutSetsTest extends ShortcutTestBase {
// Test the contents of each th cell.
$expected_items = [t('Name'), t('Weight'), t('Operations')];
foreach ($elements as $key => $element) {
- $this->assertEqual((string) $element[0], $expected_items[$key]);
+ $this->assertEqual($element->getText(), $expected_items[$key]);
}
// Look for test shortcuts in the table.
diff --git a/core/modules/shortcut/tests/src/Functional/ShortcutTestBase.php b/core/modules/shortcut/tests/src/Functional/ShortcutTestBase.php
new file mode 100644
index 0000000..3f9cc87
--- /dev/null
+++ b/core/modules/shortcut/tests/src/Functional/ShortcutTestBase.php
@@ -0,0 +1,133 @@
+<?php
+
+namespace Drupal\Tests\shortcut\Functional;
+
+use Drupal\shortcut\Entity\Shortcut;
+use Drupal\shortcut\Entity\ShortcutSet;
+use Drupal\shortcut\ShortcutSetInterface;
+use Drupal\Tests\BrowserTestBase;
+
+/**
+ * Defines base class for shortcut test cases.
+ */
+abstract class ShortcutTestBase extends BrowserTestBase {
+
+ /**
+ * Modules to enable.
+ *
+ * @var array
+ */
+ public static $modules = ['node', 'toolbar', 'shortcut'];
+
+ /**
+ * User with permission to administer shortcuts.
+ *
+ * @var \Drupal\user\UserInterface
+ */
+ protected $adminUser;
+
+ /**
+ * User with permission to use shortcuts, but not administer them.
+ *
+ * @var \Drupal\user\UserInterface
+ */
+ protected $shortcutUser;
+
+ /**
+ * Generic node used for testing.
+ *
+ * @var \Drupal\node\NodeInterface
+ */
+ protected $node;
+
+ /**
+ * Site-wide default shortcut set.
+ *
+ * @var \Drupal\shortcut\ShortcutSetInterface
+ */
+ protected $set;
+
+ protected function setUp() {
+ parent::setUp();
+
+ if ($this->profile != 'standard') {
+ // Create Basic page and Article node types.
+ $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
+ $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
+
+ // Populate the default shortcut set.
+ $shortcut = Shortcut::create([
+ 'shortcut_set' => 'default',
+ 'title' => t('Add content'),
+ 'weight' => -20,
+ 'link' => [
+ 'uri' => 'internal:/node/add',
+ ],
+ ]);
+ $shortcut->save();
+
+ $shortcut = Shortcut::create([
+ 'shortcut_set' => 'default',
+ 'title' => t('All content'),
+ 'weight' => -19,
+ 'link' => [
+ 'uri' => 'internal:/admin/content',
+ ],
+ ]);
+ $shortcut->save();
+ }
+
+ // Create users.
+ $this->adminUser = $this->drupalCreateUser(['access toolbar', 'administer shortcuts', 'view the administration theme', 'create article content', 'create page content', 'access content overview', 'administer users', 'link to any page', 'edit any article content']);
+ $this->shortcutUser = $this->drupalCreateUser(['customize shortcut links', 'switch shortcut sets', 'access shortcuts', 'access content']);
+
+ // Create a node.
+ $this->node = $this->drupalCreateNode(['type' => 'article']);
+
+ // Log in as admin and grab the default shortcut set.
+ $this->drupalLogin($this->adminUser);
+ $this->set = ShortcutSet::load('default');
+ \Drupal::entityManager()->getStorage('shortcut_set')->assignUser($this->set, $this->adminUser);
+ }
+
+ /**
+ * Creates a generic shortcut set.
+ */
+ public function generateShortcutSet($label = '', $id = NULL) {
+ $set = ShortcutSet::create([
+ 'id' => isset($id) ? $id : strtolower($this->randomMachineName()),
+ 'label' => empty($label) ? $this->randomString() : $label,
+ ]);
+ $set->save();
+ return $set;
+ }
+
+ /**
+ * Extracts information from shortcut set links.
+ *
+ * @param \Drupal\shortcut\ShortcutSetInterface $set
+ * The shortcut set object to extract information from.
+ * @param string $key
+ * The array key indicating what information to extract from each link:
+ * - 'title': Extract shortcut titles.
+ * - 'link': Extract shortcut paths.
+ * - 'id': Extract the shortcut ID.
+ *
+ * @return array
+ * Array of the requested information from each link.
+ */
+ public function getShortcutInformation(ShortcutSetInterface $set, $key) {
+ $info = [];
+ \Drupal::entityManager()->getStorage('shortcut')->resetCache();
+ foreach ($set->getShortcuts() as $shortcut) {
+ if ($key == 'link') {
+ $info[] = $shortcut->link->uri;
+ }
+ else {
+ $info[] = $shortcut->{$key}->value;
+ }
+ }
+ return $info;
+ }
+
+}
diff --git a/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php b/core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php
index 300ca3b..83bf47a 100644
--- a/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php
+++ b/core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php
@@ -1,6 +1,6 @@
<?php
-namespace Drupal\shortcut\Tests;
+namespace Drupal\Tests\shortcut\Functional;
use Drupal\content_translation\Tests\ContentTranslationUITestBase;
use Drupal\Core\Entity\EntityChangedInterface;