You are here

class RouterTest in Drupal 7 to 8/9 Module Upgrader 8

@group DMU.Routing

Hierarchy

Expanded class hierarchy of RouterTest

File

tests/src/Unit/Routing/Drupal7/RouterTest.php, line 12

Namespace

Drupal\Tests\drupalmoduleupgrader\Unit\Routing\Drupal7
View source
class RouterTest extends UnitTestCase {
  private $router;
  public function setUp() {
    parent::setUp();
    $this->router = new Router();
    foreach ($this
      ->hookMenu() as $path => $item) {
      $route = new RouteWrapper($path, $item);
      $this->router
        ->addRoute($route);
    }
  }
  public function testOfType() {
    $this
      ->assertCount(8, $this->router
      ->ofType('MENU_LOCAL_TASK, MENU_DEFAULT_LOCAL_TASK'));
  }
  public function testGetAllLinks() {
    $this
      ->assertCount(9, $this->router
      ->getAllLinks());
  }
  public function testGetLinks() {
    $this
      ->assertCount(1, $this->router
      ->getLinks());
  }
  public function testGetLocalTasks() {
    $this
      ->assertCount(5, $this->router
      ->getLocalTasks());
  }
  public function testGetDefaultLocalTasks() {
    $this
      ->assertCount(3, $this->router
      ->getDefaultLocalTasks());
  }
  public function testGetLocalActions() {
    $this
      ->assertCount(0, $this->router
      ->getLocalActions());
  }
  public function testGetContextualLinks() {
    $this
      ->assertCount(0, $this->router
      ->getContextualLinks());
  }
  public function testFinalize() {
    $this->router
      ->finalize();
    $list_revisions = $this->router['node/%node/revisions/list'];
    $this
      ->assertFalse($list_revisions
      ->hasParent());
    $this
      ->assertFalse($list_revisions
      ->hasChildren());
    $this
      ->assertTrue($list_revisions
      ->hasSiblings());
    $this
      ->assertTrue($list_revisions
      ->getSiblings()
      ->containsKey('node/%node/revisions/view'));
    $view_revisions = $this->router['node/%node/revisions/view'];
    $this
      ->assertFalse($view_revisions
      ->hasParent());
    $this
      ->assertTrue($view_revisions
      ->hasChildren());
    $this
      ->assertTrue($view_revisions
      ->getChildren()
      ->containsKey('node/%node/revisions/view/latest'));
    $this
      ->assertTrue($view_revisions
      ->hasSiblings());
    $this
      ->assertTrue($view_revisions
      ->getSiblings()
      ->containsKey('node/%node/revisions/list'));
    $diff_fields = $this->router['admin/config/content/diff/fields'];
    $this
      ->assertTrue($diff_fields
      ->hasParent());
    $this
      ->assertEquals('admin/config/content/diff', $diff_fields
      ->getParent()
      ->getPath());
  }

  /**
   * The Diff module's hook_menu() implementation. It's a nice mix of things
   * to test on.
   *
   * @return array
   */
  private function hookMenu() {
    $items = [];
    $items['node/%node/revisions/list'] = [
      'title' => 'List revisions',
      'page callback' => 'diff_diffs_overview',
      'type' => 'MENU_DEFAULT_LOCAL_TASK',
      'access callback' => 'diff_node_revision_access',
      'access arguments' => [
        1,
      ],
      'file' => 'diff.pages.inc',
    ];
    $items['node/%node/revisions/view'] = [
      'title' => 'Compare revisions',
      'page callback' => 'diff_diffs_show',
      'page arguments' => [
        1,
        4,
        5,
        6,
      ],
      'type' => 'MENU_LOCAL_TASK',
      'access callback' => 'diff_node_revision_access',
      'access arguments' => [
        1,
      ],
      'tab_parent' => 'node/%/revisions/list',
      'file' => 'diff.pages.inc',
    ];
    $items['node/%node/revisions/view/latest'] = [
      'title' => 'Show latest difference',
      'page callback' => 'diff_latest',
      'page arguments' => [
        1,
      ],
      'type' => 'MENU_LOCAL_TASK',
      'access arguments' => [
        'access content',
      ],
      'tab_parent' => 'node/%/revisions/view',
      'file' => 'diff.pages.inc',
    ];
    $items['admin/config/content/diff'] = [
      'title' => 'Diff',
      'description' => 'Diff settings.',
      'file' => 'diff.admin.inc',
      'page callback' => 'drupal_get_form',
      'page arguments' => [
        'diff_admin_settings',
      ],
      'access arguments' => [
        'administer site configuration',
      ],
    ];
    $items['admin/config/content/diff/settings'] = [
      'title' => 'Settings',
      'type' => 'MENU_DEFAULT_LOCAL_TASK',
      'weight' => -10,
    ];
    $items['admin/config/content/diff/fields'] = [
      'title' => 'Fields',
      'description' => 'Field support and settings overview.',
      'file' => 'diff.admin.inc',
      'page callback' => 'diff_admin_field_overview',
      'access arguments' => [
        'administer site configuration',
      ],
      'type' => 'MENU_LOCAL_TASK',
    ];
    $items['admin/config/content/diff/fields/%'] = [
      'title' => 'Global field settings',
      'page callback' => 'drupal_get_form',
      'page arguments' => [
        'diff_admin_global_field_settings',
        5,
      ],
      'access arguments' => [
        'administer site configuration',
      ],
      'type' => 'MENU_VISIBLE_IN_BREADCRUMB',
      'file' => 'diff.admin.inc',
    ];
    $items['admin/config/content/diff/entities'] = [
      'title' => 'Entities',
      'description' => 'Entity settings.',
      'file' => 'diff.admin.inc',
      'page callback' => 'drupal_get_form',
      'page arguments' => [
        'diff_admin_global_entity_settings',
        'node',
      ],
      'access arguments' => [
        'administer site configuration',
      ],
      'type' => 'MENU_LOCAL_TASK',
    ];
    $items['admin/config/content/diff/entities/node'] = [
      'title' => 'Nodes',
      'description' => 'Node comparison settings.',
      'type' => 'MENU_DEFAULT_LOCAL_TASK',
      'weight' => -10,
    ];
    $items['admin/config/content/diff/entities/user'] = [
      'title' => 'Users',
      'description' => 'User diff settings.',
      'file' => 'diff.admin.inc',
      'page callback' => 'drupal_get_form',
      'page arguments' => [
        'diff_admin_global_entity_settings',
        'user',
      ],
      'access arguments' => [
        'administer site configuration',
      ],
      'type' => 'MENU_LOCAL_TASK',
    ];
    return $items;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
RouterTest::$router private property
RouterTest::hookMenu private function The Diff module's hook_menu() implementation. It's a nice mix of things to test on.
RouterTest::setUp public function Overrides UnitTestCase::setUp
RouterTest::testFinalize public function
RouterTest::testGetAllLinks public function
RouterTest::testGetContextualLinks public function
RouterTest::testGetDefaultLocalTasks public function
RouterTest::testGetLinks public function
RouterTest::testGetLocalActions public function
RouterTest::testGetLocalTasks public function
RouterTest::testOfType public function
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.