You are here

public function GroupContentTest::testUrlRouteParameters in Group 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Kernel/GroupContentTest.php \Drupal\Tests\group\Kernel\GroupContentTest::testUrlRouteParameters()

Tests that entity url templates are functional.

@covers ::urlRouteParameters

File

tests/src/Kernel/GroupContentTest.php, line 26

Class

GroupContentTest
Tests for the GroupContent entity.

Namespace

Drupal\Tests\group\Kernel

Code

public function testUrlRouteParameters() {
  $group = $this
    ->createGroup();
  $account = $this
    ->createUser();
  $group
    ->addContent($account, 'group_membership');
  $group_content = $group
    ->getContent('group_membership');
  foreach ($group_content as $item) {

    // Canonical.
    $expected = "/group/{$group->id()}/content/{$item->id()}";
    $this
      ->assertEquals($expected, $item
      ->toUrl()
      ->toString());

    // Add form.
    $expected = "/group/{$group->id()}/content/add/group_membership?group_content_type=default-group_membership";
    $this
      ->assertEquals($expected, $item
      ->toUrl('add-form')
      ->toString());

    // Add page.
    $expected = "/group/{$group->id()}/content/add";
    $this
      ->assertEquals($expected, $item
      ->toUrl('add-page')
      ->toString());

    // Collection.
    $expected = "/group/{$group->id()}/content";
    $this
      ->assertEquals($expected, $item
      ->toUrl('collection')
      ->toString());

    // Create form.
    $expected = "/group/{$group->id()}/content/create/group_membership?group_content={$item->id()}";
    $this
      ->assertEquals($expected, $item
      ->toUrl('create-form')
      ->toString());

    // Create page.
    $expected = "/group/{$group->id()}/content/create?group_content={$item->id()}";
    $this
      ->assertEquals($expected, $item
      ->toUrl('create-page')
      ->toString());

    // Delete form.
    $expected = "/group/{$group->id()}/content/{$item->id()}/delete";
    $this
      ->assertEquals($expected, $item
      ->toUrl('delete-form')
      ->toString());

    // Edit form.
    $expected = "/group/{$group->id()}/content/{$item->id()}/edit";
    $this
      ->assertEquals($expected, $item
      ->toUrl('edit-form')
      ->toString());
  }
}