You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RepairCollationTest.php 2.4KB

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