Example #1
0
 /**
  * Tests that creating a shortcut works properly.
  */
 public function testShortcutLinkAdd()
 {
     $set = $this->set;
     // Create an alias for the node so we can test aliases.
     $path = array('source' => 'node/' . $this->node->id(), 'alias' => $this->randomName(8));
     $this->container->get('path.alias_storage')->save($path['source'], $path['alias']);
     // Create some paths to test.
     $test_cases = array(array('path' => ''), array('path' => 'admin'), array('path' => 'admin/config/system/site-information'), array('path' => 'node/' . $this->node->id() . '/edit'), array('path' => $path['alias']), array('path' => 'router_test/test2'), array('path' => 'router_test/test3/value'));
     // Check that each new shortcut links where it should.
     foreach ($test_cases as $test) {
         $title = $this->randomName();
         $form_data = array('title[0][value]' => $title, 'path' => $test['path']);
         $this->drupalPostForm('admin/config/user-interface/shortcut/manage/' . $set->id() . '/add-link', $form_data, t('Save'));
         $this->assertResponse(200);
         $saved_set = ShortcutSet::load($set->id());
         $paths = $this->getShortcutInformation($saved_set, 'path');
         $this->assertTrue(in_array($this->container->get('path.alias_manager')->getPathByAlias($test['path']), $paths), 'Shortcut created: ' . $test['path']);
         $this->assertLink($title, 0, 'Shortcut link found on the page.');
     }
     $saved_set = ShortcutSet::load($set->id());
     // Test that saving and re-loading a shortcut preserves its values.
     $shortcuts = $saved_set->getShortcuts();
     foreach ($shortcuts as $entity) {
         // Test the node routes with parameters.
         if (strpos($entity->route_name->value, 'node.') === 0) {
             $entity->save();
             $loaded = Shortcut::load($entity->id());
             $this->assertEqual($entity->route_name->value, $loaded->route_name->value);
             $this->assertEqual($entity->get('route_parameters')->first()->getValue(), $loaded->get('route_parameters')->first()->getValue());
         }
     }
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 protected function createEntity()
 {
     // Create a "Llama" shortcut.
     $shortcut = Shortcut::create(array('shortcut_set' => 'default', 'title' => t('Llama'), 'weight' => 0, 'link' => [['uri' => 'internal:/admin']]));
     $shortcut->save();
     return $shortcut;
 }
 /**
  * {@inheritdoc}
  */
 protected function createEntity()
 {
     // Create a "Llama" shortcut.
     $shortcut = Shortcut::create(array('set' => 'default', 'title' => t('Llama'), 'weight' => 0, 'path' => 'admin'));
     $shortcut->save();
     return $shortcut;
 }
 /**
  * Asserts various aspects of a shortcut entity.
  *
  * @param int $id
  *   The shortcut ID.
  * @param string $title
  *   The expected title of the shortcut.
  * @param int $weight
  *   The expected weight of the shortcut.
  * @param string $url
  *   The expected URL of the shortcut.
  */
 protected function assertEntity($id, $title, $weight, $url) {
   $shortcut = Shortcut::load($id);
   $this->assertTrue($shortcut instanceof ShortcutInterface);
   /** @var \Drupal\shortcut\ShortcutInterface $shortcut */
   $this->assertIdentical($title, $shortcut->getTitle());
   $this->assertIdentical($weight, $shortcut->getWeight());
   $this->assertIdentical($url, $shortcut->getUrl()->toString());
 }
 /**
  * Tests that creating a shortcut works properly.
  */
 public function testShortcutLinkAdd()
 {
     $set = $this->set;
     // Create an alias for the node so we can test aliases.
     $path = array('source' => '/node/' . $this->node->id(), 'alias' => '/' . $this->randomMachineName(8));
     $this->container->get('path.alias_storage')->save($path['source'], $path['alias']);
     // Create some paths to test.
     $test_cases = ['/', '/admin', '/admin/config/system/site-information', '/node/' . $this->node->id() . '/edit', $path['alias'], '/router_test/test2', '/router_test/test3/value'];
     $test_cases_non_access = ['/admin', '/admin/config/system/site-information'];
     // Check that each new shortcut links where it should.
     foreach ($test_cases as $test_path) {
         $title = $this->randomMachineName();
         $form_data = array('title[0][value]' => $title, 'link[0][uri]' => $test_path);
         $this->drupalPostForm('admin/config/user-interface/shortcut/manage/' . $set->id() . '/add-link', $form_data, t('Save'));
         $this->assertResponse(200);
         $this->assertText(t('Added a shortcut for @title.', array('@title' => $title)));
         $saved_set = ShortcutSet::load($set->id());
         $paths = $this->getShortcutInformation($saved_set, 'link');
         $this->assertTrue(in_array('internal:' . $test_path, $paths), 'Shortcut created: ' . $test_path);
         if (in_array($test_path, $test_cases_non_access)) {
             $this->assertNoLink($title, SafeMarkup::format('Shortcut link %url not accessible on the page.', ['%url' => $test_path]));
         } else {
             $this->assertLink($title, 0, SafeMarkup::format('Shortcut link %url found on the page.', ['%url' => $test_path]));
         }
     }
     $saved_set = ShortcutSet::load($set->id());
     // Test that saving and re-loading a shortcut preserves its values.
     $shortcuts = $saved_set->getShortcuts();
     foreach ($shortcuts as $entity) {
         // Test the node routes with parameters.
         $entity->save();
         $loaded = Shortcut::load($entity->id());
         $this->assertEqual($entity->link->uri, $loaded->link->uri);
         $this->assertEqual($entity->link->options, $loaded->link->options);
     }
     // Log in as non admin user, to check that access is checked when creating
     // shortcuts.
     $this->drupalLogin($this->shortcutUser);
     $title = $this->randomMachineName();
     $form_data = ['title[0][value]' => $title, 'link[0][uri]' => '/admin'];
     $this->drupalPostForm('admin/config/user-interface/shortcut/manage/' . $set->id() . '/add-link', $form_data, t('Save'));
     $this->assertResponse(200);
     $this->assertRaw(t("The path '@link_path' is inaccessible.", ['@link_path' => '/admin']));
     $form_data = ['title[0][value]' => $title, 'link[0][uri]' => '/node'];
     $this->drupalPostForm('admin/config/user-interface/shortcut/manage/' . $set->id() . '/add-link', $form_data, t('Save'));
     $this->assertLink($title, 0, 'Shortcut link found on the page.');
     // Create a new shortcut set and add a link to it.
     $this->drupalLogin($this->adminUser);
     $edit = array('label' => $this->randomMachineName(), 'id' => strtolower($this->randomMachineName()));
     $this->drupalPostForm('admin/config/user-interface/shortcut/add-set', $edit, t('Save'));
     $title = $this->randomMachineName();
     $form_data = ['title[0][value]' => $title, 'link[0][uri]' => '/admin'];
     $this->drupalPostForm('admin/config/user-interface/shortcut/manage/' . $edit['id'] . '/add-link', $form_data, t('Save'));
     $this->assertResponse(200);
 }
 /**
  * Tests that creating a shortcut works properly.
  */
 public function testShortcutLinkAdd()
 {
     $set = $this->set;
     // Create an alias for the node so we can test aliases.
     $path = array('source' => 'node/' . $this->node->id(), 'alias' => $this->randomMachineName(8));
     $this->container->get('path.alias_storage')->save($path['source'], $path['alias']);
     // Create some paths to test.
     $test_cases = array(array('path' => '', 'route_name' => '<front>'), array('path' => '<front>', 'route_name' => '<front>'), array('path' => 'admin', 'route_name' => 'system.admin'), array('path' => 'admin/config/system/site-information', 'route_name' => 'system.site_information_settings'), array('path' => 'node/' . $this->node->id() . '/edit', 'route_name' => 'entity.node.edit_form'), array('path' => $path['alias'], 'route_name' => 'entity.node.canonical'), array('path' => 'router_test/test2', 'route_name' => 'router_test.2'), array('path' => 'router_test/test3/value', 'route_name' => 'router_test.3'));
     // Check that each new shortcut links where it should.
     foreach ($test_cases as $test) {
         $title = $this->randomMachineName();
         $form_data = array('title[0][value]' => $title, 'path' => $test['path']);
         $this->drupalPostForm('admin/config/user-interface/shortcut/manage/' . $set->id() . '/add-link', $form_data, t('Save'));
         $this->assertResponse(200);
         $saved_set = ShortcutSet::load($set->id());
         $routes = $this->getShortcutInformation($saved_set, 'route_name');
         $this->assertTrue(in_array($test['route_name'], $routes), 'Shortcut created: ' . $test['path']);
         $this->assertLink($title, 0, 'Shortcut link found on the page.');
     }
     $saved_set = ShortcutSet::load($set->id());
     // Test that saving and re-loading a shortcut preserves its values.
     $shortcuts = $saved_set->getShortcuts();
     foreach ($shortcuts as $entity) {
         // Test the node routes with parameters.
         if (strpos($entity->route_name->value, 'node.') === 0) {
             $entity->save();
             $loaded = Shortcut::load($entity->id());
             $this->assertEqual($entity->route_name->value, $loaded->route_name->value);
             $this->assertEqual($entity->get('route_parameters')->first()->getValue(), $loaded->get('route_parameters')->first()->getValue());
         }
     }
     // Login as non admin user, to check that access is checked when creating
     // shortcuts.
     $this->drupalLogin($this->shortcut_user);
     $title = $this->randomMachineName();
     $form_data = ['title[0][value]' => $title, 'path' => 'admin'];
     $this->drupalPostForm('admin/config/user-interface/shortcut/manage/' . $set->id() . '/add-link', $form_data, t('Save'));
     $this->assertResponse(200);
     $this->assertRaw(t('The shortcut must correspond to a valid path on the site.'));
     $form_data = ['title[0][value]' => $title, 'path' => 'node'];
     $this->drupalPostForm('admin/config/user-interface/shortcut/manage/' . $set->id() . '/add-link', $form_data, t('Save'));
     $this->assertLink($title, 0, 'Shortcut link found on the page.');
 }
Example #7
0
 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 that a fixed set of modules can be installed and uninstalled.
  */
 public function testInstallUninstall()
 {
     // Get a list of modules to enable.
     $all_modules = system_rebuild_module_data();
     $all_modules = array_filter($all_modules, function ($module) {
         // Filter contrib, hidden, already enabled modules and modules in the
         // Testing package.
         if ($module->origin !== 'core' || !empty($module->info['hidden']) || $module->status == TRUE || $module->info['package'] == 'Testing') {
             return FALSE;
         }
         return TRUE;
     });
     // Install every module possible.
     \Drupal::service('module_installer')->install(array_keys($all_modules));
     $this->assertModules(array_keys($all_modules), TRUE);
     foreach ($all_modules as $module => $info) {
         $this->assertModuleConfig($module);
         $this->assertModuleTablesExist($module);
     }
     // Export active config to sync.
     $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
     system_list_reset();
     $this->resetAll();
     // Delete every field on the site so all modules can be uninstalled. For
     // example, if a comment field exists then module becomes required and can
     // not be uninstalled.
     $field_storages = \Drupal::entityManager()->getStorage('field_storage_config')->loadMultiple();
     \Drupal::entityManager()->getStorage('field_storage_config')->delete($field_storages);
     // Purge the data.
     field_purge_batch(1000);
     // Delete all terms.
     $terms = Term::loadMultiple();
     entity_delete_multiple('taxonomy_term', array_keys($terms));
     // Delete all filter formats.
     $filters = FilterFormat::loadMultiple();
     entity_delete_multiple('filter_format', array_keys($filters));
     // Delete any shortcuts so the shortcut module can be uninstalled.
     $shortcuts = Shortcut::loadMultiple();
     entity_delete_multiple('shortcut', array_keys($shortcuts));
     system_list_reset();
     $all_modules = system_rebuild_module_data();
     // Ensure that only core required modules and the install profile can not be uninstalled.
     $validation_reasons = \Drupal::service('module_installer')->validateUninstall(array_keys($all_modules));
     $this->assertEqual(['standard', 'system', 'user'], array_keys($validation_reasons));
     $modules_to_uninstall = array_filter($all_modules, function ($module) use($validation_reasons) {
         // Filter required and not enabled modules.
         if (!empty($module->info['required']) || $module->status == FALSE) {
             return FALSE;
         }
         return TRUE;
     });
     // Can not uninstall config and use admin/config/development/configuration!
     unset($modules_to_uninstall['config']);
     $this->assertTrue(isset($modules_to_uninstall['comment']), 'The comment module will be disabled');
     $this->assertTrue(isset($modules_to_uninstall['file']), 'The File module will be disabled');
     $this->assertTrue(isset($modules_to_uninstall['editor']), 'The Editor module will be disabled');
     // Uninstall all modules that can be uninstalled.
     \Drupal::service('module_installer')->uninstall(array_keys($modules_to_uninstall));
     $this->assertModules(array_keys($modules_to_uninstall), FALSE);
     foreach ($modules_to_uninstall as $module => $info) {
         $this->assertNoModuleConfig($module);
         $this->assertModuleTablesDoNotExist($module);
     }
     // Import the configuration thereby re-installing all the modules.
     $this->drupalPostForm('admin/config/development/configuration', array(), t('Import all'));
     // Modules have been installed that have services.
     $this->rebuildContainer();
     // Check that there are no errors.
     $this->assertIdentical($this->configImporter()->getErrors(), array());
     // Check that all modules that were uninstalled are now reinstalled.
     $this->assertModules(array_keys($modules_to_uninstall), TRUE);
     foreach ($modules_to_uninstall as $module => $info) {
         $this->assertModuleConfig($module);
         $this->assertModuleTablesExist($module);
     }
     // Ensure that we have no configuration changes to import.
     $storage_comparer = new StorageComparer($this->container->get('config.storage.sync'), $this->container->get('config.storage'), $this->container->get('config.manager'));
     $this->assertIdentical($storage_comparer->createChangelist()->getChangelist(), $storage_comparer->getEmptyChangelist());
     // Now we have all configuration imported, test all of them for schema
     // conformance. Ensures all imported default configuration is valid when
     // all modules are enabled.
     $names = $this->container->get('config.storage')->listAll();
     /** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config */
     $typed_config = $this->container->get('config.typed');
     foreach ($names as $name) {
         $config = $this->config($name);
         $this->assertConfigSchema($typed_config, $name, $config->get());
     }
 }