|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Setup; |
| 8 | + |
| 9 | +use Magento\Setup\Model\Declaration\Schema\SchemaConfig; |
| 10 | +use Magento\TestFramework\Deploy\CliCommand; |
| 11 | +use Magento\TestFramework\Deploy\TestModuleManager; |
| 12 | +use Magento\TestFramework\Helper\Bootstrap; |
| 13 | +use Magento\TestFramework\TestCase\SetupTestCase; |
| 14 | + |
| 15 | +/** |
| 16 | + * The purpose of this test is verifying initial InstallSchema, InstallData scripts. |
| 17 | + */ |
| 18 | +class ValidationRulesTest extends SetupTestCase |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @var TestModuleManager |
| 22 | + */ |
| 23 | + private $moduleManager; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var SchemaConfig |
| 27 | + */ |
| 28 | + private $schemaConfig; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var CliCommand |
| 32 | + */ |
| 33 | + private $cliCommad; |
| 34 | + |
| 35 | + public function setUp() |
| 36 | + { |
| 37 | + $objectManager = Bootstrap::getObjectManager(); |
| 38 | + $this->schemaConfig = $objectManager->create(SchemaConfig::class); |
| 39 | + $this->moduleManager = $objectManager->get(TestModuleManager::class); |
| 40 | + $this->cliCommad = $objectManager->get(CliCommand::class); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * @expectedException \Magento\Setup\Exception |
| 45 | + * @expectedExceptionMessageRegExp /Primary key can`t be applied on table "test_table". All columns should be not nullable/ |
| 46 | + * @moduleName Magento_TestSetupDeclarationModule8 |
| 47 | + */ |
| 48 | + public function testFailOnInvalidPrimaryKey() |
| 49 | + { |
| 50 | + $this->cliCommad->install( |
| 51 | + ['Magento_TestSetupDeclarationModule8'] |
| 52 | + ); |
| 53 | + $this->moduleManager->updateRevision( |
| 54 | + 'Magento_TestSetupDeclarationModule8', |
| 55 | + 'invalid_primary_key', |
| 56 | + 'db_schema.xml', |
| 57 | + 'etc' |
| 58 | + ); |
| 59 | + |
| 60 | + $this->schemaConfig->getDeclarationConfig(); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * @expectedException \Magento\Setup\Exception |
| 65 | + * @expectedExceptionMessageRegExp /Column definition "page_id_on" and reference column definition "page_id" are different in tables "dependent" and "test_table"/ |
| 66 | + * @moduleName Magento_TestSetupDeclarationModule8 |
| 67 | + */ |
| 68 | + public function testFailOnIncosistentReferenceDefinition() |
| 69 | + { |
| 70 | + $this->cliCommad->install( |
| 71 | + ['Magento_TestSetupDeclarationModule8'] |
| 72 | + ); |
| 73 | + $this->moduleManager->updateRevision( |
| 74 | + 'Magento_TestSetupDeclarationModule8', |
| 75 | + 'incosistence_reference_definition', |
| 76 | + 'db_schema.xml', |
| 77 | + 'etc' |
| 78 | + ); |
| 79 | + $this->schemaConfig->getDeclarationConfig(); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * @expectedException \Magento\Setup\Exception |
| 84 | + * @expectedExceptionMessageRegExp /Auto Increment column do not have index. Column - "page_id"/ |
| 85 | + * @moduleName Magento_TestSetupDeclarationModule8 |
| 86 | + */ |
| 87 | + public function testFailOnInvalidAutoIncrementFiel() |
| 88 | + { |
| 89 | + $this->cliCommad->install( |
| 90 | + ['Magento_TestSetupDeclarationModule8'] |
| 91 | + ); |
| 92 | + $this->moduleManager->updateRevision( |
| 93 | + 'Magento_TestSetupDeclarationModule8', |
| 94 | + 'invalid_auto_increment', |
| 95 | + 'db_schema.xml', |
| 96 | + 'etc' |
| 97 | + ); |
| 98 | + $this->schemaConfig->getDeclarationConfig(); |
| 99 | + } |
| 100 | +} |
0 commit comments