2014-07-07 19:37:35 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
2016-10-18 17:09:48 +03:00
|
|
|
namespace Test\Repair;
|
|
|
|
|
2017-02-10 18:20:25 +03:00
|
|
|
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
|
|
|
use OC\Repair\Collation;
|
|
|
|
use OCP\IDBConnection;
|
2016-10-18 17:09:48 +03:00
|
|
|
use OCP\ILogger;
|
|
|
|
use OCP\Migration\IOutput;
|
2017-02-10 18:20:25 +03:00
|
|
|
use Test\TestCase;
|
2016-10-18 17:09:48 +03:00
|
|
|
|
2017-02-10 18:20:25 +03:00
|
|
|
class TestCollationRepair extends Collation {
|
2014-07-07 19:37:35 +04:00
|
|
|
/**
|
2017-03-20 11:29:30 +03:00
|
|
|
* @param IDBConnection $connection
|
2014-07-07 19:37:35 +04:00
|
|
|
* @return string[]
|
|
|
|
*/
|
2017-03-20 11:29:30 +03:00
|
|
|
public function getAllNonUTF8BinTables(IDBConnection $connection) {
|
2014-07-07 19:37:35 +04:00
|
|
|
return parent::getAllNonUTF8BinTables($connection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for the converting of MySQL tables to InnoDB engine
|
|
|
|
*
|
2015-11-03 03:52:41 +03:00
|
|
|
* @group DB
|
|
|
|
*
|
2014-07-07 19:37:35 +04:00
|
|
|
* @see \OC\Repair\RepairMimeTypes
|
|
|
|
*/
|
2017-02-10 18:20:25 +03:00
|
|
|
class RepairCollationTest extends TestCase {
|
2014-07-07 19:37:35 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var TestCollationRepair
|
|
|
|
*/
|
|
|
|
private $repair;
|
|
|
|
|
|
|
|
/**
|
2021-01-03 17:28:31 +03:00
|
|
|
* @var IDBConnection
|
2014-07-07 19:37:35 +04:00
|
|
|
*/
|
|
|
|
private $connection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $tableName;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OCP\IConfig
|
|
|
|
*/
|
|
|
|
private $config;
|
|
|
|
|
2016-10-18 17:09:48 +03:00
|
|
|
/** @var ILogger */
|
|
|
|
private $logger;
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2014-11-11 01:30:38 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2021-01-03 17:28:31 +03:00
|
|
|
$this->connection = \OC::$server->get(IDBConnection::class);
|
2016-10-18 17:09:48 +03:00
|
|
|
$this->logger = $this->createMock(ILogger::class);
|
2014-07-07 19:37:35 +04:00
|
|
|
$this->config = \OC::$server->getConfig();
|
2017-02-10 18:20:25 +03:00
|
|
|
if (!$this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
|
2014-07-07 19:37:35 +04:00
|
|
|
$this->markTestSkipped("Test only relevant on MySql");
|
|
|
|
}
|
|
|
|
|
|
|
|
$dbPrefix = $this->config->getSystemValue("dbtableprefix");
|
2014-12-02 15:51:36 +03:00
|
|
|
$this->tableName = $this->getUniqueID($dbPrefix . "_collation_test");
|
2021-01-03 17:28:31 +03:00
|
|
|
$this->connection->prepare("CREATE TABLE $this->tableName(text VARCHAR(16)) COLLATE utf8_unicode_ci")->execute();
|
2014-07-07 19:37:35 +04:00
|
|
|
|
2016-10-18 17:09:48 +03:00
|
|
|
$this->repair = new TestCollationRepair($this->config, $this->logger, $this->connection, false);
|
2014-07-07 19:37:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function tearDown(): void {
|
2021-01-03 17:28:31 +03:00
|
|
|
$this->connection->getInner()->getSchemaManager()->dropTable($this->tableName);
|
2014-11-11 01:30:38 +03:00
|
|
|
parent::tearDown();
|
2014-07-07 19:37:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCollationConvert() {
|
|
|
|
$tables = $this->repair->getAllNonUTF8BinTables($this->connection);
|
|
|
|
$this->assertGreaterThanOrEqual(1, count($tables));
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IOutput | \PHPUnit\Framework\MockObject\MockObject $outputMock */
|
2016-04-22 16:35:39 +03:00
|
|
|
$outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$this->repair->run($outputMock);
|
2014-07-07 19:37:35 +04:00
|
|
|
|
|
|
|
$tables = $this->repair->getAllNonUTF8BinTables($this->connection);
|
|
|
|
$this->assertCount(0, $tables);
|
|
|
|
}
|
|
|
|
}
|