RepairCollationTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. use Doctrine\DBAL\Platforms\MySqlPlatform;
  10. use OC\Repair\Collation;
  11. use OCP\IDBConnection;
  12. use OCP\ILogger;
  13. use OCP\Migration\IOutput;
  14. use Test\TestCase;
  15. class TestCollationRepair extends Collation {
  16. /**
  17. * @param IDBConnection $connection
  18. * @return string[]
  19. */
  20. public function getAllNonUTF8BinTables(IDBConnection $connection) {
  21. return parent::getAllNonUTF8BinTables($connection);
  22. }
  23. }
  24. /**
  25. * Tests for the converting of MySQL tables to InnoDB engine
  26. *
  27. * @group DB
  28. *
  29. * @see \OC\Repair\RepairMimeTypes
  30. */
  31. class RepairCollationTest extends TestCase {
  32. /**
  33. * @var TestCollationRepair
  34. */
  35. private $repair;
  36. /**
  37. * @var IDBConnection
  38. */
  39. private $connection;
  40. /**
  41. * @var string
  42. */
  43. private $tableName;
  44. /**
  45. * @var \OCP\IConfig
  46. */
  47. private $config;
  48. /** @var ILogger */
  49. private $logger;
  50. protected function setUp(): void {
  51. parent::setUp();
  52. $this->connection = \OC::$server->get(IDBConnection::class);
  53. $this->logger = $this->createMock(ILogger::class);
  54. $this->config = \OC::$server->getConfig();
  55. if (!$this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
  56. $this->markTestSkipped("Test only relevant on MySql");
  57. }
  58. $dbPrefix = $this->config->getSystemValue("dbtableprefix");
  59. $this->tableName = $this->getUniqueID($dbPrefix . "_collation_test");
  60. $this->connection->prepare("CREATE TABLE $this->tableName(text VARCHAR(16)) COLLATE utf8_unicode_ci")->execute();
  61. $this->repair = new TestCollationRepair($this->config, $this->logger, $this->connection, false);
  62. }
  63. protected function tearDown(): void {
  64. $this->connection->getInner()->getSchemaManager()->dropTable($this->tableName);
  65. parent::tearDown();
  66. }
  67. public function testCollationConvert() {
  68. $tables = $this->repair->getAllNonUTF8BinTables($this->connection);
  69. $this->assertGreaterThanOrEqual(1, count($tables));
  70. /** @var IOutput | \PHPUnit\Framework\MockObject\MockObject $outputMock */
  71. $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
  72. ->disableOriginalConstructor()
  73. ->getMock();
  74. $this->repair->run($outputMock);
  75. $tables = $this->repair->getAllNonUTF8BinTables($this->connection);
  76. $this->assertCount(0, $tables);
  77. }
  78. }