public function UrlBagTest::testGetters in Mini site 8
Test getter functions.
File
- tests/
src/ Kernel/ UrlBagTest.php, line 295
Class
- UrlBagTest
- Class UrlBagTest.
Namespace
Drupal\Tests\minisite\KernelCode
public function testGetters() {
$bag = new UrlBag('public://minisite/static/24c22dd1-2cf1-47ae-ac8a-23a7ff8b86c5/rootpath/subpath/file.txt', 'http://example.com');
$this
->assertEquals('http://example.com', $bag
->getBaseUrl());
$this
->assertEquals('public://minisite/static/24c22dd1-2cf1-47ae-ac8a-23a7ff8b86c5/rootpath/subpath/file.txt', $bag
->getUri());
$this
->assertEquals('rootpath', $bag
->getRootDir());
$this
->assertEquals('subpath/file.txt', $bag
->getPathInArchive());
// Relative URL will be within VFS.
$this
->assertContains('files/minisite/static/24c22dd1-2cf1-47ae-ac8a-23a7ff8b86c5/rootpath/subpath/file.txt', $bag
->getUrl());
// Can only test absolute URLs with partial matching.
$this
->assertContains('files/minisite/static/24c22dd1-2cf1-47ae-ac8a-23a7ff8b86c5/rootpath/subpath/file.txt', $bag
->getUrlAbsolute());
$this
->assertNull($bag
->getAlias());
$this
->assertNull($bag
->getAliasAbsolute());
$this
->assertNull($bag
->getParentAlias());
$this
->assertNull($bag
->getParentAliasAbsolute());
// With parent alias.
$bag
->setParentAlias('/parent/alias');
$this
->assertEquals('/parent/alias/rootpath/subpath/file.txt', $bag
->getAlias());
$this
->assertContains('/parent/alias/rootpath/subpath/file.txt', $bag
->getAliasAbsolute());
$this
->assertEquals('/parent/alias', $bag
->getParentAlias());
$this
->assertContains('/parent/alias', $bag
->getParentAliasAbsolute());
$this
->assertNotContains('rootpath/subpath/file.txt', $bag
->getParentAlias());
$this
->assertNotContains('rootpath/subpath/file.txt', $bag
->getParentAliasAbsolute());
// Same as above, but with alias set. Need a new bag to test cleanly.
$bag = new UrlBag('public://minisite/static/24c22dd1-2cf1-47ae-ac8a-23a7ff8b86c5/rootpath/subpath/file.txt', 'http://example.com');
// With alias autodiscovery.
$bag
->setAlias('/parent/alias/rootpath/subpath/file.txt');
$this
->assertEquals('/parent/alias/rootpath/subpath/file.txt', $bag
->getAlias());
$this
->assertContains('/parent/alias/rootpath/subpath/file.txt', $bag
->getAliasAbsolute());
$this
->assertEquals('/parent/alias', $bag
->getParentAlias());
$this
->assertContains('/parent/alias', $bag
->getParentAliasAbsolute());
$this
->assertNotContains('rootpath/subpath/file.txt', $bag
->getParentAlias());
$this
->assertNotContains('rootpath/subpath/file.txt', $bag
->getParentAliasAbsolute());
}