PageVariantPageEntityTest.php in Page Manager 8
File
tests/src/Kernel/PageVariantPageEntityTest.php
View source
<?php
namespace Drupal\Tests\page_manager\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\page_manager\Entity\Page;
use Drupal\page_manager\Entity\PageVariant;
class PageVariantPageEntityTest extends KernelTestBase {
public static $modules = [
'page_manager',
];
public function testPageGetsCached() {
$page = Page::create([
'id' => 'test_page',
]);
$page
->save();
$page_variant = PageVariant::create([
'id' => 'test_page_variant',
'page' => 'test_page',
]);
$page_first = $page_variant
->getPage();
$this
->assertNotEmpty($page_first);
$page_second = $page_variant
->getPage();
$this
->assertEquals(spl_object_hash($page_first), spl_object_hash($page_second));
}
public function testUnsavedPage() {
$page = Page::create([
'id' => 'test_page',
]);
$page_variant = PageVariant::create([
'id' => 'test_page_variant',
'page' => 'test_page',
]);
$page_variant
->setPageEntity($page);
$page_result = $page_variant
->getPage();
$this
->assertEquals($page, $page_result);
}
public function testChangePageId() {
$page_variant = PageVariant::create([
'id' => 'test_page_variant',
]);
$page1 = Page::create([
'id' => 'test_page_1',
]);
$page_variant
->setPageEntity($page1);
$this
->assertEquals('test_page_1', $page_variant
->get('page'));
$page2 = Page::create([
'id' => 'test_page_2',
]);
$page_variant
->setPageEntity($page2);
$this
->assertEquals('test_page_2', $page_variant
->get('page'));
}
}