class NgLightboxTest in NG Lightbox 8
Same name in this branch
- 8 src/Tests/NgLightboxTest.php \Drupal\ng_lightbox\Tests\NgLightboxTest
- 8 tests/src/Unit/NgLightboxTest.php \Drupal\Tests\ng_lightbox\Unit\NgLightboxTest
- 8 tests/src/Kernel/NgLightboxTest.php \Drupal\Tests\ng_lightbox\Kernel\NgLightboxTest
Same name and namespace in other branches
- 2.x tests/src/Unit/NgLightboxTest.php \Drupal\Tests\ng_lightbox\Unit\NgLightboxTest
@coversDefaultClass \Drupal\ng_lightbox\NgLightbox @group ng_lightbox
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\ng_lightbox\Unit\NgLightboxTest
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\UnitView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
NgLightboxTest:: |
protected | function | Get the lightbox service setup for testing. | |
NgLightboxTest:: |
protected | function | Helper to create Url mocks. | |
NgLightboxTest:: |
public | function | Test the admin_skip_path settings. | |
NgLightboxTest:: |
public | function | Test with an empty path. | |
NgLightboxTest:: |
public | function | Test with an External URL. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |