X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fshortcut%2Ftests%2Fsrc%2FFunctional%2FShortcutTestBase.php;fp=web%2Fcore%2Fmodules%2Fshortcut%2Ftests%2Fsrc%2FFunctional%2FShortcutTestBase.php;h=3f9cc87be3840659957157088f43828cd53ee364;hp=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/shortcut/tests/src/Functional/ShortcutTestBase.php b/web/core/modules/shortcut/tests/src/Functional/ShortcutTestBase.php new file mode 100644 index 000000000..3f9cc87be --- /dev/null +++ b/web/core/modules/shortcut/tests/src/Functional/ShortcutTestBase.php @@ -0,0 +1,133 @@ +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; + } + +}