X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fsrc%2FKernel%2FScripts%2FDbDumpCommandTest.php;fp=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fsrc%2FKernel%2FScripts%2FDbDumpCommandTest.php;h=a2ca86486200842a281e82f45901baab3de679a3;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/system/tests/src/Kernel/Scripts/DbDumpCommandTest.php b/web/core/modules/system/tests/src/Kernel/Scripts/DbDumpCommandTest.php new file mode 100644 index 000000000..a2ca86486 --- /dev/null +++ b/web/core/modules/system/tests/src/Kernel/Scripts/DbDumpCommandTest.php @@ -0,0 +1,85 @@ +databaseType() !== 'mysql') { + $this->markTestSkipped("Skipping test since the DbDumpCommand is currently only compatible with MySQL"); + } + + // Rebuild the router to ensure a routing table. + \Drupal::service('router.builder')->rebuild(); + + /** @var \Drupal\Core\Database\Connection $connection */ + $connection = $this->container->get('database'); + $connection->insert('router')->fields(['name', 'path', 'pattern_outline'])->values(['test', 'test', 'test'])->execute(); + } + + /** + * Test the command directly. + */ + public function testDbDumpCommand() { + $command = new DbDumpCommand(); + $command_tester = new CommandTester($command); + $command_tester->execute([]); + + // Assert that insert exists and that some expected fields exist. + $output = $command_tester->getDisplay(); + $this->assertContains("createTable('router", $output, 'Table router found'); + $this->assertContains("insert('router", $output, 'Insert found'); + $this->assertContains("'name' => 'test", $output, 'Insert name field found'); + $this->assertContains("'path' => 'test", $output, 'Insert path field found'); + $this->assertContains("'pattern_outline' => 'test", $output, 'Insert pattern_outline field found'); + $this->assertContains("// @codingStandardsIgnoreFile", $output); + } + + /** + * Test schema only option. + */ + public function testSchemaOnly() { + $command = new DbDumpCommand(); + $command_tester = new CommandTester($command); + $command_tester->execute(['--schema-only' => 'router']); + + // Assert that insert statement doesn't exist for schema only table. + $output = $command_tester->getDisplay(); + $this->assertContains("createTable('router", $output, 'Table router found'); + $this->assertNotContains("insert('router", $output, 'Insert not found'); + $this->assertNotContains("'name' => 'test", $output, 'Insert name field not found'); + $this->assertNotContains("'path' => 'test", $output, 'Insert path field not found'); + $this->assertNotContains("'pattern_outline' => 'test", $output, 'Insert pattern_outline field not found'); + + // Assert that insert statement doesn't exist for wildcard schema only match. + $command_tester->execute(['--schema-only' => 'route.*']); + $output = $command_tester->getDisplay(); + $this->assertContains("createTable('router", $output, 'Table router found'); + $this->assertNotContains("insert('router", $output, 'Insert not found'); + $this->assertNotContains("'name' => 'test", $output, 'Insert name field not found'); + $this->assertNotContains("'path' => 'test", $output, 'Insert path field not found'); + $this->assertNotContains("'pattern_outline' => 'test", $output, 'Insert pattern_outline field not found'); + } + +}