class LayoutBuilderRoutesTest
Same name in other branches
- 9 core/modules/layout_builder/tests/src/Unit/LayoutBuilderRoutesTest.php \Drupal\Tests\layout_builder\Unit\LayoutBuilderRoutesTest
- 8.9.x core/modules/layout_builder/tests/src/Unit/LayoutBuilderRoutesTest.php \Drupal\Tests\layout_builder\Unit\LayoutBuilderRoutesTest
- 10 core/modules/layout_builder/tests/src/Unit/LayoutBuilderRoutesTest.php \Drupal\Tests\layout_builder\Unit\LayoutBuilderRoutesTest
@coversDefaultClass \Drupal\layout_builder\Routing\LayoutBuilderRoutes
@group layout_builder
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\layout_builder\Unit\LayoutBuilderRoutesTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of LayoutBuilderRoutesTest
File
-
core/
modules/ layout_builder/ tests/ src/ Unit/ LayoutBuilderRoutesTest.php, line 22
Namespace
Drupal\Tests\layout_builder\UnitView source
class LayoutBuilderRoutesTest extends UnitTestCase {
/**
* The Layout Builder route builder.
*
* @var \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface
*/
protected $sectionStorageManager;
/**
* The Layout Builder route builder.
*
* @var \Drupal\layout_builder\Routing\LayoutBuilderRoutes
*/
protected $routeBuilder;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->sectionStorageManager = $this->prophesize(SectionStorageManagerInterface::class);
$this->routeBuilder = new LayoutBuilderRoutes($this->sectionStorageManager
->reveal());
}
/**
* @covers ::onAlterRoutes
*/
public function testOnAlterRoutes() : void {
$expected = [
'test_route1' => new Route('/test/path1'),
'test_route_shared' => new Route('/test/path/shared2'),
'test_route2' => new Route('/test/path2'),
];
$section_storage_first = $this->prophesize(SectionStorageInterface::class);
$section_storage_first->buildRoutes(Argument::type(RouteCollection::class))
->shouldBeCalled()
->will(function ($args) {
/** @var \Symfony\Component\Routing\RouteCollection $collection */
$collection = $args[0];
$collection->add('test_route_shared', new Route('/test/path/shared1'));
$collection->add('test_route1', new Route('/test/path1'));
});
$section_storage_second = $this->prophesize(SectionStorageInterface::class);
$section_storage_second->buildRoutes(Argument::type(RouteCollection::class))
->shouldBeCalled()
->will(function ($args) {
/** @var \Symfony\Component\Routing\RouteCollection $collection */
$collection = $args[0];
$collection->add('test_route_shared', new Route('/test/path/shared2'));
$collection->add('test_route2', new Route('/test/path2'));
});
$this->sectionStorageManager
->loadEmpty('first')
->willReturn($section_storage_first->reveal());
$this->sectionStorageManager
->loadEmpty('second')
->willReturn($section_storage_second->reveal());
$definitions['first'] = new SectionStorageDefinition();
$definitions['second'] = new SectionStorageDefinition();
$this->sectionStorageManager
->getDefinitions()
->willReturn($definitions);
$collection = new RouteCollection();
$event = new RouteBuildEvent($collection);
$this->routeBuilder
->onAlterRoutes($event);
$this->assertEquals($expected, $collection->all());
$this->assertSame(array_keys($expected), array_keys($collection->all()));
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::getCallableName | private static | function | Returns a callable as a string suitable for inclusion in a message. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
LayoutBuilderRoutesTest::$routeBuilder | protected | property | The Layout Builder route builder. | |
LayoutBuilderRoutesTest::$sectionStorageManager | protected | property | The Layout Builder route builder. | |
LayoutBuilderRoutesTest::setUp | protected | function | Overrides UnitTestCase::setUp | |
LayoutBuilderRoutesTest::testOnAlterRoutes | public | function | @covers ::onAlterRoutes | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
UnitTestCase::$root | protected | property | The app root. | |
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::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.