SerializerTest.php in Drupal 8
File
core/modules/rest/tests/src/Unit/Plugin/views/style/SerializerTest.php
View source
<?php
namespace Drupal\Tests\rest\Unit\Plugin\views\style;
use Drupal\rest\Plugin\views\display\RestExport;
use Drupal\rest\Plugin\views\style\Serializer;
use Drupal\Tests\UnitTestCase;
use Drupal\views\ViewExecutable;
use Prophecy\Argument;
use Symfony\Component\Serializer\SerializerInterface;
class SerializerTest extends UnitTestCase {
protected $view;
protected $displayHandler;
protected function setUp() {
parent::setUp();
$this->view = $this
->getMockBuilder(ViewExecutable::class)
->disableOriginalConstructor()
->getMock();
$this->view->result = [];
$this->displayHandler = $this
->getMockBuilder(RestExport::class)
->disableOriginalConstructor()
->getMock();
$this->displayHandler
->expects($this
->any())
->method('getContentType')
->willReturn('json');
}
public function testSerializerReceivesOptions() {
$mock_serializer = $this
->prophesize(SerializerInterface::class);
$mock_serializer
->serialize([], 'json', Argument::that(function ($argument) {
return isset($argument['views_style_plugin']) && $argument['views_style_plugin'] instanceof Serializer;
}))
->willReturn()
->shouldBeCalled();
$view_serializer_style = new Serializer([], 'dummy_serializer', [], $mock_serializer
->reveal(), [
'json',
'xml',
], [
'json' => 'serialization',
'xml' => 'serialization',
]);
$view_serializer_style->options = [
'formats' => [
'xml',
'json',
],
];
$view_serializer_style->view = $this->view;
$view_serializer_style->displayHandler = $this->displayHandler;
$view_serializer_style
->render();
}
}