diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2014-07-07 12:32:24 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-07-07 12:32:24 +0200 |
commit | b091b15f0bc683e15f5f6ee2414c265ac7a3cdbb (patch) | |
tree | d90e5c4ede7be147052f88d0eafe1d9646001e5f /tests | |
parent | 5c444c2da8b47546ef120a365b872b4fc078a8cf (diff) | |
download | nextcloud-server-b091b15f0bc683e15f5f6ee2414c265ac7a3cdbb.tar.gz nextcloud-server-b091b15f0bc683e15f5f6ee2414c265ac7a3cdbb.zip |
MySQL: adding repair step to convert MyIsam tables to InnoDB
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/repair/repairinnodb.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/lib/repair/repairinnodb.php b/tests/lib/repair/repairinnodb.php new file mode 100644 index 00000000000..e7d2442f127 --- /dev/null +++ b/tests/lib/repair/repairinnodb.php @@ -0,0 +1,65 @@ +<?php +/** + * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +/** + * Tests for the converting of MySQL tables to InnoDB engine + * + * @see \OC\Repair\RepairMimeTypes + */ +class TestRepairInnoDB extends PHPUnit_Framework_TestCase { + + /** @var \OC\RepairStep */ + private $repair; + + /** @var \Doctrine\DBAL\Connection */ + private $connection; + + /** @var string */ + private $tableName; + + public function setUp() { + $this->connection = \OC_DB::getConnection(); + if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) { + $this->markTestSkipped("Test only relevant on MySql"); + } + + $dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix"); + $this->tableName = uniqid($dbPrefix . "_innodb_test"); + $this->connection->exec("CREATE TABLE $this->tableName(id INT) ENGINE MyISAM"); + + $this->repair = new \OC\Repair\InnoDB(); + } + + public function tearDown() { + $this->connection->getSchemaManager()->dropTable($this->tableName); + } + + public function testInnoDBConvert() { + $result = $this->countMyIsamTables(); + $this->assertEquals(1, $result); + + $this->repair->run(); + + $result = $this->countMyIsamTables(); + $this->assertEquals(0, $result); + } + + /** + * @param $dbName + * @return mixed + */ + private function countMyIsamTables() { + $dbName = \OC::$server->getConfig()->getSystemValue("dbname"); + + $result = $this->connection->fetchColumn( + "SELECT count(*) FROM information_schema.tables WHERE table_schema = ? and table_name = ? AND engine = 'MyISAM'", + array($dbName, $this->tableName) + ); + return $result; + } +} |