You are here

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

@group DMU.Routing

Hierarchy

Expanded class hierarchy of LinkBindingTest

File

tests/src/Unit/Routing/LinkBinding/LinkBindingTest.php, line 15

Namespace

Drupal\Tests\drupalmoduleupgrader\Unit\Routing\LinkBinding
View source
class LinkBindingTest extends UnitTestCase {
  private $source, $destination;
  public function setUp() {
    parent::setUp();
    $item = [
      'title' => 'Diff',
      'description' => 'Diff settings.',
      'file' => 'diff.admin.inc',
      'page callback' => 'drupal_get_form',
      'page arguments' => [
        'diff_admin_settings',
      ],
      'access arguments' => [
        'administer site configuration',
      ],
    ];
    $this->source = new Drupal7Route('admin/config/content/diff', $item);
    $this->destination = new Drupal8Route('diff.settings', new Route('/admin/config/content/diff'), $this
      ->createMock('\\Drupal\\Core\\Routing\\RouteProviderInterface'));
  }
  private function getMockBinding() {
    return new LinkBinding($this->source, $this->destination);
  }
  public function testGetSource() {
    $this
      ->assertSame($this->source, $this
      ->getMockBinding()
      ->getSource());
  }
  public function testGetDestination() {
    $this
      ->assertSame($this->destination, $this
      ->getMockBinding()
      ->getDestination());
  }
  public function testGetIdentifier() {
    $this
      ->assertSame('diff.settings', $this
      ->getMockBinding()
      ->getIdentifier());
  }
  public function testOnIndexed() {
    $binding = $this
      ->getMockBinding();
    $index = new LinkIndex();
    $index
      ->addBinding($binding);
    $this
      ->assertSame('diff.settings', $binding
      ->getIdentifier());

    // If a binding is added with the same identifier (which could easily happen,
    // depending on how the binding computes its identifier), _0, _1, etc. should
    // be appended to it by the index.
    $clone = clone $binding;
    $index
      ->addBinding($clone);
    $this
      ->assertSame('diff.settings_0', $clone
      ->getIdentifier());
  }
  public function testBuild() {
    $link = $this
      ->getMockBinding()
      ->build();
    $this
      ->assertEquals('diff.settings', $link['route_name']);
    $this
      ->assertEquals('Diff', $link['title']);
    $this
      ->assertArrayNotHasKey('weight', $link);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LinkBindingTest::$source private property
LinkBindingTest::getMockBinding private function
LinkBindingTest::setUp public function Overrides UnitTestCase::setUp
LinkBindingTest::testBuild public function
LinkBindingTest::testGetDestination public function
LinkBindingTest::testGetIdentifier public function
LinkBindingTest::testGetSource public function
LinkBindingTest::testOnIndexed public function
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.
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.