You are here

class NgLightboxTest in NG Lightbox 8

Same name in this branch
  1. 8 src/Tests/NgLightboxTest.php \Drupal\ng_lightbox\Tests\NgLightboxTest
  2. 8 tests/src/Unit/NgLightboxTest.php \Drupal\Tests\ng_lightbox\Unit\NgLightboxTest
  3. 8 tests/src/Kernel/NgLightboxTest.php \Drupal\Tests\ng_lightbox\Kernel\NgLightboxTest
Same name and namespace in other branches
  1. 2.x tests/src/Unit/NgLightboxTest.php \Drupal\Tests\ng_lightbox\Unit\NgLightboxTest

@coversDefaultClass \Drupal\ng_lightbox\NgLightbox @group ng_lightbox

Hierarchy

Expanded class hierarchy of NgLightboxTest

File

tests/src/Unit/NgLightboxTest.php, line 18
Contains \Drupal\Tests\ng_lightbox\Unit\NgLightboxTest

Namespace

Drupal\Tests\ng_lightbox\Unit
View source
class NgLightboxTest extends UnitTestCase {

  /**
   * Test with an External URL.
   */
  public function testExternalUrl() {
    $lightbox = $this
      ->getLightbox();
    $this
      ->assertEquals(FALSE, $lightbox
      ->isNgLightboxEnabledPath($this
      ->getUrlMock(TRUE)
      ->reveal()));
  }

  /**
   * Test the admin_skip_path settings.
   */
  public function testAdminSkipPaths() {

    // Admin skip paths enabled and admin route.
    $lightbox = $this
      ->getLightbox();
    $this
      ->assertEquals(FALSE, $lightbox
      ->isNgLightboxEnabledPath($this
      ->getUrlMock()
      ->reveal()));
  }

  /**
   * Test with an empty path.
   */
  public function testEmptyPath() {
    $lightbox = $this
      ->getLightbox(FALSE);
    $url = $this
      ->getUrlMock();
    $url
      ->toString()
      ->willReturn('');
    $this
      ->assertEquals(FALSE, $lightbox
      ->isNgLightboxEnabledPath($url
      ->reveal()));
  }

  /**
   * Helper to create Url mocks.
   *
   * @param bool|FALSE $is_external
   *   TRUE if this URL is external otherwise FALSE.
   *
   * @return \Prophecy\Prophecy\ObjectProphecy
   *   The url prophecy for testing.
   */
  protected function getUrlMock($is_external = FALSE) {
    $url = $this
      ->prophesize('Drupal\\Core\\Url');
    $url
      ->isExternal()
      ->willReturn($is_external);
    return $url;
  }

  /**
   * Get the lightbox service setup for testing.
   *
   * @return \Drupal\ng_lightbox\NgLightbox
   *   The lightbox service.
   */
  protected function getLightbox($skip_admin_paths = TRUE, $is_admin_route = TRUE) {
    $path_matcher = $this
      ->prophesize('Drupal\\Core\\Path\\PathMatcherInterface');
    $alias_manager = $this
      ->prophesize('Drupal\\Core\\Path\\AliasManagerInterface');
    $config_factory = $this
      ->prophesize('Drupal\\Core\\Config\\ConfigFactoryInterface');
    $config = $this
      ->prophesize('Drupal\\Core\\Config\\ImmutableConfig');
    $config
      ->get(Argument::exact('skip_admin_paths'))
      ->willReturn($skip_admin_paths);
    $config_factory
      ->get(Argument::exact('ng_lightbox.settings'))
      ->willReturn($config);
    $admin_context = $this
      ->prophesize('Drupal\\Core\\Routing\\AdminContext');
    $admin_context
      ->isAdminRoute()
      ->willReturn($is_admin_route);
    $lightbox = new NgLightbox($path_matcher
      ->reveal(), $alias_manager
      ->reveal(), $config_factory
      ->reveal(), $admin_context
      ->reveal());
    return $lightbox;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
NgLightboxTest::getLightbox protected function Get the lightbox service setup for testing.
NgLightboxTest::getUrlMock protected function Helper to create Url mocks.
NgLightboxTest::testAdminSkipPaths public function Test the admin_skip_path settings.
NgLightboxTest::testEmptyPath public function Test with an empty path.
NgLightboxTest::testExternalUrl public function Test with an External URL.
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