You are here

class RouteSubscriberTest in Replicate UI 8

@coversDefaultClass \Drupal\replicate_ui\RouteSubscriber @group replicate

Hierarchy

Expanded class hierarchy of RouteSubscriberTest

File

tests/src/Unit/RouteSubscriberTest.php, line 17

Namespace

Drupal\Tests\replicate_ui\Unit
View source
class RouteSubscriberTest extends UnitTestCase {

  /**
   * @covers ::onRouteBuild
   */
  public function testDisabledReplicateFunctionality() {
    $em = $this
      ->setupEntityManager();
    $config_manager = $this
      ->getConfigFactoryStub([
      'replicate_ui.settings' => [
        'entity_types' => [],
      ],
    ]);
    $subscriber = new RouteSubscriber($em
      ->reveal(), $config_manager);
    $routes = $this
      ->setupRouteCollection();
    $event = new RouteBuildEvent($routes);
    $this
      ->assertCount(4, $routes);
    $subscriber
      ->onRouteBuild($event);
    $this
      ->assertCount(4, $routes);
  }

  /**
   * @covers ::onRouteBuild
   */
  public function testEnabledReplicateFunctionality() {
    $em = $this
      ->setupEntityManager();
    $config_manager = $this
      ->getConfigFactoryStub([
      'replicate_ui.settings' => [
        'entity_types' => [
          'entity_test_1',
          'entity_test_2',
        ],
      ],
    ]);
    $subscriber = new RouteSubscriber($em
      ->reveal(), $config_manager);
    $routes = $this
      ->setupRouteCollection();
    $event = new RouteBuildEvent($routes);
    $this
      ->assertCount(4, $routes);
    $subscriber
      ->onRouteBuild($event);
    $this
      ->assertCount(6, $routes);
    $this
      ->assertEquals('/entity_test_1/{entity_test_1}/replicate', $routes
      ->get('entity.entity_test_1.replicate')
      ->getPath());
    $this
      ->assertEquals('entity_test_1.replicate', $routes
      ->get('entity.entity_test_1.replicate')
      ->getDefault('_entity_form'));
    $this
      ->assertFalse($routes
      ->get('entity.entity_test_1.replicate')
      ->hasOption('_admin_route'));
    $this
      ->assertEquals('/entity_test_2/{entity_test_2}/replicate', $routes
      ->get('entity.entity_test_2.replicate')
      ->getPath());
    $this
      ->assertEquals('entity_test_2.replicate', $routes
      ->get('entity.entity_test_2.replicate')
      ->getDefault('_entity_form'));
    $this
      ->assertTrue($routes
      ->get('entity.entity_test_2.replicate')
      ->getOption('_admin_route'));
  }
  protected function setupEntityManager() {
    $entity_manager = $this
      ->prophesize(EntityTypeManagerInterface::class);
    $entity_manager
      ->getDefinitions()
      ->willReturn([
      'entity_test_1' => new ContentEntityType([
        'id' => 'entity_test_1',
        'links' => [
          'canonical' => '/entity_test_1/{entity_test_1}',
        ],
      ]),
      'entity_test_2' => new ContentEntityType([
        'id' => 'entity_test_2',
        'links' => [
          'canonical' => '/entity_test_2/{entity_test_2}',
        ],
      ]),
    ]);
    return $entity_manager;
  }
  protected function setupRouteCollection() {
    $route_collection = new RouteCollection();
    $route_collection
      ->add('entity.entity_test_1.canonical', new Route('/entity_test_1/{entity_test_1}'));
    $route_collection
      ->add('entity.entity_test_2.canonical', new Route('/entity_test_2/{entity_test_2}'));
    $route_collection
      ->add('entity.entity_test_1.edit_form', new Route('/entity_test_1/{entity_test_1}/edit'));
    $route_collection
      ->add('entity.entity_test_2.edit_form', new Route('/entity_test_2/{entity_test_2}/edit', [], [], [
      '_admin_route' => TRUE,
    ]));
    return $route_collection;
  }

}

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.
RouteSubscriberTest::setupEntityManager protected function
RouteSubscriberTest::setupRouteCollection protected function
RouteSubscriberTest::testDisabledReplicateFunctionality public function @covers ::onRouteBuild
RouteSubscriberTest::testEnabledReplicateFunctionality public function @covers ::onRouteBuild
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