repaircollation.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. * @see \OC\Repair\RepairMimeTypes
  21. */
  22. class TestRepairCollation extends \Test\TestCase {
  23. /**
  24. * @var TestCollationRepair
  25. */
  26. private $repair;
  27. /**
  28. * @var \Doctrine\DBAL\Connection
  29. */
  30. private $connection;
  31. /**
  32. * @var string
  33. */
  34. private $tableName;
  35. /**
  36. * @var \OCP\IConfig
  37. */
  38. private $config;
  39. protected function setUp() {
  40. parent::setUp();
  41. $this->connection = \OC_DB::getConnection();
  42. $this->config = \OC::$server->getConfig();
  43. if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
  44. $this->markTestSkipped("Test only relevant on MySql");
  45. }
  46. $dbPrefix = $this->config->getSystemValue("dbtableprefix");
  47. $this->tableName = $this->getUniqueID($dbPrefix . "_collation_test");
  48. $this->connection->exec("CREATE TABLE $this->tableName(text VARCHAR(16)) COLLATE utf8_unicode_ci");
  49. $this->repair = new TestCollationRepair($this->config, $this->connection);
  50. }
  51. protected function tearDown() {
  52. $this->connection->getSchemaManager()->dropTable($this->tableName);
  53. parent::tearDown();
  54. }
  55. public function testCollationConvert() {
  56. $tables = $this->repair->getAllNonUTF8BinTables($this->connection);
  57. $this->assertGreaterThanOrEqual(1, count($tables));
  58. $this->repair->run();
  59. $tables = $this->repair->getAllNonUTF8BinTables($this->connection);
  60. $this->assertCount(0, $tables);
  61. }
  62. }