Security update for permissions_by_term
[yaffs-website] / vendor / drupal / drupal-driver / tests / Drupal / Tests / Driver / FieldHandlerAbstractTest.php
1 <?php
2
3 namespace Drupal\Tests\Driver;
4
5 /**
6  * Base class for field handler tests.
7  */
8 abstract class FieldHandlerAbstractTest extends \PHPUnit_Framework_TestCase {
9
10   /**
11    * {@inheritdoc}
12    */
13   public function tearDown() {
14     \Mockery::close();
15   }
16
17   /**
18    * Factory method to build and returned a mocked field handler.
19    *
20    * @param string $handler
21    *   The name of the field handler class under test.
22    * @param object $entity
23    *   An object representing an entity. Should contain a single property which
24    *   represents a field containing a value.
25    * @param string $entity_type
26    *   The entity type under test.
27    * @param array $field
28    *   An associative array with the following keys:
29    *   - 'field_name': the field name that is used for the property on $entity.
30    *   - 'columns': an optional array containing the column names of the field
31    *     as keys.
32    *
33    * @return \Mockery\MockInterface
34    *   The mocked field handler.
35    */
36   protected function getMockHandler($handler, $entity, $entity_type, array $field) {
37     $mock = \Mockery::mock(sprintf('Drupal\Driver\Fields\Drupal7\%s', $handler));
38     $mock->makePartial();
39     $mock->shouldReceive('getFieldInfo')->andReturn($field);
40     $mock->shouldReceive('getEntityLanguage')->andReturn('en');
41     $mock->__construct($entity, $entity_type, $field);
42
43     return $mock;
44   }
45
46   /**
47    * Simulate __call() since mocked handlers will not run through magic methods.
48    *
49    * @param mixed $values
50    *   The field value(s).
51    *
52    * @return array
53    *   The values parameter cast to an array.
54    */
55   protected function values($values) {
56     return (array) $values;
57   }
58
59 }