diff --git a/contextual_links_example/contextual_links_example.routing.yml b/contextual_links_example/contextual_links_example.routing.yml index 2e690d6..a296e12 100644 --- a/contextual_links_example/contextual_links_example.routing.yml +++ b/contextual_links_example/contextual_links_example.routing.yml @@ -8,7 +8,7 @@ contextual_links_example.contextual_node_action_form: _access: 'TRUE' contextual_links_example.contextual_links_object_list: - path: 'examples/contextual-links' + path: '/examples/contextual-links' defaults: _title: 'Contextual links example list objects' _controller: '\Drupal\contextual_links_example\Controller\CLEController::clePage' @@ -16,7 +16,7 @@ contextual_links_example.contextual_links_object_list: _access: 'TRUE' contextual_links_example.contextual_links_object_view: - path: 'examples/contextual-links/{entity_id}' + path: '/examples/contextual-links/{entity_id}' defaults: _title: 'Contextual links example object' _controller: '\Drupal\contextual_links_example\Controller\CLEController::cleContent' diff --git a/contextual_links_example/tests/src/Functional/ContextualLinksMenuTest.php b/contextual_links_example/tests/src/Functional/ContextualLinksMenuTest.php new file mode 100644 index 0000000..21ddbb0 --- /dev/null +++ b/contextual_links_example/tests/src/Functional/ContextualLinksMenuTest.php @@ -0,0 +1,64 @@ +assertSession(); + + // Routes with menu links, and their form buttons. + $main_route = 'contextual_links_example.contextual_links_object_list'; + + // Ensure the links appear in the tools menu sidebar. + $this->drupalGet(''); + $assertion->linkByHrefExists(Url::fromRoute($main_route)->getInternalPath()); + + // Ensure we can go to the main route. + $path = Url::fromRoute($main_route); + $this->drupalGet($path); + $assertion->statusCodeEquals(200); + + // Ensure our node action form works. + $node = $this->createNode(); + $path = Url::fromRoute( + 'contextual_links_example.contextual_node_action_form', ['node' => $node->id()] + ); + $this->drupalGet($path); + $assertion->statusCodeEquals(200); + + // Ensure our entity edit routes work. + /* @var $entity \Drupal\contextual_links_example\Entity\CLEEntity */ + $entity = CLEEntity::create(); + $entity->save(); + // Add routes with no menu links. + $routes = [ + 'contextual_links_example.contextual_links_object_view', + 'contextual_links_example.contextual_links_object_edit', + ]; + foreach ($routes as $route) { + $this->drupalGet(Url::fromRoute($route, ['entity_id' => $entity->id()])); + } + } + +} diff --git a/examples.module b/examples.module index 6cb777b..fe67ef2 100644 --- a/examples.module +++ b/examples.module @@ -42,6 +42,7 @@ function examples_toolbar() { 'cache_example' => 'cache_example.description', 'config_entity_example' => 'entity.robot.list', 'content_entity_example' => 'entity.content_entity_example_contact.collection', + 'contextual_menu_example' => 'contextual_links_example.contextual_links_object_list', 'cron_example' => 'cron_example', 'dbtng_example' => 'dbtng_example', 'email_example' => 'email_example.description',