Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / migrate_drupal / tests / src / Unit / source / DrupalSqlBaseTest.php
1 <?php
2
3 namespace Drupal\Tests\migrate_drupal\Unit\source;
4
5 use Drupal\Tests\migrate\Unit\MigrateTestCase;
6 use Drupal\migrate\Exception\RequirementsException;
7
8 /**
9  * @coversDefaultClass Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase
10  * @group migrate_drupal
11  */
12 class DrupalSqlBaseTest extends MigrateTestCase {
13
14   /**
15    * Define bare minimum migration configuration.
16    */
17   protected $migrationConfiguration = [
18     'id' => 'DrupalSqlBase',
19   ];
20
21   /**
22    * @var \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase
23   */
24   protected $base;
25
26   /**
27    * Minimum database contents needed to test DrupalSqlBase.
28    */
29   protected $databaseContents = [
30     'system' => [
31       [
32         'filename' => 'sites/all/modules/module1',
33         'name' => 'module1',
34         'type' => 'module',
35         'status' => 0,
36         'schema_version' => -1,
37       ],
38     ],
39   ];
40
41   /**
42    * @covers ::checkRequirements
43    */
44   public function testSourceProviderNotActive() {
45     $plugin_definition['requirements_met'] = TRUE;
46     $plugin_definition['source_module'] = 'module1';
47     /** @var \Drupal\Core\State\StateInterface $state */
48     $state = $this->getMock('Drupal\Core\State\StateInterface');
49     /** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */
50     $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
51     $plugin = new TestDrupalSqlBase([], 'placeholder_id', $plugin_definition, $this->getMigration(), $state, $entity_manager);
52     $plugin->setDatabase($this->getDatabase($this->databaseContents));
53     $system_data = $plugin->getSystemData();
54     $this->setExpectedException(RequirementsException::class, 'The module module1 is not enabled in the source site.');
55     try {
56       $plugin->checkRequirements();
57     }
58     catch (RequirementsException $e) {
59       // Ensure requirements are set on the exception.
60       $this->assertEquals(['source_module' => 'module1'], $e->getRequirements());
61       // Re-throw so PHPUnit can assert the exception.
62       throw $e;
63     }
64   }
65
66 }
67
68 namespace Drupal\Tests\migrate_drupal\Unit\source;
69
70 use Drupal\Core\Database\Connection;
71 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
72
73 /**
74  * Extends the DrupalSqlBase abstract class.
75  */
76 class TestDrupalSqlBase extends DrupalSqlBase {
77
78   /**
79    * {@inheritdoc}
80    */
81   public function fields() {
82     return [];
83   }
84
85   /**
86    * {@inheritdoc}
87    */
88   public function query() {
89   }
90
91   /**
92    * Tweaks DrupalSqlBase to set a new database connection for tests.
93    *
94    * @param \Drupal\Core\Database\Connection $database
95    *   The new connection to use.
96    *
97    * @see \Drupal\Tests\migrate\Unit\MigrateSourceSqlTestCase
98    */
99   public function setDatabase(Connection $database) {
100     $this->database = $database;
101   }
102
103   /**
104    * {@inheritdoc}
105    */
106   public function getIds() {
107     return [];
108   }
109
110 }