3 namespace Drupal\Tests\rest\Unit\Plugin\views\style;
5 use Drupal\rest\Plugin\views\display\RestExport;
6 use Drupal\rest\Plugin\views\style\Serializer;
7 use Drupal\Tests\UnitTestCase;
8 use Drupal\views\ViewExecutable;
10 use Symfony\Component\Serializer\SerializerInterface;
13 * @coversDefaultClass \Drupal\rest\Plugin\views\style\Serializer
16 class SerializerTest extends UnitTestCase {
21 * @var \Drupal\views\ViewExecutable|\PHPUnit_Framework_MockObject_MockObject
26 * The RestExport display handler.
28 * @var \Drupal\rest\Plugin\views\display\RestExport|\PHPUnit_Framework_MockObject_MockObject
30 protected $displayHandler;
35 protected function setUp() {
38 $this->view = $this->getMockBuilder(ViewExecutable::class)
39 ->disableOriginalConstructor()
42 // Make the view result empty so we don't have to mock the row plugin render
44 $this->view->result = [];
46 $this->displayHandler = $this->getMockBuilder(RestExport::class)
47 ->disableOriginalConstructor()
50 $this->displayHandler->expects($this->any())
51 ->method('getContentType')
56 * Tests that the symfony serializer receives style plugin from the render() method.
60 public function testSerializerReceivesOptions() {
61 $mock_serializer = $this->prophesize(SerializerInterface::class);
63 // This is the main expectation of the test. We want to make sure the
64 // serializer options are passed to the SerializerInterface object.
65 $mock_serializer->serialize([], 'json', Argument::that(function ($argument) {
66 return isset($argument['views_style_plugin']) && $argument['views_style_plugin'] instanceof Serializer;
71 $view_serializer_style = new Serializer([], 'dummy_serializer', [], $mock_serializer->reveal(), ['json', 'xml'], ['json' => 'serialization', 'xml' => 'serialization']);
72 $view_serializer_style->options = ['formats' => ['xml', 'json']];
73 $view_serializer_style->view = $this->view;
74 $view_serializer_style->displayHandler = $this->displayHandler;
75 $view_serializer_style->render();