/** * Asserts various aspects of a shortcut set entity. * * @param string $id * The expected shortcut set ID. * @param string $label * The expected shortcut set label. * @param int $expected_size * The number of shortcuts expected to be in the set. */ protected function assertEntity($id, $label, $expected_size) { $shortcut_set = ShortcutSet::load($id); $this->assertTrue($shortcut_set instanceof ShortcutSetInterface); /** @var \Drupal\shortcut\ShortcutSetInterface $shortcut_set */ $this->assertIdentical($id, $shortcut_set->id()); $this->assertIdentical($label, $shortcut_set->label()); // Check the number of shortcuts in the set. $shortcuts = $shortcut_set->getShortcuts(); $this->assertIdentical(count($shortcuts), $expected_size); }
function setUp() { parent::setUp(); if ($this->profile != 'standard') { // Create Basic page and Article node types. $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); // Populate the default shortcut set. $shortcut = Shortcut::create(array('set' => 'default', 'title' => t('Add content'), 'weight' => -20, 'path' => 'node/add')); $shortcut->save(); $shortcut = Shortcut::create(array('set' => 'default', 'title' => t('All content'), 'weight' => -19, 'path' => 'admin/content')); $shortcut->save(); } // Create users. $this->admin_user = $this->drupalCreateUser(array('access toolbar', 'administer shortcuts', 'view the administration theme', 'create article content', 'create page content', 'access content overview', 'administer users')); $this->shortcut_user = $this->drupalCreateUser(array('customize shortcut links', 'switch shortcut sets')); // Create a node. $this->node = $this->drupalCreateNode(array('type' => 'article')); // Log in as admin and grab the default shortcut set. $this->drupalLogin($this->admin_user); $this->set = ShortcutSet::load('default'); shortcut_set_assign_user($this->set, $this->admin_user); }
/** * Tests deleting a shortcut link. */ public function testShortcutLinkDelete() { $set = $this->set; $shortcuts = $set->getShortcuts(); $shortcut = reset($shortcuts); $this->drupalPostForm('admin/config/user-interface/shortcut/link/' . $shortcut->id() . '/delete', array(), 'Delete'); $saved_set = ShortcutSet::load($set->id()); $ids = $this->getShortcutInformation($saved_set, 'id'); $this->assertFalse(in_array($shortcut->id(), $ids), 'Successfully deleted a shortcut.'); // Delete all the remaining shortcut links. entity_delete_multiple('shortcut', array_filter($ids)); // Get the front page to check that no exceptions occur. $this->drupalGet(''); }
/** * Tests renaming a shortcut set. */ function testShortcutSetRename() { $set = $this->set; $new_label = $this->randomMachineName(); $this->drupalGet('admin/config/user-interface/shortcut'); $this->clickLink(t('Edit shortcut set')); $this->drupalPostForm(NULL, array('label' => $new_label), t('Save')); $set = ShortcutSet::load($set->id()); $this->assertTrue($set->label() == $new_label, 'Shortcut set has been successfully renamed.'); }
/** * Tests renaming a shortcut set to the same name as another set. */ function testShortcutSetRenameAlreadyExists() { $set = $this->generateShortcutSet($this->randomMachineName()); $existing_label = $this->set->label(); $this->drupalPostForm('admin/config/user-interface/shortcut/manage/' . $set->id(), array('label' => $existing_label), t('Save')); $this->assertRaw(t('The shortcut set %name already exists. Choose another name.', array('%name' => $existing_label))); $set = ShortcutSet::load($set->id()); $this->assertNotEqual($set->label(), $existing_label, format_string('The shortcut set %title cannot be renamed to %new-title because a shortcut set with that title already exists.', array('%title' => $set->label(), '%new-title' => $existing_label))); }