You are here

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

Same name in this branch
  1. 8 tests/src/Unit/Routing/Drupal7/RouteWrapperTest.php \Drupal\Tests\drupalmoduleupgrader\Unit\Routing\Drupal7\RouteWrapperTest
  2. 8 tests/src/Unit/Routing/Drupal8/RouteWrapperTest.php \Drupal\Tests\drupalmoduleupgrader\Unit\Routing\Drupal8\RouteWrapperTest

@group DMU.Routing

Hierarchy

Expanded class hierarchy of RouteWrapperTest

File

tests/src/Unit/Routing/Drupal7/RouteWrapperTest.php, line 11

Namespace

Drupal\Tests\drupalmoduleupgrader\Unit\Routing\Drupal7
View source
class RouteWrapperTest extends UnitTestCase {
  private function getMockRouteWrapper() {
    $route = [
      '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',
    ];
    return new RouteWrapper('node/%node/revisions/list', $route);
  }
  public function testGetIdentifier() {
    $this
      ->assertEquals('node/%node/revisions/list', $this
      ->getMockRouteWrapper()
      ->getIdentifier());
  }
  public function testGetPath() {
    $wrapper = $this
      ->getMockRouteWrapper();
    $this
      ->assertInstanceOf('\\Drupal\\drupalmoduleupgrader\\Utility\\Path\\Drupal7\\PathUtility', $wrapper
      ->getPath());
    $this
      ->assertEquals('node/%node/revisions/list', $wrapper
      ->getPath());
  }
  public function testUnwrap() {
    $route = [
      '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',
    ];
    $unwrapped_route = $this
      ->getMockRouteWrapper()
      ->unwrap();
    $this
      ->assertTrue(is_array($unwrapped_route));
    foreach ($route as $key => $value) {
      $this
        ->assertArrayHasKey($key, $unwrapped_route);
      $this
        ->assertEquals($value, $unwrapped_route[$key]);
    }
  }
  public function testIsAbsoluteAccess() {
    $wrapper = $this
      ->getMockRouteWrapper();
    $this
      ->assertFalse($wrapper
      ->isAbsoluteAccess());
    $wrapper['access callback'] = TRUE;
    $this
      ->assertTrue($wrapper
      ->isAbsoluteAccess());
    $wrapper['access callback'] = FALSE;
    $this
      ->assertTrue($wrapper
      ->isAbsoluteAccess());
  }
  public function testIsPermissionBased() {
    $wrapper = $this
      ->getMockRouteWrapper();
    $this
      ->assertFalse($wrapper
      ->isPermissionBased());
    $wrapper['access callback'] = 'user_access';
    $this
      ->assertTrue($wrapper
      ->isPermissionBased());
  }
  public function testHasLink() {
    $this
      ->assertTrue($this
      ->getMockRouteWrapper()
      ->hasLink());
  }
  public function testIsLink() {
    $wrapper = $this
      ->getMockRouteWrapper();
    $this
      ->assertFalse($wrapper
      ->isLink());
    $wrapper['type'] = 'MENU_NORMAL_ITEM';
    $this
      ->assertTrue($wrapper
      ->isLink());
  }
  public function testIsLocalTask() {
    $wrapper = $this
      ->getMockRouteWrapper();
    $this
      ->assertFalse($wrapper
      ->isLocalTask());
    $wrapper['type'] = 'MENU_LOCAL_TASK';
    $this
      ->assertTrue($wrapper
      ->isLocalTask());
  }
  public function testIsDefaultLocalTask() {
    $wrapper = $this
      ->getMockRouteWrapper();
    $this
      ->assertTrue($wrapper
      ->isDefaultLocalTask());
    $wrapper['type'] = 'MENU_NORMAL_ITEM';
    $this
      ->assertFalse($wrapper
      ->isDefaultLocalTask());
  }
  public function testIsLocalAction() {
    $wrapper = $this
      ->getMockRouteWrapper();
    $this
      ->assertFalse($wrapper
      ->isLocalAction());
    $wrapper['type'] = 'MENU_LOCAL_ACTION';
    $this
      ->assertTrue($wrapper
      ->isLocalAction());
  }
  public function testIsContextualLink() {
    $wrapper = $this
      ->getMockRouteWrapper();
    $this
      ->assertFalse($wrapper
      ->isContextualLink());
    $wrapper['type'] = 'MENU_LOCAL_ACTION';
    $this
      ->assertTrue($wrapper
      ->isLocalAction());
    $this
      ->assertFalse($wrapper
      ->isContextualLink());
    $wrapper['context'] = 'MENU_CONTEXT_INLINE';
    $this
      ->assertTrue($wrapper
      ->isContextualLink());
    $wrapper['type'] = 'MENU_NORMAL_ITEM';
    $this
      ->assertFalse($wrapper
      ->isContextualLink());
  }

}

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.
RouteWrapperTest::getMockRouteWrapper private function
RouteWrapperTest::testGetIdentifier public function
RouteWrapperTest::testGetPath public function
RouteWrapperTest::testHasLink public function
RouteWrapperTest::testIsAbsoluteAccess public function
RouteWrapperTest::testIsContextualLink public function
RouteWrapperTest::testIsDefaultLocalTask public function
RouteWrapperTest::testIsLink public function
RouteWrapperTest::testIsLocalAction public function
RouteWrapperTest::testIsLocalTask public function
RouteWrapperTest::testIsPermissionBased public function
RouteWrapperTest::testUnwrap 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.
UnitTestCase::setUp protected function 340