-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3881f04
commit 78c2c21
Showing
6 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
dev/tests/integration/testsuite/Magento/Framework/Backup/DbTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Framework\Backup; | ||
|
||
use Magento\Backup\Helper\Data; | ||
use Magento\Framework\App\Filesystem\DirectoryList; | ||
use Magento\Framework\Filesystem; | ||
use Magento\Framework\Module\Setup; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Provide tests for \Magento\Framework\Backup\Db. | ||
*/ | ||
class DbTest extends TestCase | ||
{ | ||
/** | ||
* Test db backup includes triggers. | ||
* | ||
* @magentoDataFixture Magento/Framework/Backup/_files/trigger.php | ||
*/ | ||
public function testBackupIncludesCustomTriggers() | ||
{ | ||
$helper = Bootstrap::getObjectManager()->get(Data::class); | ||
$time = time(); | ||
$backupManager = Bootstrap::getObjectManager()->get(Factory::class)->create( | ||
Factory::TYPE_DB | ||
)->setBackupExtension( | ||
$helper->getExtensionByType(Factory::TYPE_DB) | ||
)->setTime( | ||
$time | ||
)->setBackupsDir( | ||
$helper->getBackupsDir() | ||
)->setName('test_backup'); | ||
$backupManager->create(); | ||
$write = Bootstrap::getObjectManager()->get(Filesystem::class)->getDirectoryWrite(DirectoryList::VAR_DIR); | ||
$content = $write->readFile('/backups/' . $time . '_db_testbackup.sql'); | ||
$tableName = Bootstrap::getObjectManager()->get(Setup::class) | ||
->getTable('test_table_with_custom_trigger'); | ||
$this->assertRegExp( | ||
'/CREATE TRIGGER test_custom_trigger AFTER INSERT ON '. $tableName . ' FOR EACH ROW/', | ||
$content | ||
); | ||
//Clean up. | ||
$write->delete('/backups/' . $time . '_db_testbackup.sql'); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
dev/tests/integration/testsuite/Magento/Framework/Backup/_files/trigger.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
use Magento\Framework\DB\Ddl\Trigger; | ||
use Magento\Framework\DB\Ddl\TriggerFactory; | ||
use Magento\Framework\Module\Setup; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
$setup = Bootstrap::getObjectManager()->get(Setup::class); | ||
$tableName = $setup->getTable('test_table_with_custom_trigger'); | ||
$table = $setup->getConnection()->newTable( | ||
$tableName | ||
)->addColumn( | ||
'id', | ||
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, | ||
null, | ||
['identity' => true, 'nullable' => false, 'primary' => true], | ||
'ID' | ||
)->setComment( | ||
'Test table with test custom trigger' | ||
); | ||
$setup->getConnection()->createTable($table); | ||
|
||
$trigger = Bootstrap::getObjectManager()->get(TriggerFactory::class)->create() | ||
->setName('test_custom_trigger') | ||
->setTime(Trigger::TIME_AFTER) | ||
->setEvent(Trigger::EVENT_INSERT) | ||
->setTable($tableName) | ||
->addStatement($setup->getConnection()->quoteInto('SET @test_variable = ?', 'test_value')); | ||
$setup->getConnection()->createTrigger($trigger); |
13 changes: 13 additions & 0 deletions
13
dev/tests/integration/testsuite/Magento/Framework/Backup/_files/trigger_rollback.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
use Magento\Framework\Module\Setup; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
$setup = Bootstrap::getObjectManager()->get(Setup::class); | ||
$tableName = $setup->getTable('test_table_with_custom_trigger'); | ||
$setup->getConnection()->dropTrigger('test_custom_trigger'); | ||
$setup->getConnection()->dropTable($tableName); |