Interim commit.
[yaffs-website] / web / modules / contrib / video_embed_field / tests / src / Kernel / KernelTestBase.php
1 <?php
2
3 namespace Drupal\Tests\video_embed_field\Kernel;
4
5 use Drupal\Core\Entity\Entity\EntityViewDisplay;
6 use Drupal\field\Entity\FieldConfig;
7 use Drupal\field\Entity\FieldStorageConfig;
8 use Drupal\KernelTests\KernelTestBase as CoreKernelTestBase;
9
10 /**
11  * A kernel test base.
12  */
13 abstract class KernelTestBase extends CoreKernelTestBase {
14
15   /**
16    * The test field name.
17    *
18    * @var string
19    */
20   protected $fieldName = 'field_test';
21
22   /**
23    * The entity type ID.
24    *
25    * @var string
26    */
27   protected $entityTypeId = 'entity_test';
28
29   /**
30    * Modules to enable.
31    *
32    * @var array
33    */
34   public static $modules = [
35     'user',
36     'system',
37     'field',
38     'text',
39     'entity_test',
40     'field_test',
41     'video_embed_field',
42     'image',
43   ];
44
45   /**
46    * {@inheritdoc}
47    */
48   protected function setUp() {
49     parent::setUp();
50
51     $this->installEntitySchema($this->entityTypeId);
52
53     // Install image styles.
54     $this->installConfig(['image']);
55
56     EntityViewDisplay::create([
57       'targetEntityType' => 'entity_test',
58       'bundle' => 'entity_test',
59       'mode' => 'default',
60     ])->save();
61     FieldStorageConfig::create([
62       'field_name' => $this->fieldName,
63       'entity_type' => $this->entityTypeId,
64       'type' => 'video_embed_field',
65     ])->save();
66     FieldConfig::create([
67       'entity_type' => $this->entityTypeId,
68       'field_name' => $this->fieldName,
69       'bundle' => $this->entityTypeId,
70     ])->save();
71
72     // Fake colorbox being enabled for the purposes of testing.
73     $this->container->get('module_handler')->addModule('colorbox', NULL);
74
75     // Use a HTTP mock which won't attempt to download anything.
76     $this->container->set('http_client', new MockHttpClient());
77
78     // Shim in a service required from the colorbox module.
79     $colorbox_mock = $this->getMockBuilder('ColorboxAttachment')->setMethods(['attach'])->getMock();
80     $this->container->set('colorbox.attachment', $colorbox_mock);
81   }
82
83 }