NgLightboxTest.php in NG Lightbox 8
File
tests/src/Unit/NgLightboxTest.php
View source
<?php
namespace Drupal\Tests\ng_lightbox\Unit;
use Drupal\ng_lightbox\NgLightbox;
use Drupal\Tests\UnitTestCase;
use Prophecy\Argument;
class NgLightboxTest extends UnitTestCase {
public function testExternalUrl() {
$lightbox = $this
->getLightbox();
$this
->assertEquals(FALSE, $lightbox
->isNgLightboxEnabledPath($this
->getUrlMock(TRUE)
->reveal()));
}
public function testAdminSkipPaths() {
$lightbox = $this
->getLightbox();
$this
->assertEquals(FALSE, $lightbox
->isNgLightboxEnabledPath($this
->getUrlMock()
->reveal()));
}
public function testEmptyPath() {
$lightbox = $this
->getLightbox(FALSE);
$url = $this
->getUrlMock();
$url
->toString()
->willReturn('');
$this
->assertEquals(FALSE, $lightbox
->isNgLightboxEnabledPath($url
->reveal()));
}
protected function getUrlMock($is_external = FALSE) {
$url = $this
->prophesize('Drupal\\Core\\Url');
$url
->isExternal()
->willReturn($is_external);
return $url;
}
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;
}
}