/**
  * 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);
 }
 /**
  * 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('');
 }
Exemple #3
0
 /**
  * Tests creating a new shortcut set with a defined set name.
  */
 function testShortcutSetCreateWithSetName()
 {
     $random_name = $this->randomMachineName();
     $new_set = $this->generateShortcutSet($random_name, $random_name);
     $sets = ShortcutSet::loadMultiple();
     $this->assertTrue(isset($sets[$random_name]), 'Successfully created a shortcut set with a defined set name.');
     $this->drupalGet('user/' . $this->adminUser->id() . '/shortcuts');
     $this->assertText($new_set->label(), 'Generated shortcut set was listed as a choice on the user account page.');
 }
 /**
  * Tests the shortcut listing for the translate operation.
  */
 public function doShortcutListTest()
 {
     // Create a test shortcut to decouple looking for translate operations
     // link so this does not test more than necessary.
     $shortcut = ShortcutSet::create(array('id' => Unicode::strtolower($this->randomMachineName(16)), 'label' => $this->randomString()));
     $shortcut->save();
     // Get the shortcut listing.
     $this->drupalGet('admin/config/user-interface/shortcut');
     $translate_link = 'admin/config/user-interface/shortcut/manage/' . $shortcut->id() . '/translate';
     // Test if the link to translate the shortcut is on the page.
     $this->assertLinkByHref($translate_link);
     // Test if the link to translate actually goes to the translate page.
     $this->drupalGet($translate_link);
     $this->assertRaw('<th>' . t('Language') . '</th>');
 }
 /**
  * Creates a generic shortcut set.
  */
 function generateShortcutSet($label = '', $id = NULL)
 {
     $set = ShortcutSet::create(array('id' => isset($id) ? $id : strtolower($this->randomName()), 'label' => empty($label) ? $this->randomString() : $label));
     $set->save();
     return $set;
 }
 /**
  * Tests renaming a shortcut set to the same name as another set.
  */
 function testShortcutSetRenameAlreadyExists()
 {
     $set = $this->generateShortcutSet($this->randomName());
     $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)));
 }