Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / system / tests / src / Kernel / Scripts / DbDumpCommandTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Kernel\Scripts;
4
5 use Drupal\Core\Command\DbDumpCommand;
6 use Drupal\Core\Database\Database;
7 use Drupal\KernelTests\KernelTestBase;
8 use Symfony\Component\Console\Tester\CommandTester;
9
10 /**
11  * Test that the DbDumpCommand works correctly.
12  *
13  * @group console
14  */
15 class DbDumpCommandTest extends KernelTestBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public static $modules = ['system'];
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function setUp() {
26     parent::setUp();
27
28     // Determine what database backend is running, and set the skip flag.
29     if (Database::getConnection()->databaseType() !== 'mysql') {
30       $this->markTestSkipped("Skipping test since the DbDumpCommand is currently only compatible with MySQL");
31     }
32
33     // Rebuild the router to ensure a routing table.
34     \Drupal::service('router.builder')->rebuild();
35
36     /** @var \Drupal\Core\Database\Connection $connection */
37     $connection = $this->container->get('database');
38     $connection->insert('router')->fields(['name', 'path', 'pattern_outline'])->values(['test', 'test', 'test'])->execute();
39   }
40
41   /**
42    * Test the command directly.
43    */
44   public function testDbDumpCommand() {
45     $command = new DbDumpCommand();
46     $command_tester = new CommandTester($command);
47     $command_tester->execute([]);
48
49     // Assert that insert exists and that some expected fields exist.
50     $output = $command_tester->getDisplay();
51     $this->assertContains("createTable('router", $output, 'Table router found');
52     $this->assertContains("insert('router", $output, 'Insert found');
53     $this->assertContains("'name' => 'test", $output, 'Insert name field found');
54     $this->assertContains("'path' => 'test", $output, 'Insert path field found');
55     $this->assertContains("'pattern_outline' => 'test", $output, 'Insert pattern_outline field found');
56     $this->assertContains("// @codingStandardsIgnoreFile", $output);
57   }
58
59   /**
60    * Test schema only option.
61    */
62   public function testSchemaOnly() {
63     $command = new DbDumpCommand();
64     $command_tester = new CommandTester($command);
65     $command_tester->execute(['--schema-only' => 'router']);
66
67     // Assert that insert statement doesn't exist for schema only table.
68     $output = $command_tester->getDisplay();
69     $this->assertContains("createTable('router", $output, 'Table router found');
70     $this->assertNotContains("insert('router", $output, 'Insert not found');
71     $this->assertNotContains("'name' => 'test", $output, 'Insert name field not found');
72     $this->assertNotContains("'path' => 'test", $output, 'Insert path field not found');
73     $this->assertNotContains("'pattern_outline' => 'test", $output, 'Insert pattern_outline field not found');
74
75     // Assert that insert statement doesn't exist for wildcard schema only match.
76     $command_tester->execute(['--schema-only' => 'route.*']);
77     $output = $command_tester->getDisplay();
78     $this->assertContains("createTable('router", $output, 'Table router found');
79     $this->assertNotContains("insert('router", $output, 'Insert not found');
80     $this->assertNotContains("'name' => 'test", $output, 'Insert name field not found');
81     $this->assertNotContains("'path' => 'test", $output, 'Insert path field not found');
82     $this->assertNotContains("'pattern_outline' => 'test", $output, 'Insert pattern_outline field not found');
83   }
84
85 }