class RouteSubscriberTest in Replicate UI 8
@coversDefaultClass \Drupal\replicate_ui\RouteSubscriber @group replicate
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\replicate_ui\Unit\RouteSubscriberTest
 
 
Expanded class hierarchy of RouteSubscriberTest
File
- tests/
src/ Unit/ RouteSubscriberTest.php, line 17  
Namespace
Drupal\Tests\replicate_ui\UnitView 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
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            PhpunitCompatibilityTrait:: | 
                  public | function | Returns a mock object for the specified class using the available method. | |
| 
            PhpunitCompatibilityTrait:: | 
                  public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
| 
            RouteSubscriberTest:: | 
                  protected | function | ||
| 
            RouteSubscriberTest:: | 
                  protected | function | ||
| 
            RouteSubscriberTest:: | 
                  public | function | @covers ::onRouteBuild | |
| 
            RouteSubscriberTest:: | 
                  public | function | @covers ::onRouteBuild | |
| 
            UnitTestCase:: | 
                  protected | property | The random generator. | |
| 
            UnitTestCase:: | 
                  protected | property | The app root. | 1 | 
| 
            UnitTestCase:: | 
                  protected | function | Asserts if two arrays are equal by sorting them first. | |
| 
            UnitTestCase:: | 
                  protected | function | Mocks a block with a block plugin. | 1 | 
| 
            UnitTestCase:: | 
                  protected | function | Returns a stub class resolver. | |
| 
            UnitTestCase:: | 
                  public | function | Returns a stub config factory that behaves according to the passed array. | |
| 
            UnitTestCase:: | 
                  public | function | Returns a stub config storage that returns the supplied configuration. | |
| 
            UnitTestCase:: | 
                  protected | function | Sets up a container with a cache tags invalidator. | |
| 
            UnitTestCase:: | 
                  protected | function | Gets the random generator for the utility methods. | |
| 
            UnitTestCase:: | 
                  public | function | Returns a stub translation manager that just returns the passed string. | |
| 
            UnitTestCase:: | 
                  public | function | Generates a unique random string containing letters and numbers. | |
| 
            UnitTestCase:: | 
                  protected | function | 340 |