You are here

public function DevelControllerTest::testRouteGeneration in Devel 8.3

Same name and namespace in other branches
  1. 8 tests/src/Functional/DevelControllerTest.php \Drupal\Tests\devel\Functional\DevelControllerTest::testRouteGeneration()
  2. 8.2 tests/src/Functional/DevelControllerTest.php \Drupal\Tests\devel\Functional\DevelControllerTest::testRouteGeneration()
  3. 4.x tests/src/Functional/DevelControllerTest.php \Drupal\Tests\devel\Functional\DevelControllerTest::testRouteGeneration()

Tests route generation.

File

tests/src/Functional/DevelControllerTest.php, line 69

Class

DevelControllerTest
Tests Devel controller.

Namespace

Drupal\Tests\devel\Functional

Code

public function testRouteGeneration() {

  // Test Devel load and render routes for entities with both route
  // definitions.
  $this
    ->drupalGet('entity_test/' . $this->entity
    ->id());
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->LinkExists('View');
  $this
    ->assertSession()
    ->LinkExists('Edit');
  $this
    ->assertSession()
    ->LinkExists('Devel');
  $this
    ->drupalGet('devel/entity_test/' . $this->entity
    ->id());
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->LinkExists('Definition');
  $this
    ->assertSession()
    ->LinkExists('Render');
  $this
    ->assertSession()
    ->LinkExists('Load');
  $this
    ->assertSession()
    ->linkByHrefExists('devel/entity_test/' . $this->entity
    ->id() . '/render');
  $this
    ->drupalGet('devel/entity_test/' . $this->entity
    ->id() . '/render');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->linkByHrefExists('devel/entity_test/' . $this->entity
    ->id() . '/definition');
  $this
    ->drupalGet('devel/entity_test/' . $this->entity
    ->id() . '/definition');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Test Devel load and render routes for entities with only canonical route
  // definitions.
  $this
    ->drupalGet('devel_entity_test_canonical/' . $this->entity_canonical
    ->id());
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->LinkExists('View');
  $this
    ->assertSession()
    ->LinkNotExists('Edit');
  $this
    ->assertSession()
    ->LinkExists('Devel');

  // Use xpath with equality check on @data-drupal-link-system-path because
  // assertNoLinkByHref matches on partial values and finds the other link.
  $this
    ->assertSession()
    ->elementNotExists('xpath', '//a[@data-drupal-link-system-path = "devel/devel_entity_test_canonical/' . $this->entity_canonical
    ->id() . '"]');
  $this
    ->assertSession()
    ->elementExists('xpath', '//a[@data-drupal-link-system-path = "devel/devel_entity_test_canonical/' . $this->entity_canonical
    ->id() . '/render"]');
  $this
    ->drupalGet('devel/devel_entity_test_canonical/' . $this->entity_canonical
    ->id());
  $this
    ->assertSession()
    ->statusCodeEquals(404);
  $this
    ->drupalGet('devel/devel_entity_test_canonical/' . $this->entity_canonical
    ->id() . '/render');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->LinkExists('Definition');
  $this
    ->assertSession()
    ->LinkExists('Render');
  $this
    ->assertSession()
    ->LinkNotExists('Load');
  $this
    ->assertSession()
    ->linkByHrefExists('devel/devel_entity_test_canonical/' . $this->entity_canonical
    ->id() . '/definition');
  $this
    ->drupalGet('devel/devel_entity_test_canonical/' . $this->entity_canonical
    ->id() . '/definition');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Test Devel load and render routes for entities with only edit route
  // definitions.
  $this
    ->drupalGet('devel_entity_test_edit/manage/' . $this->entity_edit
    ->id());
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->LinkNotExists('View');
  $this
    ->assertSession()
    ->LinkExists('Edit');
  $this
    ->assertSession()
    ->LinkExists('Devel');
  $this
    ->assertSession()
    ->linkByHrefExists('devel/devel_entity_test_edit/' . $this->entity_edit
    ->id());
  $this
    ->drupalGet('devel/devel_entity_test_edit/' . $this->entity_edit
    ->id());
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->LinkExists('Definition');
  $this
    ->assertSession()
    ->LinkNotExists('Render');
  $this
    ->assertSession()
    ->LinkExists('Load');
  $this
    ->assertSession()
    ->linkByHrefExists('devel/devel_entity_test_edit/' . $this->entity_edit
    ->id() . '/definition');
  $this
    ->assertSession()
    ->linkByHrefNotExists('devel/devel_entity_test_edit/' . $this->entity_edit
    ->id() . '/render');
  $this
    ->drupalGet('devel/devel_entity_test_edit/' . $this->entity_edit
    ->id() . '/definition');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->drupalGet('devel/devel_entity_test_edit/' . $this->entity_edit
    ->id() . '/render');
  $this
    ->assertSession()
    ->statusCodeEquals(404);

  // Test Devel load and render routes for entities with no route
  // definitions.
  $this
    ->drupalGet('devel_entity_test_no_links/' . $this->entity_edit
    ->id());
  $this
    ->assertSession()
    ->statusCodeEquals(404);
  $this
    ->drupalGet('devel/devel_entity_test_no_links/' . $this->entity_no_links
    ->id());
  $this
    ->assertSession()
    ->statusCodeEquals(404);
  $this
    ->drupalGet('devel/devel_entity_test_no_links/' . $this->entity_no_links
    ->id() . '/render');
  $this
    ->assertSession()
    ->statusCodeEquals(404);
  $this
    ->drupalGet('devel/devel_entity_test_no_links/' . $this->entity_no_links
    ->id() . '/definition');
  $this
    ->assertSession()
    ->statusCodeEquals(404);
}