repairinnodb.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test\Repair;
  9. /**
  10. * Tests for the converting of MySQL tables to InnoDB engine
  11. *
  12. * @see \OC\Repair\RepairMimeTypes
  13. */
  14. class RepairInnoDB extends \Test\TestCase {
  15. /** @var \OC\RepairStep */
  16. private $repair;
  17. /** @var \Doctrine\DBAL\Connection */
  18. private $connection;
  19. /** @var string */
  20. private $tableName;
  21. protected function setUp() {
  22. parent::setUp();
  23. $this->connection = \OC_DB::getConnection();
  24. if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
  25. $this->markTestSkipped("Test only relevant on MySql");
  26. }
  27. $dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix");
  28. $this->tableName = $this->getUniqueID($dbPrefix . "_innodb_test");
  29. $this->connection->exec("CREATE TABLE $this->tableName(id INT) ENGINE MyISAM");
  30. $this->repair = new \OC\Repair\InnoDB();
  31. }
  32. protected function tearDown() {
  33. $this->connection->getSchemaManager()->dropTable($this->tableName);
  34. parent::tearDown();
  35. }
  36. public function testInnoDBConvert() {
  37. $result = $this->countMyIsamTables();
  38. $this->assertEquals(1, $result);
  39. $this->repair->run();
  40. $result = $this->countMyIsamTables();
  41. $this->assertEquals(0, $result);
  42. }
  43. /**
  44. * @param $dbName
  45. * @return mixed
  46. */
  47. private function countMyIsamTables() {
  48. $dbName = \OC::$server->getConfig()->getSystemValue("dbname");
  49. $result = $this->connection->fetchColumn(
  50. "SELECT count(*) FROM information_schema.tables WHERE table_schema = ? and table_name = ? AND engine = 'MyISAM'",
  51. array($dbName, $this->tableName)
  52. );
  53. return $result;
  54. }
  55. }