2014-07-07 15:37:35 +00: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 14:09:48 +00:00
|
|
|
namespace Test\Repair;
|
|
|
|
|
2017-02-10 15:20:25 +00:00
|
|
|
use Doctrine\DBAL\Connection;
|
|
|
|
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
|
|
|
use OC\Repair\Collation;
|
|
|
|
use OCP\IDBConnection;
|
2016-10-18 14:09:48 +00:00
|
|
|
use OCP\ILogger;
|
|
|
|
use OCP\Migration\IOutput;
|
2017-02-10 15:20:25 +00:00
|
|
|
use Test\TestCase;
|
2016-10-18 14:09:48 +00:00
|
|
|
|
2017-02-10 15:20:25 +00:00
|
|
|
class TestCollationRepair extends Collation {
|
2014-07-07 15:37:35 +00:00
|
|
|
/**
|
2017-03-20 08:29:30 +00:00
|
|
|
* @param IDBConnection $connection
|
2014-07-07 15:37:35 +00:00
|
|
|
* @return string[]
|
|
|
|
*/
|
2017-03-20 08:29:30 +00:00
|
|
|
public function getAllNonUTF8BinTables(IDBConnection $connection) {
|
2014-07-07 15:37:35 +00:00
|
|
|
return parent::getAllNonUTF8BinTables($connection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for the converting of MySQL tables to InnoDB engine
|
|
|
|
*
|
2015-11-03 00:52:41 +00:00
|
|
|
* @group DB
|
|
|
|
*
|
2014-07-07 15:37:35 +00:00
|
|
|
* @see \OC\Repair\RepairMimeTypes
|
|
|
|
*/
|
2017-02-10 15:20:25 +00:00
|
|
|
class RepairCollationTest extends TestCase {
|
2014-07-07 15:37:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var TestCollationRepair
|
|
|
|
*/
|
|
|
|
private $repair;
|
|
|
|
|
|
|
|
/**
|
2017-02-10 15:20:25 +00:00
|
|
|
* @var Connection|IDBConnection
|
2014-07-07 15:37:35 +00:00
|
|
|
*/
|
|
|
|
private $connection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $tableName;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OCP\IConfig
|
|
|
|
*/
|
|
|
|
private $config;
|
|
|
|
|
2016-10-18 14:09:48 +00:00
|
|
|
/** @var ILogger */
|
|
|
|
private $logger;
|
|
|
|
|
2014-11-10 22:30:38 +00:00
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
2016-01-07 09:26:00 +00:00
|
|
|
$this->connection = \OC::$server->getDatabaseConnection();
|
2016-10-18 14:09:48 +00:00
|
|
|
$this->logger = $this->createMock(ILogger::class);
|
2014-07-07 15:37:35 +00:00
|
|
|
$this->config = \OC::$server->getConfig();
|
2017-02-10 15:20:25 +00:00
|
|
|
if (!$this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
|
2014-07-07 15:37:35 +00:00
|
|
|
$this->markTestSkipped("Test only relevant on MySql");
|
|
|
|
}
|
|
|
|
|
|
|
|
$dbPrefix = $this->config->getSystemValue("dbtableprefix");
|
2014-12-02 12:51:36 +00:00
|
|
|
$this->tableName = $this->getUniqueID($dbPrefix . "_collation_test");
|
2014-07-07 15:37:35 +00:00
|
|
|
$this->connection->exec("CREATE TABLE $this->tableName(text VARCHAR(16)) COLLATE utf8_unicode_ci");
|
|
|
|
|
2016-10-18 14:09:48 +00:00
|
|
|
$this->repair = new TestCollationRepair($this->config, $this->logger, $this->connection, false);
|
2014-07-07 15:37:35 +00:00
|
|
|
}
|
|
|
|
|
2014-11-10 22:30:38 +00:00
|
|
|
protected function tearDown() {
|
2014-07-07 15:37:35 +00:00
|
|
|
$this->connection->getSchemaManager()->dropTable($this->tableName);
|
2014-11-10 22:30:38 +00:00
|
|
|
parent::tearDown();
|
2014-07-07 15:37:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCollationConvert() {
|
|
|
|
$tables = $this->repair->getAllNonUTF8BinTables($this->connection);
|
|
|
|
$this->assertGreaterThanOrEqual(1, count($tables));
|
|
|
|
|
2016-04-22 13:35:39 +00:00
|
|
|
/** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
|
|
|
|
$outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$this->repair->run($outputMock);
|
2014-07-07 15:37:35 +00:00
|
|
|
|
|
|
|
$tables = $this->repair->getAllNonUTF8BinTables($this->connection);
|
|
|
|
$this->assertCount(0, $tables);
|
|
|
|
}
|
|
|
|
}
|