repairinnodb.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. * @group DB
  13. *
  14. * @see \OC\Repair\RepairMimeTypes
  15. */
  16. class RepairInnoDB extends \Test\TestCase {
  17. /** @var \OC\RepairStep */
  18. private $repair;
  19. /** @var \Doctrine\DBAL\Connection */
  20. private $connection;
  21. /** @var string */
  22. private $tableName;
  23. protected function setUp() {
  24. parent::setUp();
  25. $this->connection = \OC::$server->getDatabaseConnection();
  26. if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
  27. $this->markTestSkipped("Test only relevant on MySql");
  28. }
  29. $dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix");
  30. $this->tableName = $this->getUniqueID($dbPrefix . "_innodb_test");
  31. $this->connection->exec("CREATE TABLE $this->tableName(id INT) ENGINE MyISAM");
  32. $this->repair = new \OC\Repair\InnoDB();
  33. }
  34. protected function tearDown() {
  35. $this->connection->getSchemaManager()->dropTable($this->tableName);
  36. parent::tearDown();
  37. }
  38. public function testInnoDBConvert() {
  39. $result = $this->countMyIsamTables();
  40. $this->assertEquals(1, $result);
  41. $this->repair->run();
  42. $result = $this->countMyIsamTables();
  43. $this->assertEquals(0, $result);
  44. }
  45. /**
  46. * @param $dbName
  47. * @return mixed
  48. */
  49. private function countMyIsamTables() {
  50. $dbName = \OC::$server->getConfig()->getSystemValue("dbname");
  51. $result = $this->connection->fetchColumn(
  52. "SELECT count(*) FROM information_schema.tables WHERE table_schema = ? and table_name = ? AND engine = 'MyISAM'",
  53. array($dbName, $this->tableName)
  54. );
  55. return $result;
  56. }
  57. }