You are here

class PanelsEverywherePageDisplayVariantSubscriberTest in Panels Everywhere 8.4

@coversDefaultClass \Drupal\panels_everywhere\EventSubscriber\PanelsEverywherePageDisplayVariantSubscriber @group panels_everywhere

Hierarchy

Expanded class hierarchy of PanelsEverywherePageDisplayVariantSubscriberTest

File

tests/src/Unit/EventSubscriber/PanelsEverywherePageDisplayVariantSubscriberTest.php, line 20

Namespace

Drupal\Tests\panels_everywhere\Unit\EventSubscriber
View source
class PanelsEverywherePageDisplayVariantSubscriberTest extends UnitTestCase {
  public function testSubscriberDoesNotStopPropagationForAdminRoutes() {

    // Given.
    $entity_type_manager = $this
      ->prophesize(EntityTypeManagerInterface::class);
    $subscriber = new PanelsEverywherePageDisplayVariantSubscriber($entity_type_manager
      ->reveal());
    $route = new Route('/some-path');
    $route
      ->setOption('_admin_route', TRUE);
    $routeMatch = new RouteMatch('some.route_name', $route);
    $event = new PageDisplayVariantSelectionEvent('some_plugin_id', $routeMatch);

    // When.
    $subscriber
      ->onSelectPageDisplayVariant($event);

    // Then.
    self::assertFalse($event
      ->isPropagationStopped());
  }
  public function testSubscriberDoesNotStopPropagationForNonAdminRoutesIfNoPanelsEveryWhereVariantIsFound() {
    $page_id = 'some_page_id';
    $variantPlugin = $this
      ->prophesize(BlockDisplayVariant::class);
    $variantPlugin
      ->getPluginId()
      ->willReturn('non_panels_everywhere_variant');
    $variantPlugin
      ->getConfiguration()
      ->willReturn([]);
    $variantPlugin
      ->getContexts()
      ->willReturn([]);
    $pageVariant = $this
      ->prophesize(PageVariantInterface::class);
    $pageVariant
      ->access('view')
      ->willReturn(TRUE);
    $pageVariant
      ->getVariantPluginId()
      ->willReturn('');
    $pageVariant
      ->getVariantPlugin()
      ->willReturn($variantPlugin
      ->reveal());
    $page = $this
      ->prophesize(PageInterface::class);
    $page
      ->get('status')
      ->willReturn(TRUE);
    $page
      ->getVariants()
      ->willReturn([
      $pageVariant
        ->reveal(),
    ]);
    $pageStorage = $this
      ->prophesize(EntityStorageInterface::class);
    $pageStorage
      ->load($page_id)
      ->willReturn($page
      ->reveal());
    $pageStorage
      ->load('site_template')
      ->willReturn(NULL);
    $entity_type_manager = $this
      ->prophesize(EntityTypeManagerInterface::class);
    $entity_type_manager
      ->getStorage('page')
      ->willReturn($pageStorage
      ->reveal());
    $subscriber = new PanelsEverywherePageDisplayVariantSubscriber($entity_type_manager
      ->reveal());
    $route = new Route('/some-path');
    $route
      ->setOption('_admin_route', FALSE);
    $route
      ->setDefault('page_id', $page_id);
    $routeMatch = new RouteMatch('some.route_name', $route);
    $event = new PageDisplayVariantSelectionEvent('some_plugin_id', $routeMatch);

    // When.
    $subscriber
      ->onSelectPageDisplayVariant($event);

    // Then.
    self::assertFalse($event
      ->isPropagationStopped());
  }
  public function testSubscriberStopsPropagationForNonAdminRoutesIfPanelsEverywhereVariantIsFound() {
    $page_id = 'some_page_id';
    $variantPlugin = $this
      ->prophesize(BlockDisplayVariant::class);
    $variantPlugin
      ->getPluginId()
      ->willReturn('panels_everywhere_variant');
    $variantPlugin
      ->getConfiguration()
      ->willReturn([]);
    $variantPlugin
      ->getContexts()
      ->willReturn([]);
    $pageVariant = $this
      ->prophesize(PageVariantInterface::class);
    $pageVariant
      ->access('view')
      ->willReturn(TRUE);
    $pageVariant
      ->getVariantPlugin()
      ->willReturn($variantPlugin
      ->reveal());
    $page = $this
      ->prophesize(PageInterface::class);
    $page
      ->get('status')
      ->willReturn(TRUE);
    $page
      ->getVariants()
      ->willReturn([
      $pageVariant
        ->reveal(),
    ]);
    $pageStorage = $this
      ->prophesize(EntityStorageInterface::class);
    $pageStorage
      ->load($page_id)
      ->willReturn($page
      ->reveal());
    $pageStorage
      ->load('site_template')
      ->willReturn(NULL);
    $entity_type_manager = $this
      ->prophesize(EntityTypeManagerInterface::class);
    $entity_type_manager
      ->getStorage('page')
      ->willReturn($pageStorage
      ->reveal());
    $subscriber = new PanelsEverywherePageDisplayVariantSubscriber($entity_type_manager
      ->reveal());
    $route = new Route('/some-path');
    $route
      ->setOption('_admin_route', FALSE);
    $route
      ->setDefault('page_id', $page_id);
    $routeMatch = new RouteMatch('some.route_name', $route);
    $event = new PageDisplayVariantSelectionEvent('some_plugin_id', $routeMatch);

    // When.
    $subscriber
      ->onSelectPageDisplayVariant($event);

    // Then.
    self::assertTrue($event
      ->isPropagationStopped());
  }
  public function testSubscriberStopsPropagationForPanelsEverywhereDisplayVariantOnSiteTemplateOnly() {
    $variantPlugin = $this
      ->prophesize(BlockDisplayVariant::class);
    $variantPlugin
      ->getPluginId()
      ->willReturn('panels_everywhere_variant');
    $variantPlugin
      ->getConfiguration()
      ->willReturn([]);
    $variantPlugin
      ->getContexts()
      ->willReturn([]);
    $pageVariant = $this
      ->prophesize(PageVariantInterface::class);
    $pageVariant
      ->access('view')
      ->willReturn(TRUE);
    $pageVariant
      ->getVariantPlugin()
      ->willReturn($variantPlugin
      ->reveal());
    $page = $this
      ->prophesize(PageInterface::class);
    $page
      ->get('status')
      ->willReturn(TRUE);
    $page
      ->getVariants()
      ->willReturn([
      $pageVariant
        ->reveal(),
    ]);
    $pageStorage = $this
      ->prophesize(EntityStorageInterface::class);
    $pageStorage
      ->load('site_template')
      ->willReturn($page
      ->reveal());
    $entity_type_manager = $this
      ->prophesize(EntityTypeManagerInterface::class);
    $entity_type_manager
      ->getStorage('page')
      ->willReturn($pageStorage
      ->reveal());
    $subscriber = new PanelsEverywherePageDisplayVariantSubscriber($entity_type_manager
      ->reveal());
    $route = new Route('/some-path');
    $route
      ->setOption('_admin_route', FALSE);
    $routeMatch = new RouteMatch('some.route_name', $route);
    $event = new PageDisplayVariantSelectionEvent('some_plugin_id', $routeMatch);

    // When.
    $subscriber
      ->onSelectPageDisplayVariant($event);

    // Then.
    self::assertTrue($event
      ->isPropagationStopped());
  }
  public function testSubscriberDoesNotStopPropagationForPageDisabledPage() {
    $page = $this
      ->prophesize(PageInterface::class);
    $pageStorage = $this
      ->prophesize(EntityStorageInterface::class);
    $pageStorage
      ->load('site_template')
      ->willReturn($page
      ->reveal());
    $entity_type_manager = $this
      ->prophesize(EntityTypeManagerInterface::class);
    $entity_type_manager
      ->getStorage('page')
      ->willReturn($pageStorage
      ->reveal());
    $subscriber = new PanelsEverywherePageDisplayVariantSubscriber($entity_type_manager
      ->reveal());
    $route = new Route('/some-path');
    $route
      ->setOption('_admin_route', FALSE);
    $routeMatch = new RouteMatch('some.route_name', $route);
    $event = new PageDisplayVariantSelectionEvent('some_plugin_id', $routeMatch);

    // When.
    $subscriber
      ->onSelectPageDisplayVariant($event);

    // Then.
    self::assertFalse($event
      ->isPropagationStopped());
  }
  public function testSubscriberDoesNotStopPropagationForNotPageFound() {
    $pageStorage = $this
      ->prophesize(EntityStorageInterface::class);
    $entity_type_manager = $this
      ->prophesize(EntityTypeManagerInterface::class);
    $entity_type_manager
      ->getStorage('page')
      ->willReturn($pageStorage
      ->reveal());
    $subscriber = new PanelsEverywherePageDisplayVariantSubscriber($entity_type_manager
      ->reveal());
    $route = new Route('/some-path');
    $route
      ->setOption('_admin_route', FALSE);
    $routeMatch = new RouteMatch('some.route_name', $route);
    $event = new PageDisplayVariantSelectionEvent('some_plugin_id', $routeMatch);

    // When.
    $subscriber
      ->onSelectPageDisplayVariant($event);

    // Then.
    self::assertFalse($event
      ->isPropagationStopped());
  }
  public function testSubscriberDoesNotStopPropagationForNoAccessibleVariantFound() {
    $page_id = 'some_page_id';
    $pageVariant = $this
      ->prophesize(PageVariantInterface::class);
    $pageVariant
      ->access('view')
      ->willReturn(FALSE);
    $page = $this
      ->prophesize(PageInterface::class);
    $page
      ->get('status')
      ->willReturn(TRUE);
    $page
      ->getVariants()
      ->willReturn([
      $pageVariant
        ->reveal(),
    ]);
    $pageStorage = $this
      ->prophesize(EntityStorageInterface::class);
    $pageStorage
      ->load($page_id)
      ->willReturn($page
      ->reveal());
    $pageStorage
      ->load('site_template')
      ->willReturn(NULL);
    $entity_type_manager = $this
      ->prophesize(EntityTypeManagerInterface::class);
    $entity_type_manager
      ->getStorage('page')
      ->willReturn($pageStorage
      ->reveal());
    $subscriber = new PanelsEverywherePageDisplayVariantSubscriber($entity_type_manager
      ->reveal());
    $route = new Route('/some-path');
    $route
      ->setOption('_admin_route', FALSE);
    $route
      ->setDefault('page_id', $page_id);
    $routeMatch = new RouteMatch('some.route_name', $route);
    $event = new PageDisplayVariantSelectionEvent('some_plugin_id', $routeMatch);

    // When.
    $subscriber
      ->onSelectPageDisplayVariant($event);

    // Then.
    self::assertFalse($event
      ->isPropagationStopped());
  }
  public function testSubscriberFallsBackToSiteTemplateForNoAccessiblePageVariantFound() {
    $page_id = 'some_page_idV';
    $pageVariant = $this
      ->prophesize(PageVariantInterface::class);
    $pageVariant
      ->access('view')
      ->willReturn(FALSE);
    $variantPlugin = $this
      ->prophesize(BlockDisplayVariant::class);
    $variantPlugin
      ->getPluginId()
      ->willReturn('panels_everywhere_variant');
    $variantPlugin
      ->getConfiguration()
      ->willReturn([]);
    $variantPlugin
      ->getContexts()
      ->willReturn([]);
    $siteTemplatePageVariant = $this
      ->prophesize(PageVariantInterface::class);
    $siteTemplatePageVariant
      ->access('view')
      ->willReturn(TRUE);
    $siteTemplatePageVariant
      ->getVariantPlugin()
      ->willReturn($variantPlugin
      ->reveal());
    $page = $this
      ->prophesize(PageInterface::class);
    $page
      ->get('status')
      ->willReturn(TRUE);
    $page
      ->getVariants()
      ->willReturn([
      $pageVariant
        ->reveal(),
    ]);
    $siteTemplatePage = $this
      ->prophesize(PageInterface::class);
    $siteTemplatePage
      ->get('status')
      ->willReturn(TRUE);
    $siteTemplatePage
      ->getVariants()
      ->willReturn([
      $siteTemplatePageVariant
        ->reveal(),
    ]);
    $pageStorage = $this
      ->prophesize(EntityStorageInterface::class);
    $pageStorage
      ->load($page_id)
      ->willReturn($page
      ->reveal());
    $pageStorage
      ->load('site_template')
      ->willReturn($siteTemplatePage
      ->reveal());
    $entity_type_manager = $this
      ->prophesize(EntityTypeManagerInterface::class);
    $entity_type_manager
      ->getStorage('page')
      ->willReturn($pageStorage
      ->reveal());
    $subscriber = new PanelsEverywherePageDisplayVariantSubscriber($entity_type_manager
      ->reveal());
    $route = new Route('/some-path');
    $route
      ->setOption('_admin_route', FALSE);
    $route
      ->setDefault('page_id', $page_id);
    $routeMatch = new RouteMatch('some.route_name', $route);
    $event = new PageDisplayVariantSelectionEvent('some_plugin_id', $routeMatch);

    // When.
    $subscriber
      ->onSelectPageDisplayVariant($event);

    // Then.
    self::assertTrue($event
      ->isPropagationStopped());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PanelsEverywherePageDisplayVariantSubscriberTest::testSubscriberDoesNotStopPropagationForAdminRoutes public function
PanelsEverywherePageDisplayVariantSubscriberTest::testSubscriberDoesNotStopPropagationForNoAccessibleVariantFound public function
PanelsEverywherePageDisplayVariantSubscriberTest::testSubscriberDoesNotStopPropagationForNonAdminRoutesIfNoPanelsEveryWhereVariantIsFound public function
PanelsEverywherePageDisplayVariantSubscriberTest::testSubscriberDoesNotStopPropagationForNotPageFound public function
PanelsEverywherePageDisplayVariantSubscriberTest::testSubscriberDoesNotStopPropagationForPageDisabledPage public function
PanelsEverywherePageDisplayVariantSubscriberTest::testSubscriberFallsBackToSiteTemplateForNoAccessiblePageVariantFound public function
PanelsEverywherePageDisplayVariantSubscriberTest::testSubscriberStopsPropagationForNonAdminRoutesIfPanelsEverywhereVariantIsFound public function
PanelsEverywherePageDisplayVariantSubscriberTest::testSubscriberStopsPropagationForPanelsEverywhereDisplayVariantOnSiteTemplateOnly 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.
UnitTestCase::setUp protected function 340