Пример #1
0
 /**
  * Tests overriding an existing route.
  *
  * @covers ::alterRoutes
  * @covers ::findPageRouteName
  *
  * @dataProvider providerTestAlterRoutesOverrideExisting
  */
 public function testAlterRoutesOverrideExisting($page_path, $existing_route_path, $requirements = [])
 {
     $route_name = 'test_route';
     // Set up a page with the same path as an existing route.
     $page = $this->prophesize(PageInterface::class);
     $page->status()->willReturn(TRUE)->shouldBeCalled();
     $page->getPath()->willReturn($page_path)->shouldBeCalled();
     $variant1 = $this->prophesize(PageVariantInterface::class);
     $variant1->getWeight()->willReturn(0);
     $page->getVariants()->willReturn(['variant1' => $variant1->reveal()]);
     $page->id()->willReturn('page1');
     $page->label()->willReturn(NULL);
     $page->usesAdminTheme()->willReturn(FALSE);
     $this->pageStorage->loadMultiple()->willReturn(['page1' => $page->reveal()])->shouldBeCalledTimes(1);
     $this->cacheTagsInvalidator->invalidateTags(["page_manager_route_name:{$route_name}"])->shouldBeCalledTimes(1);
     $collection = new RouteCollection();
     $collection->add($route_name, new Route($existing_route_path, ['default_exists' => 'default_value'], $requirements, ['parameters' => ['foo' => 'bar']]));
     $route_event = new RouteBuildEvent($collection);
     $this->routeSubscriber->onAlterRoutes($route_event);
     // The normal route name is not used, the existing route name is instead.
     $this->assertSame(1, $collection->count());
     $this->assertNull($collection->get('page_manager.page_view_page1'));
     $this->assertNull($collection->get('page_manager.page_view_page1_variant1'));
     $route = $collection->get($route_name);
     $expected_defaults = ['_entity_view' => 'page_manager_page_variant', '_title' => NULL, 'page_manager_page_variant' => 'variant1', 'page_manager_page' => 'page1', 'page_manager_page_variant_weight' => 0, 'base_route_name' => $route_name];
     $expected_requirements = $requirements;
     $expected_options = ['compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler', 'parameters' => ['page_manager_page_variant' => ['type' => 'entity:page_variant'], 'page_manager_page' => ['type' => 'entity:page'], 'foo' => 'bar'], '_admin_route' => FALSE];
     $this->assertMatchingRoute($route, $existing_route_path, $expected_defaults, $expected_requirements, $expected_options);
 }
 /**
  * Tests the getAllBundleInfo() method.
  *
  * @covers ::getAllBundleInfo
  */
 public function testGetAllBundleInfo()
 {
     $this->moduleHandler->invokeAll('entity_bundle_info')->willReturn([]);
     $this->moduleHandler->alter('entity_bundle_info', Argument::type('array'))->willReturn(NULL);
     $apple = $this->prophesize(EntityTypeInterface::class);
     $apple->getLabel()->willReturn('Apple');
     $apple->getBundleOf()->willReturn(NULL);
     $banana = $this->prophesize(EntityTypeInterface::class);
     $banana->getLabel()->willReturn('Banana');
     $banana->getBundleOf()->willReturn(NULL);
     $this->setUpEntityTypeDefinitions(['apple' => $apple, 'banana' => $banana]);
     $this->cacheBackend->get('entity_bundle_info:en')->willReturn(FALSE);
     $this->cacheBackend->set('entity_bundle_info:en', Argument::any(), Cache::PERMANENT, ['entity_types', 'entity_bundles'])->will(function () {
         $this->get('entity_bundle_info:en')->willReturn((object) ['data' => 'cached data'])->shouldBeCalled();
     })->shouldBeCalled();
     $this->cacheTagsInvalidator->invalidateTags(['entity_bundles'])->shouldBeCalled();
     $this->typedDataManager->clearCachedDefinitions()->shouldBeCalled();
     $expected = ['apple' => ['apple' => ['label' => 'Apple']], 'banana' => ['banana' => ['label' => 'Banana']]];
     $bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
     $this->assertSame($expected, $bundle_info);
     $bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
     $this->assertSame($expected, $bundle_info);
     $this->entityTypeBundleInfo->clearCachedBundles();
     $bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
     $this->assertSame('cached data', $bundle_info);
 }
Пример #3
0
 /**
  * Tests the clearCachedFieldDefinitions() method.
  *
  * @covers ::clearCachedFieldDefinitions
  */
 public function testClearCachedFieldDefinitions()
 {
     $this->setUpEntityTypeDefinitions();
     $this->cacheTagsInvalidator->invalidateTags(['entity_field_info'])->shouldBeCalled();
     $this->container->get('cache_tags.invalidator')->willReturn($this->cacheTagsInvalidator->reveal())->shouldBeCalled();
     $this->typedDataManager->clearCachedDefinitions()->shouldBeCalled();
     $this->entityFieldManager->clearCachedFieldDefinitions();
 }