Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / views / tests / src / Unit / Plugin / field / FieldTest.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Tests\views\Unit\Plugin\field\FieldTest.
6  */
7
8 namespace Drupal\Tests\views\Unit\Plugin\field;
9
10 use Drupal\Core\Field\FieldStorageDefinitionInterface;
11 use Drupal\Tests\UnitTestCase;
12 use Drupal\Tests\views\Unit\Plugin\HandlerTestTrait;
13 use Drupal\views\Plugin\views\field\EntityField;
14 use Drupal\views\ResultRow;
15 use Symfony\Component\DependencyInjection\ContainerBuilder;
16
17 /**
18  * @coversDefaultClass \Drupal\views\Plugin\views\field\EntityField
19  * @group views
20  */
21 class FieldTest extends UnitTestCase {
22
23   use HandlerTestTrait;
24
25   /**
26    * The entity manager.
27    *
28    * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
29    */
30   protected $entityManager;
31
32   /**
33    * The mocked formatter plugin manager.
34    *
35    * @var \Drupal\Core\Field\FormatterPluginManager|\PHPUnit_Framework_MockObject_MockObject
36    */
37   protected $formatterPluginManager;
38
39   /**
40    * The mocked language manager.
41    *
42    * @var \Drupal\Core\Language\LanguageManagerInterface|\PHPUnit_Framework_MockObject_MockObject
43    */
44   protected $languageManager;
45
46   /**
47    * The mocked field type plugin manager.
48    *
49    * @var \Drupal\Core\Field\FieldTypePluginManagerInterface|\PHPUnit_Framework_MockObject_MockObject
50    */
51   protected $fieldTypePluginManager;
52
53   /**
54    * The renderer.
55    *
56    * @var \Drupal\Core\Render\RendererInterface|\PHPUnit_Framework_MockObject_MockObject
57    */
58   protected $renderer;
59
60   /**
61    * The container.
62    *
63    * @var \Drupal\Core\DependencyInjection\Container
64    */
65   protected $container;
66
67   /**
68    * {@inheritdoc}
69    */
70   protected function setUp() {
71     parent::setUp();
72
73     $this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
74     $this->formatterPluginManager = $this->getMockBuilder('Drupal\Core\Field\FormatterPluginManager')
75       ->disableOriginalConstructor()
76       ->getMock();
77
78     $this->fieldTypePluginManager = $this->getMock('Drupal\Core\Field\FieldTypePluginManagerInterface');
79     $this->fieldTypePluginManager->expects($this->any())
80       ->method('getDefaultStorageSettings')
81       ->willReturn([]);
82     $this->fieldTypePluginManager->expects($this->any())
83       ->method('getDefaultFieldSettings')
84       ->willReturn([]);
85
86     $this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
87     $this->renderer = $this->getMock('Drupal\Core\Render\RendererInterface');
88
89     $this->setupExecutableAndView();
90     $this->setupViewsData();
91     $this->display = $this->getMockBuilder('Drupal\views\Plugin\views\display\DisplayPluginBase')
92       ->disableOriginalConstructor()
93       ->getMock();
94
95     $this->container = new ContainerBuilder();
96     $this->container->set('plugin.manager.field.field_type', $this->fieldTypePluginManager);
97     \Drupal::setContainer($this->container);
98   }
99
100   /**
101    * @covers ::__construct
102    */
103   public function testConstruct() {
104     $definition = [
105       'entity_type' => 'test_entity',
106       // Just provide 'entity field' as definition. This is how EntityViewsData
107       // provides it.
108       'entity field' => 'title',
109     ];
110     $handler = new EntityField([], 'field', $definition, $this->entityManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer);
111
112     $this->assertEquals('title', $handler->definition['field_name']);
113   }
114
115   /**
116    * @covers ::defineOptions
117    */
118   public function testDefineOptionsWithNoOptions() {
119     $definition = [
120       'entity_type' => 'test_entity',
121       'field_name' => 'title',
122     ];
123     $handler = new EntityField([], 'field', $definition, $this->entityManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer);
124
125     // Setup the entity manager to allow fetching the storage definitions.
126     $title_storage = $this->getBaseFieldStorage();
127
128     $this->entityManager->expects($this->atLeastOnce())
129       ->method('getFieldStorageDefinitions')
130       ->with('test_entity')
131       ->willReturn([
132         'title' => $title_storage,
133       ]);
134
135     $options = [];
136     $handler->init($this->executable, $this->display, $options);
137
138     $this->assertEquals('value', $handler->options['group_column']);
139     $this->assertEquals(0, $handler->options['delta_limit']);
140   }
141
142   /**
143    * @covers ::defineOptions
144    */
145   public function testDefineOptionsWithDefaultFormatterOnFieldDefinition() {
146     $definition = [
147       'entity_type' => 'test_entity',
148       'field_name' => 'title',
149       'default_formatter' => 'test_example',
150       'default_formatter_settings' => ['link_to_entity' => TRUE],
151     ];
152     $handler = new EntityField([], 'field', $definition, $this->entityManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer);
153
154     // Setup the entity manager to allow fetching the storage definitions.
155     $title_storage = $this->getBaseFieldStorage();
156
157     $this->entityManager->expects($this->atLeastOnce())
158       ->method('getFieldStorageDefinitions')
159       ->with('test_entity')
160       ->willReturn([
161         'title' => $title_storage,
162       ]);
163
164     $options = [];
165     $handler->init($this->executable, $this->display, $options);
166
167     $this->assertEquals('test_example', $handler->options['type']);
168   }
169
170   /**
171    * @covers ::defineOptions
172    */
173   public function testDefineOptionsWithDefaultFormatterOnFieldType() {
174     $definition = [
175       'entity_type' => 'test_entity',
176       'field_name' => 'title',
177       'default_formatter_settings' => ['link_to_entity' => TRUE],
178     ];
179     $handler = new EntityField([], 'field', $definition, $this->entityManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer);
180
181     // Setup the entity manager to allow fetching the storage definitions.
182     $title_storage = $this->getBaseFieldStorage();
183
184     $this->entityManager->expects($this->atLeastOnce())
185       ->method('getFieldStorageDefinitions')
186       ->with('test_entity')
187       ->willReturn([
188         'title' => $title_storage,
189       ]);
190
191     $options = [];
192     $handler->init($this->executable, $this->display, $options);
193
194     $this->assertEquals(['link_to_entity' => TRUE], $handler->options['settings']);
195   }
196
197   /**
198    * @covers ::calculateDependencies
199    */
200   public function testCalculateDependenciesWithBaseField() {
201     $definition = [
202       'entity_type' => 'test_entity',
203       'field_name' => 'title',
204     ];
205     $handler = new EntityField([], 'field', $definition, $this->entityManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer);
206
207     $title_storage = $this->getBaseFieldStorage();
208     $this->entityManager->expects($this->atLeastOnce())
209       ->method('getFieldStorageDefinitions')
210       ->with('test_entity')
211       ->willReturn([
212         'title' => $title_storage,
213       ]);
214
215     $dependencies = $handler->calculateDependencies();
216     $this->assertEmpty($dependencies);
217   }
218
219   /**
220    * @covers ::calculateDependencies
221    */
222   public function testCalculateDependenciesWithConfiguredField() {
223     $definition = [
224       'entity_type' => 'test_entity',
225       'field_name' => 'body',
226     ];
227     $handler = new EntityField([], 'field', $definition, $this->entityManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer);
228
229     $body_storage = $this->getConfigFieldStorage();
230     $this->entityManager->expects($this->atLeastOnce())
231       ->method('getFieldStorageDefinitions')
232       ->with('test_entity')
233       ->willReturn([
234         'body' => $body_storage,
235       ]);
236
237     $body_storage->expects($this->atLeastOnce())
238       ->method('getConfigDependencyName')
239       ->willReturn('field.field_storage_config.body');
240
241     $dependencies = $handler->calculateDependencies();
242     $this->assertEquals(['config' => ['field.field_storage_config.body']], $dependencies);
243   }
244
245   /**
246    * @covers ::access
247    */
248   public function testAccess() {
249     $definition = [
250       'entity_type' => 'test_entity',
251       'field_name' => 'title',
252     ];
253     $handler = new EntityField([], 'field', $definition, $this->entityManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer);
254     $handler->view = $this->executable;
255     $handler->setViewsData($this->viewsData);
256
257     $this->view->expects($this->atLeastOnce())
258       ->method('get')
259       ->with('base_table')
260       ->willReturn('test_entity_table');
261
262     $this->viewsData->expects($this->atLeastOnce())
263       ->method('get')
264       ->with('test_entity_table')
265       ->willReturn([
266         'table' => ['entity type' => 'test_entity'],
267       ]);
268
269     $access_control_handler = $this->getMock('Drupal\Core\Entity\EntityAccessControlHandlerInterface');
270     $this->entityManager->expects($this->atLeastOnce())
271       ->method('getAccessControlHandler')
272       ->with('test_entity')
273       ->willReturn($access_control_handler);
274
275     $title_storage = $this->getBaseFieldStorage();
276     $this->entityManager->expects($this->atLeastOnce())
277       ->method('getFieldStorageDefinitions')
278       ->with('test_entity')
279       ->willReturn([
280         'title' => $title_storage,
281       ]);
282
283     $account = $this->getMock('Drupal\Core\Session\AccountInterface');
284
285     $access_control_handler->expects($this->atLeastOnce())
286       ->method('fieldAccess')
287       ->with('view', $this->anything(), $account, NULL, $this->anything())
288       ->willReturn(TRUE);
289
290     $this->assertTrue($handler->access($account));
291   }
292
293   /**
294    * @dataProvider providerSortOrders
295    *
296    * @param string $order
297    *   The sort order.
298    */
299   public function testClickSortWithOutConfiguredColumn($order) {
300     $definition = [
301       'entity_type' => 'test_entity',
302       'field_name' => 'title',
303     ];
304     $handler = new EntityField([], 'field', $definition, $this->entityManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer);
305     $handler->view = $this->executable;
306
307     $this->entityManager->expects($this->never())
308       ->method('getFieldStorageDefinitions');
309
310     $handler->clickSort($order);
311   }
312
313   /**
314    * @dataProvider providerSortOrders
315    *
316    * @param string $order
317    *   The sort order.
318    *
319    * @covers ::clickSort
320    */
321   public function testClickSortWithBaseField($order) {
322     $definition = [
323       'entity_type' => 'test_entity',
324       'field_name' => 'title',
325     ];
326     $handler = new EntityField([], 'field', $definition, $this->entityManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer);
327     $handler->view = $this->executable;
328
329     $field_storage = $this->getBaseFieldStorage();
330     $this->entityManager->expects($this->atLeastOnce())
331       ->method('getFieldStorageDefinitions')
332       ->with('test_entity')
333       ->willReturn([
334         'title' => $field_storage,
335       ]);
336
337     $table_mapping = $this->getMock('Drupal\Core\Entity\Sql\TableMappingInterface');
338     $table_mapping
339       ->expects($this->atLeastOnce())
340       ->method('getFieldColumnName')
341       ->with($field_storage, 'value')
342       ->willReturn('title');
343     $entity_storage = $this->getMock('Drupal\Core\Entity\Sql\SqlEntityStorageInterface');
344     $entity_storage->expects($this->atLeastOnce())
345       ->method('getTableMapping')
346       ->willReturn($table_mapping);
347     $this->entityManager->expects($this->atLeastOnce())
348       ->method('getStorage')
349       ->with('test_entity')
350       ->willReturn($entity_storage);
351
352     // Setup a click sort configuration.
353     $options = [
354       'click_sort_column' => 'value',
355       'table' => 'test_entity',
356     ];
357     $handler->init($this->executable, $this->display, $options);
358
359     $handler->query = $this->getMockBuilder('Drupal\views\Plugin\views\query\Sql')
360       ->disableOriginalConstructor()
361       ->getMock();
362     $handler->query->expects($this->atLeastOnce())
363       ->method('ensureTable')
364       ->with('test_entity', NULL)
365       ->willReturn('test_entity');
366
367     $handler->query->expects($this->atLeastOnce())
368       ->method('addOrderBy')
369       ->with(NULL, NULL, $order, 'test_entity.title', []);
370     $handler->clickSort($order);
371   }
372
373   /**
374    * @dataProvider providerSortOrders
375    *
376    * @param string $order
377    *   The sort order.
378    *
379    * @covers ::clickSort
380    */
381   public function testClickSortWithConfiguredField($order) {
382     $definition = [
383       'entity_type' => 'test_entity',
384       'field_name' => 'body',
385     ];
386     $handler = new EntityField([], 'field', $definition, $this->entityManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer);
387     $handler->view = $this->executable;
388
389     $field_storage = $this->getConfigFieldStorage();
390     $this->entityManager->expects($this->atLeastOnce())
391       ->method('getFieldStorageDefinitions')
392       ->with('test_entity')
393       ->willReturn([
394         'body' => $field_storage,
395       ]);
396
397     $table_mapping = $this->getMock('Drupal\Core\Entity\Sql\TableMappingInterface');
398     $table_mapping
399       ->expects($this->atLeastOnce())
400       ->method('getFieldColumnName')
401       ->with($field_storage, 'value')
402       ->willReturn('body_value');
403     $entity_storage = $this->getMock('Drupal\Core\Entity\Sql\SqlEntityStorageInterface');
404     $entity_storage->expects($this->atLeastOnce())
405       ->method('getTableMapping')
406       ->willReturn($table_mapping);
407     $this->entityManager->expects($this->atLeastOnce())
408       ->method('getStorage')
409       ->with('test_entity')
410       ->willReturn($entity_storage);
411
412     // Setup a click sort configuration.
413     $options = [
414       'click_sort_column' => 'value',
415       'table' => 'test_entity__body',
416     ];
417     $handler->init($this->executable, $this->display, $options);
418
419     $handler->query = $this->getMockBuilder('Drupal\views\Plugin\views\query\Sql')
420       ->disableOriginalConstructor()
421       ->getMock();
422     $handler->query->expects($this->atLeastOnce())
423       ->method('ensureTable')
424       ->with('test_entity__body', NULL)
425       ->willReturn('test_entity__body_alias');
426
427     $handler->query->expects($this->atLeastOnce())
428       ->method('addOrderBy')
429       ->with(NULL, NULL, $order, 'test_entity__body_alias.body_value', []);
430     $handler->clickSort($order);
431   }
432
433   /**
434    * @covers ::query
435    */
436   public function testQueryWithGroupByForBaseField() {
437     $definition = [
438       'entity_type' => 'test_entity',
439       'field_name' => 'title',
440     ];
441     $handler = new EntityField([], 'field', $definition, $this->entityManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer);
442     $handler->view = $this->executable;
443     $handler->view->field = [$handler];
444
445     $this->setupLanguageRenderer($handler, $definition);
446
447     $field_storage = $this->getBaseFieldStorage();
448     $this->entityManager->expects($this->any())
449       ->method('getFieldStorageDefinitions')
450       ->with('test_entity')
451       ->willReturn([
452         'title' => $field_storage,
453       ]);
454
455     $table_mapping = $this->getMock('Drupal\Core\Entity\Sql\TableMappingInterface');
456     $table_mapping
457       ->expects($this->any())
458       ->method('getFieldColumnName')
459       ->with($field_storage, 'value')
460       ->willReturn('title');
461     $entity_storage = $this->getMock('Drupal\Core\Entity\Sql\SqlEntityStorageInterface');
462     $entity_storage->expects($this->any())
463       ->method('getTableMapping')
464       ->willReturn($table_mapping);
465     $this->entityManager->expects($this->any())
466       ->method('getStorage')
467       ->with('test_entity')
468       ->willReturn($entity_storage);
469
470     $options = [
471       'group_column' => 'value',
472       'group_columns' => [],
473       'table' => 'test_entity_table',
474     ];
475     $handler->init($this->executable, $this->display, $options);
476
477     $query = $this->getMockBuilder('Drupal\views\Plugin\views\query\Sql')
478       ->disableOriginalConstructor()
479       ->getMock();
480     $query->expects($this->once())
481       ->method('ensureTable')
482       ->with('test_entity_table', NULL)
483       ->willReturn('test_entity_table');
484     // Ensure that we add the title field to the query, if we group by some
485     // other field in the view.
486     $query->expects($this->once())
487       ->method('addField')
488       ->with('test_entity_table', 'title');
489
490     $this->executable->query = $query;
491
492     $handler->query(TRUE);
493   }
494
495   /**
496    * @covers ::query
497    */
498   public function testQueryWithGroupByForConfigField() {
499     $definition = [
500       'entity_type' => 'test_entity',
501       'field_name' => 'body',
502     ];
503     $handler = new EntityField([], 'field', $definition, $this->entityManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer);
504     $handler->view = $this->executable;
505     $handler->view->field = [$handler];
506
507     $this->setupLanguageRenderer($handler, $definition);
508
509     $field_storage = $this->getConfigFieldStorage();
510     $this->entityManager->expects($this->any())
511       ->method('getFieldStorageDefinitions')
512       ->with('test_entity')
513       ->willReturn([
514         'body' => $field_storage,
515       ]);
516
517     $table_mapping = $this->getMock('Drupal\Core\Entity\Sql\TableMappingInterface');
518     $table_mapping
519       ->expects($this->any())
520       ->method('getFieldColumnName')
521       ->with($field_storage, 'value')
522       ->willReturn('body_value');
523     $entity_storage = $this->getMock('Drupal\Core\Entity\Sql\SqlEntityStorageInterface');
524     $entity_storage->expects($this->any())
525       ->method('getTableMapping')
526       ->willReturn($table_mapping);
527     $this->entityManager->expects($this->any())
528       ->method('getStorage')
529       ->with('test_entity')
530       ->willReturn($entity_storage);
531
532     $options = [
533       'group_column' => 'value',
534       'group_columns' => [],
535       'table' => 'test_entity__body',
536     ];
537     $handler->init($this->executable, $this->display, $options);
538
539     $query = $this->getMockBuilder('Drupal\views\Plugin\views\query\Sql')
540       ->disableOriginalConstructor()
541       ->getMock();
542     $query->expects($this->once())
543       ->method('ensureTable')
544       ->with('test_entity__body', NULL)
545       ->willReturn('test_entity__body');
546     // Ensure that we add the title field to the query, if we group by some
547     // other field in the view.
548     $query->expects($this->once())
549       ->method('addField')
550       ->with('test_entity__body', 'body_value');
551
552     $this->executable->query = $query;
553
554     $handler->query(TRUE);
555   }
556
557   /**
558    * @covers ::prepareItemsByDelta
559    *
560    * @dataProvider providerTestPrepareItemsByDelta
561    */
562   public function testPrepareItemsByDelta(array $options, array $expected_values) {
563     $definition = [
564       'entity_type' => 'test_entity',
565       'field_name' => 'integer',
566     ];
567     $handler = new FieldTestEntityField([], 'field', $definition, $this->entityManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer);
568     $handler->view = $this->executable;
569     $handler->view->field = [$handler];
570
571     $this->setupLanguageRenderer($handler, $definition);
572
573     $field_storage = $this->getConfigFieldStorage();
574     $field_storage->expects($this->any())
575       ->method('getCardinality')
576       ->willReturn(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
577
578     $this->entityManager->expects($this->any())
579       ->method('getFieldStorageDefinitions')
580       ->with('test_entity')
581       ->willReturn([
582         'integer' => $field_storage,
583       ]);
584
585     $table_mapping = $this->getMock('Drupal\Core\Entity\Sql\TableMappingInterface');
586     $table_mapping
587       ->expects($this->any())
588       ->method('getFieldColumnName')
589       ->with($field_storage, 'value')
590       ->willReturn('integer_value');
591     $entity_storage = $this->getMock('Drupal\Core\Entity\Sql\SqlEntityStorageInterface');
592     $entity_storage->expects($this->any())
593       ->method('getTableMapping')
594       ->willReturn($table_mapping);
595     $this->entityManager->expects($this->any())
596       ->method('getStorage')
597       ->with('test_entity')
598       ->willReturn($entity_storage);
599
600     $options = [
601       'group_column' => 'value',
602       'group_columns' => [],
603       'table' => 'test_entity__integer',
604     ] + $options;
605     $handler->init($this->executable, $this->display, $options);
606
607     $this->executable->row_index = 0;
608     $this->executable->result = [0 => new ResultRow([])];
609
610     $items = [3, 1, 4, 1, 5, 9];
611     $this->assertEquals($expected_values, $handler->executePrepareItemsByDelta($items));
612   }
613
614   /**
615    * Provides test data for testPrepareItemsByDelta().
616    */
617   public function providerTestPrepareItemsByDelta() {
618     $data = [];
619
620     // Let's display all values.
621     $data[] = [[], [3, 1, 4, 1, 5, 9]];
622     // Test just reversed deltas.
623     $data[] = [['delta_reversed' => TRUE], [9, 5, 1, 4, 1, 3]];
624
625     // Test combinations of delta limit, offset and first_last.
626     $data[] = [['group_rows' => TRUE, 'delta_limit' => 3], [3, 1, 4]];
627     $data[] = [['group_rows' => TRUE, 'delta_limit' => 3, 'delta_offset' => 2], [4, 1, 5]];
628     $data[] = [['group_rows' => TRUE, 'delta_reversed' => TRUE, 'delta_limit' => 3, 'delta_offset' => 2], [1, 4, 1]];
629     $data[] = [['group_rows' => TRUE, 'delta_first_last' => TRUE], [3, 9]];
630     $data[] = [['group_rows' => TRUE, 'delta_limit' => 1, 'delta_first_last' => TRUE], [3]];
631     $data[] = [['group_rows' => TRUE, 'delta_offset' => 1, 'delta_first_last' => TRUE], [1, 9]];
632
633     return $data;
634   }
635
636   /**
637    * Returns a mocked base field storage object.
638    *
639    * @return \Drupal\Core\Field\FieldStorageDefinitionInterface|\PHPUnit_Framework_MockObject_MockObject
640    */
641   protected function getBaseFieldStorage() {
642     $title_storage = $this->getMock('Drupal\Core\Field\FieldStorageDefinitionInterface');
643     $title_storage->expects($this->any())
644       ->method('getColumns')
645       ->willReturn(['value' => ['type' => 'varchar']]);
646     $title_storage->expects($this->any())
647       ->method('getSettings')
648       ->willReturn([]);
649     $title_storage->expects($this->any())
650       ->method('getConstraints')
651       ->willReturn([]);
652     return $title_storage;
653   }
654
655   /**
656    * Returns a mocked configurable field storage object.
657    *
658    * @return \Drupal\field\FieldStorageConfigInterface|\PHPUnit_Framework_MockObject_MockObject
659    */
660   protected function getConfigFieldStorage() {
661     $title_storage = $this->getMock('Drupal\field\FieldStorageConfigInterface');
662     $title_storage->expects($this->any())
663       ->method('getColumns')
664       ->willReturn(['value' => ['type' => 'varchar']]);
665     $title_storage->expects($this->any())
666       ->method('getSettings')
667       ->willReturn([]);
668     $title_storage->expects($this->any())
669       ->method('getConstraints')
670       ->willReturn([]);
671     return $title_storage;
672   }
673
674   /**
675    * Provides sort orders for clickSort() test methods.
676    *
677    * @return array
678    */
679   public function providerSortOrders() {
680     return [
681       ['asc'],
682       ['desc'],
683       ['ASC'],
684       ['DESC'],
685     ];
686   }
687
688   /**
689    * Setup the mock data needed to make language renderers work.
690    *
691    * @param \Drupal\views\Plugin\views\field\EntityField $handler
692    *   The field handler.
693    * @param $definition
694    *   An array with entity type definition data.
695    */
696   protected function setupLanguageRenderer(EntityField $handler, $definition) {
697     $display_handler = $this->getMockBuilder('\Drupal\views\Plugin\views\display\DisplayPluginBase')
698       ->disableOriginalConstructor()
699       ->getMock();
700     $display_handler->expects($this->any())
701       ->method('getOption')
702       ->with($this->equalTo('rendering_language'))
703       ->willReturn('en');
704     $handler->view->display_handler = $display_handler;
705
706     $data['table']['entity type'] = $definition['entity_type'];
707     $views_data = $this->getMockBuilder('\Drupal\views\ViewsData')
708       ->disableOriginalConstructor()
709       ->getMock();
710     $views_data->expects($this->any())
711       ->method('get')
712       ->willReturn($data);
713     $this->container->set('views.views_data', $views_data);
714
715     $entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
716     $entity_type->expects($this->any())
717       ->method('id')
718       ->willReturn($definition['entity_type']);
719
720     $this->entityManager->expects($this->any())
721       ->method('getDefinition')
722       ->willReturn($entity_type);
723   }
724
725 }
726
727 class FieldTestEntityField extends EntityField {
728
729   public function executePrepareItemsByDelta(array $all_values) {
730     return $this->prepareItemsByDelta($all_values);
731   }
732
733 }