1
0

RepairCollationTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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\Migration\IOutput;
  13. use Psr\Log\LoggerInterface;
  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 LoggerInterface */
  49. private $logger;
  50. protected function setUp(): void {
  51. parent::setUp();
  52. $this->connection = \OC::$server->get(IDBConnection::class);
  53. $this->logger = $this->createMock(LoggerInterface::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->getSystemValueString("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. }