コード例 #1
0
 /**
  * Resolves contextual links directly, without the need for javascript.
  *
  * @Then I click the contextual link :linkText in the :region region
  */
 public function iClickTheContextualLinkInTheRegion($linkText, $region)
 {
     $account = user_load($this->getUserManager()->getCurrentUser()->uid);
     $links = array();
     /** @var \Drupal\Core\Menu\ContextualLinkManager $contextual_links_manager */
     $contextual_links_manager = \Drupal::service('plugin.manager.menu.contextual_link');
     $session = $this->getSession();
     $regionObj = $session->getPage()->find('region', $region);
     if (!$regionObj) {
         throw new \Exception(sprintf('No region "%s" found on the page %s.', $region, $session->getCurrentUrl()));
     }
     /** @var \Behat\Mink\Element\NodeElement $item */
     foreach ($regionObj->findAll('xpath', '//*[@data-contextual-id]') as $item) {
         $contextual_id = $item->getAttribute('data-contextual-id');
         foreach (_contextual_id_to_links($contextual_id) as $group_name => $link) {
             $route_parameters = $link['route_parameters'];
             foreach ($contextual_links_manager->getContextualLinkPluginsByGroup($group_name) as $plugin_id => $plugin_definition) {
                 /** @var \Drupal\Core\Menu\ContextualLinkInterface $plugin */
                 $plugin = $contextual_links_manager->createInstance($plugin_id);
                 $route_name = $plugin->getRouteName();
                 // Check access.
                 if (!\Drupal::accessManager()->checkNamedRoute($route_name, $route_parameters, $account)) {
                     continue;
                 }
                 /** @var \Drupal\Core\Url $url */
                 $url = Url::fromRoute($route_name, $route_parameters, $plugin->getOptions())->toRenderArray();
                 $links[$plugin->getTitle()] = $url['#url']->toString();
             }
         }
     }
     if (isset($links[$linkText])) {
         $session->visit($this->locatePath($links[$linkText]));
         return;
     }
     throw new \Exception(t('Could not find a contextual link %link in the region %region', ['%link' => $linkText, '%region' => $region]));
 }
コード例 #2
0
ファイル: DrupalTest.php プロジェクト: dmyerson/d8ecs
 /**
  * Tests the accessManager() method.
  *
  * @covers ::accessManager
  */
 public function testAccessManager()
 {
     $this->setMockContainerService('access_manager');
     $this->assertNotNull(\Drupal::accessManager());
 }