class PanelizerDefaultPanelsStorageTest in Panelizer 8.4
Same name and namespace in other branches
- 8.5 tests/src/Unit/PanelizerDefaultPanelsStorageTest.php \Drupal\Tests\panelizer\Unit\PanelizerDefaultPanelsStorageTest
- 8.3 tests/src/Unit/PanelizerDefaultPanelsStorageTest.php \Drupal\Tests\panelizer\Unit\PanelizerDefaultPanelsStorageTest
Tests the PanelizerDefaultPanelsStorage service.
@coversDefaultClass \Drupal\panelizer\Plugin\PanelsStorage\PanelizerDefaultPanelsStorage
@group panelizer
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\panelizer\Unit\PanelizerDefaultPanelsStorageTest
Expanded class hierarchy of PanelizerDefaultPanelsStorageTest
File
- tests/
src/ Unit/ PanelizerDefaultPanelsStorageTest.php, line 24
Namespace
Drupal\Tests\panelizer\UnitView source
class PanelizerDefaultPanelsStorageTest extends UnitTestCase {
/**
* @var \Drupal\Core\Entity\EntityStorageInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $storage;
/**
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $entityTypeManager;
/**
* @var \Drupal\panelizer\PanelizerInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $panelizer;
/**
* @var \Drupal\panels\Storage\PanelsStorageInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $panelsStorage;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->storage = $this
->prophesize(EntityStorageInterface::class);
$this->entityTypeManager = $this
->prophesize(EntityTypeManagerInterface::class);
$this->entityTypeManager
->getStorage('entity_type_id')
->willReturn($this->storage
->reveal());
$this->panelizer = $this
->prophesize(Panelizer::class);
$this->panelsStorage = $this
->getMockBuilder(PanelizerDefaultPanelsStorage::class)
->setConstructorArgs([
[],
'',
[],
$this->entityTypeManager
->reveal(),
$this->panelizer
->reveal(),
])
->setMethods([
'getEntityContext',
])
->getMock();
}
/**
* @covers ::load
*/
public function testLoadEmptyContext() {
$entity_context = $this
->prophesize(AutomaticContext::class);
$panels_display = $this
->prophesize(PanelsDisplayVariant::class);
$panels_display
->setContexts([
'@panelizer.entity_context:entity' => $entity_context
->reveal(),
])
->shouldBeCalled();
$this->panelizer
->getDefaultPanelsDisplay('default', 'entity_type_id', 'bundle', 'view_mode', NULL)
->willReturn($panels_display
->reveal());
$this->panelizer
->getDisplayStaticContexts('default', 'entity_type_id', 'bundle', 'view_mode')
->willReturn([]);
$this->panelsStorage
->method('getEntityContext')
->with($this
->equalTo('entity_type_id'), $this
->isNull())
->willReturn([
'@panelizer.entity_context:entity' => $entity_context
->reveal(),
]);
$this
->assertSame($panels_display
->reveal(), $this->panelsStorage
->load('entity_type_id:bundle:view_mode:default'));
}
/**
* @covers ::load
*/
public function testLoadWithContextValue() {
$entity_context = $this
->prophesize(AutomaticContext::class);
$panels_display = $this
->prophesize(PanelsDisplayVariant::class);
$panels_display
->setContexts([
'@panelizer.entity_context:entity' => $entity_context
->reveal(),
])
->shouldBeCalled();
$this->panelizer
->getDefaultPanelsDisplay('default', 'entity_type_id', 'bundle', 'view_mode', NULL)
->willReturn($panels_display
->reveal());
$this->panelizer
->getDisplayStaticContexts('default', 'entity_type_id', 'bundle', 'view_mode')
->willReturn([]);
$entity = $this
->prophesize(EntityInterface::class);
$entity
->bundle()
->willReturn("bundle");
$this->storage
->load('123')
->willReturn($entity
->reveal())
->shouldBeCalled();
$this->panelsStorage
->method('getEntityContext')
->with($this
->equalTo('entity_type_id'), $entity
->reveal())
->willReturn([
'@panelizer.entity_context:entity' => $entity_context
->reveal(),
]);
$this
->assertSame($panels_display
->reveal(), $this->panelsStorage
->load('*entity_type_id:123:view_mode:default'));
}
/**
* @covers ::load
*/
public function testLoadDoesntExist() {
$this->panelizer
->getDefaultPanelsDisplay('default', 'entity_type_id', 'bundle', 'view_mode', NULL)
->willReturn(NULL);
$this
->assertSame(NULL, $this->panelsStorage
->load('entity_type_id:bundle:view_mode:default'));
}
/**
* @covers ::load
*/
public function testLoadNoEntity() {
$this->storage
->load('123')
->willReturn(NULL)
->shouldBeCalled();
$this->panelizer
->getDefaultPanelsDisplay('default', 'entity_type_id', 'bundle', 'view_mode', NULL)
->shouldNotBeCalled();
$this
->assertSame(NULL, $this->panelsStorage
->load('*entity_type_id:123:view_mode:default'));
}
/**
* @covers ::save
*/
public function testSaveSuccessful() {
$panels_display = $this
->prophesize(PanelsDisplayVariant::class);
$panels_display
->getStorageId()
->willReturn('entity_type_id:bundle:view_mode:default');
$this->panelizer
->setDefaultPanelsDisplay('default', 'entity_type_id', 'bundle', 'view_mode', $panels_display
->reveal())
->shouldBeCalled();
$this->panelsStorage
->save($panels_display
->reveal());
}
/**
* @covers ::save
*/
public function testSaveDoesntExist() {
$panels_display = $this
->prophesize(PanelsDisplayVariant::class);
$panels_display
->getStorageId()
->willReturn('entity_type_id:bundle:view_mode:default');
$this->panelizer
->setDefaultPanelsDisplay('default', 'entity_type_id', 'bundle', 'view_mode', $panels_display
->reveal())
->willThrow(new PanelizerException());
$this
->expectException('Exception');
$this
->expectExceptionMessage("Couldn't find Panelizer default to store Panels display");
$this->panelsStorage
->save($panels_display
->reveal());
}
/**
* @covers ::save
*/
public function testSaveNoEntity() {
$panels_display = $this
->prophesize(PanelsDisplayVariant::class);
$panels_display
->getStorageId()
->willReturn('*entity_type_id:123:view_mode:default');
$this->storage
->load('123')
->willReturn(NULL)
->shouldBeCalled();
$this->panelizer
->setDefaultPanelsDisplay('default', 'entity_type_id', 'bundle', 'view_mode', $panels_display
->reveal())
->shouldNotBeCalled();
$this
->expectException('Exception');
$this
->expectExceptionMessage("Couldn't find Panelizer default to store Panels display");
$this->panelsStorage
->save($panels_display
->reveal());
}
/**
* @covers ::access
*/
public function testAccessRead() {
$panels_display = $this
->prophesize(PanelsDisplayVariant::class);
$account = $this
->prophesize(AccountInterface::class);
$this->panelizer
->getDefaultPanelsDisplay('default', 'entity_type_id', 'bundle', 'view_mode')
->willReturn($panels_display
->reveal());
$this->panelizer
->hasDefaultPermission()
->shouldNotBeCalled();
$this
->assertEquals(AccessResult::allowed(), $this->panelsStorage
->access('entity_type_id:bundle:view_mode:default', 'read', $account
->reveal()));
}
/**
* @covers ::access
*/
public function testAccessNotFound() {
$account = $this
->prophesize(AccountInterface::class);
$this->panelizer
->getDefaultPanelsDisplay('default', 'entity_type_id', 'bundle', 'view_mode')
->willReturn(NULL);
$this->panelizer
->hasDefaultPermission()
->shouldNotBeCalled();
$this
->assertEquals(AccessResult::forbidden(), $this->panelsStorage
->access('entity_type_id:bundle:view_mode:default', 'read', $account
->reveal()));
}
/**
* @covers ::access
*/
public function testAccessNoEntity() {
$account = $this
->prophesize(AccountInterface::class);
$this->storage
->load('123')
->willReturn(NULL)
->shouldBeCalled();
$this->panelizer
->getDefaultPanelsDisplay('default', 'entity_type_id', 'bundle', 'view_mode')
->shouldNotBeCalled();
$this
->assertEquals(AccessResult::forbidden(), $this->panelsStorage
->access('*entity_type_id:123:view_mode:default', 'read', $account
->reveal()));
}
/**
* @covers ::access
*/
public function testAccessChangeContent() {
$panels_display = $this
->prophesize(PanelsDisplayVariant::class);
$account = $this
->prophesize(AccountInterface::class);
$this->panelizer
->getDefaultPanelsDisplay('default', 'entity_type_id', 'bundle', 'view_mode')
->willReturn($panels_display
->reveal());
$this->panelizer
->hasDefaultPermission('change content', 'entity_type_id', 'bundle', 'view_mode', 'default', $account
->reveal())
->willReturn(TRUE);
$this
->assertEquals(AccessResult::allowed(), $this->panelsStorage
->access('entity_type_id:bundle:view_mode:default', 'update', $account
->reveal()));
$this
->assertEquals(AccessResult::allowed(), $this->panelsStorage
->access('entity_type_id:bundle:view_mode:default', 'delete', $account
->reveal()));
$this
->assertEquals(AccessResult::allowed(), $this->panelsStorage
->access('entity_type_id:bundle:view_mode:default', 'create', $account
->reveal()));
}
/**
* @covers ::access
*/
public function testAccessChangeLayout() {
$panels_display = $this
->prophesize(PanelsDisplayVariant::class);
$account = $this
->prophesize(AccountInterface::class);
$this->panelizer
->getDefaultPanelsDisplay('default', 'entity_type_id', 'bundle', 'view_mode')
->willReturn($panels_display
->reveal());
$this->panelizer
->hasDefaultPermission('change layout', 'entity_type_id', 'bundle', 'view_mode', 'default', $account
->reveal())
->willReturn(TRUE);
$this
->assertEquals(AccessResult::allowed(), $this->panelsStorage
->access('entity_type_id:bundle:view_mode:default', 'change layout', $account
->reveal()));
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PanelizerDefaultPanelsStorageTest:: |
protected | property | ||
PanelizerDefaultPanelsStorageTest:: |
protected | property | ||
PanelizerDefaultPanelsStorageTest:: |
protected | property | ||
PanelizerDefaultPanelsStorageTest:: |
protected | property | ||
PanelizerDefaultPanelsStorageTest:: |
protected | function |
Overrides UnitTestCase:: |
|
PanelizerDefaultPanelsStorageTest:: |
public | function | @covers ::access | |
PanelizerDefaultPanelsStorageTest:: |
public | function | @covers ::access | |
PanelizerDefaultPanelsStorageTest:: |
public | function | @covers ::access | |
PanelizerDefaultPanelsStorageTest:: |
public | function | @covers ::access | |
PanelizerDefaultPanelsStorageTest:: |
public | function | @covers ::access | |
PanelizerDefaultPanelsStorageTest:: |
public | function | @covers ::load | |
PanelizerDefaultPanelsStorageTest:: |
public | function | @covers ::load | |
PanelizerDefaultPanelsStorageTest:: |
public | function | @covers ::load | |
PanelizerDefaultPanelsStorageTest:: |
public | function | @covers ::load | |
PanelizerDefaultPanelsStorageTest:: |
public | function | @covers ::save | |
PanelizerDefaultPanelsStorageTest:: |
public | function | @covers ::save | |
PanelizerDefaultPanelsStorageTest:: |
public | function | @covers ::save | |
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. |