repaircollation.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. class TestCollationRepair extends \OC\Repair\Collation {
  9. /**
  10. * @param \Doctrine\DBAL\Connection $connection
  11. * @return string[]
  12. */
  13. public function getAllNonUTF8BinTables($connection) {
  14. return parent::getAllNonUTF8BinTables($connection);
  15. }
  16. }
  17. /**
  18. * Tests for the converting of MySQL tables to InnoDB engine
  19. *
  20. * @group DB
  21. *
  22. * @see \OC\Repair\RepairMimeTypes
  23. */
  24. class TestRepairCollation extends \Test\TestCase {
  25. /**
  26. * @var TestCollationRepair
  27. */
  28. private $repair;
  29. /**
  30. * @var \Doctrine\DBAL\Connection
  31. */
  32. private $connection;
  33. /**
  34. * @var string
  35. */
  36. private $tableName;
  37. /**
  38. * @var \OCP\IConfig
  39. */
  40. private $config;
  41. protected function setUp() {
  42. parent::setUp();
  43. $this->connection = \OC::$server->getDatabaseConnection();
  44. $this->config = \OC::$server->getConfig();
  45. if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
  46. $this->markTestSkipped("Test only relevant on MySql");
  47. }
  48. $dbPrefix = $this->config->getSystemValue("dbtableprefix");
  49. $this->tableName = $this->getUniqueID($dbPrefix . "_collation_test");
  50. $this->connection->exec("CREATE TABLE $this->tableName(text VARCHAR(16)) COLLATE utf8_unicode_ci");
  51. $this->repair = new TestCollationRepair($this->config, $this->connection);
  52. }
  53. protected function tearDown() {
  54. $this->connection->getSchemaManager()->dropTable($this->tableName);
  55. parent::tearDown();
  56. }
  57. public function testCollationConvert() {
  58. $tables = $this->repair->getAllNonUTF8BinTables($this->connection);
  59. $this->assertGreaterThanOrEqual(1, count($tables));
  60. $this->repair->run();
  61. $tables = $this->repair->getAllNonUTF8BinTables($this->connection);
  62. $this->assertCount(0, $tables);
  63. }
  64. }