class UpdateLayoutRequestHandlerTest in Panels 8.3
Tests for \Drupal\panels_ipe\Helpers\UpdateLayoutRequestHandler.
@group Panels IPE
Hierarchy
- class \Drupal\Tests\panels\Unit\panels_ipe\RequestHandlerTestBase extends \Drupal\Tests\panels\Unit\panels_ipe\PHPUnit_Framework_TestCase
- class \Drupal\Tests\panels\Unit\panels_ipe\UpdateLayoutRequestHandlerTest
Expanded class hierarchy of UpdateLayoutRequestHandlerTest
File
- tests/
src/ Unit/ panels_ipe/ UpdateLayoutRequestHandlerTest.php, line 19
Namespace
Drupal\Tests\panels\Unit\panels_ipeView source
class UpdateLayoutRequestHandlerTest extends RequestHandlerTestBase {
public function setUp() {
parent::setUp();
$this->sut = new UpdateLayoutRequestHandler($this->moduleHandler, $this->panelsStore, $this->tempStore);
}
private function getLayoutModel() {
return [
'regionCollection' => [
[
'name' => 'some_region',
'blockCollection' => [
[
'uuid' => 'someBlock',
],
[
'uuid' => 'someOtherBlock',
],
],
],
],
];
}
private function setPanelsDisplayExpectations() {
$block = $this
->getMockBuilder(BlockBase::class)
->disableOriginalConstructor()
->getMock();
$block
->expects($this
->exactly(4))
->method('setConfigurationValue');
$block
->expects($this
->exactly(2))
->method('getConfiguration')
->willReturn([]);
$this->panelsDisplay
->method('getBlock')
->willReturn($block);
}
/**
* @test
*/
public function successfulSaveOperationResultsInEmptyJsonResponse() {
$this
->setPanelsDisplayExpectations();
$this->sut
->handleRequest($this->panelsDisplay, $this
->createRequest(Json::encode($this
->getLayoutModel())));
$this
->assertEquals(new JsonResponse([]), $this->sut
->getJsonResponse());
}
/**
* @test
*/
public function successfulTempStoreSaveOperationResultsInEmptyJsonResponse() {
$this
->setPanelsDisplayExpectations();
$this->sut
->handleRequest($this->panelsDisplay, $this
->createRequest(Json::encode($this
->getLayoutModel())), TRUE);
$this
->assertEquals(new JsonResponse([]), $this->sut
->getJsonResponse());
}
/**
* @test
*/
public function updatedLayoutGetsSaved() {
$this
->setPanelsDisplayExpectations();
$this->panelsStore
->expects($this
->once())
->method('save');
$this->tempStore
->expects($this
->once())
->method('delete');
$this->tempStore
->expects($this
->never())
->method('set');
$this->sut
->handleRequest($this->panelsDisplay, $this
->createRequest(Json::encode($this
->getLayoutModel())));
}
/**
* @test
*/
public function updatedLayoutGetsSavedToTempStore() {
$this
->setPanelsDisplayExpectations();
$this->panelsStore
->expects($this
->never())
->method('save');
$this->tempStore
->expects($this
->never())
->method('delete');
$this->tempStore
->expects($this
->once())
->method('set');
$this->sut
->handleRequest($this->panelsDisplay, $this
->createRequest(Json::encode($this
->getLayoutModel())), TRUE);
}
/**
* @test
*/
public function hookPreSaveGetsCalledBeforeSave() {
$this
->setPanelsDisplayExpectations();
$this->moduleHandler
->expects($this
->once())
->method('invokeAll');
$this->sut
->handleRequest($this->panelsDisplay, $this
->createRequest(Json::encode($this
->getLayoutModel())), TRUE);
}
}