2018-07-21 14:43:43 +02:00
|
|
|
<?php
|
|
|
|
|
2019-02-27 12:32:56 +01:00
|
|
|
namespace Friendica\Test\src\Database;
|
2018-07-21 14:43:43 +02:00
|
|
|
|
2019-02-05 22:03:07 +01:00
|
|
|
use Friendica\App;
|
2018-07-21 14:43:43 +02:00
|
|
|
use Friendica\Database\DBStructure;
|
2019-02-05 22:03:07 +01:00
|
|
|
use Friendica\Factory;
|
2018-07-21 14:43:43 +02:00
|
|
|
use Friendica\Test\DatabaseTest;
|
2019-02-05 22:03:07 +01:00
|
|
|
use Friendica\Util\BasePath;
|
2019-04-08 23:12:34 +02:00
|
|
|
use Friendica\Util\BaseURL;
|
2019-03-24 12:54:26 +01:00
|
|
|
use Friendica\Util\Config\ConfigFileLoader;
|
2018-07-21 14:43:43 +02:00
|
|
|
|
|
|
|
class DBStructureTest extends DatabaseTest
|
|
|
|
{
|
|
|
|
public function setUp()
|
|
|
|
{
|
2019-02-22 23:51:13 +01:00
|
|
|
$basePath = BasePath::create(dirname(__DIR__) . '/../../');
|
2019-03-14 02:36:49 +01:00
|
|
|
$mode = new App\Mode($basePath);
|
2019-04-06 05:16:12 +02:00
|
|
|
$router = new App\Router();
|
2019-03-24 12:54:26 +01:00
|
|
|
$configLoader = new ConfigFileLoader($basePath, $mode);
|
2019-02-10 19:52:21 +01:00
|
|
|
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
2019-02-17 21:12:12 +01:00
|
|
|
$profiler = Factory\ProfilerFactory::create($configCache);
|
2019-06-07 00:10:45 +02:00
|
|
|
$database = Factory\DBFactory::init($configCache, $profiler, $_SERVER);
|
2019-02-10 19:52:21 +01:00
|
|
|
$config = Factory\ConfigFactory::createConfig($configCache);
|
2019-02-17 21:12:12 +01:00
|
|
|
Factory\ConfigFactory::createPConfig($configCache);
|
2019-06-07 00:10:45 +02:00
|
|
|
$logger = Factory\LoggerFactory::create('test', $database, $config, $profiler);
|
2019-04-08 23:12:34 +02:00
|
|
|
$baseUrl = new BaseURL($config, $_SERVER);
|
2019-06-07 00:10:45 +02:00
|
|
|
$this->app = new App($database, $config, $mode, $router, $baseUrl, $logger, $profiler, false);
|
2018-07-21 14:43:43 +02:00
|
|
|
|
2019-02-05 22:03:07 +01:00
|
|
|
parent::setUp();
|
2018-07-21 14:43:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
|
|
|
*/
|
|
|
|
public function testExists() {
|
|
|
|
$this->assertTrue(DBStructure::existsTable('config'));
|
|
|
|
|
|
|
|
$this->assertFalse(DBStructure::existsTable('notatable'));
|
|
|
|
|
|
|
|
$this->assertTrue(DBStructure::existsColumn('config', ['k']));
|
|
|
|
$this->assertFalse(DBStructure::existsColumn('config', ['nonsense']));
|
|
|
|
$this->assertFalse(DBStructure::existsColumn('config', ['k', 'nonsense']));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
|
|
|
*/
|
|
|
|
public function testRename() {
|
|
|
|
$fromColumn = 'k';
|
|
|
|
$toColumn = 'key';
|
|
|
|
$fromType = 'varbinary(255) not null';
|
|
|
|
$toType = 'varbinary(255) not null comment \'Test To Type\'';
|
|
|
|
|
|
|
|
$this->assertTrue(DBStructure::rename('config', [ $fromColumn => [ $toColumn, $toType ]]));
|
|
|
|
$this->assertTrue(DBStructure::existsColumn('config', [ $toColumn ]));
|
|
|
|
$this->assertFalse(DBStructure::existsColumn('config', [ $fromColumn ]));
|
|
|
|
|
|
|
|
$this->assertTrue(DBStructure::rename('config', [ $toColumn => [ $fromColumn, $fromType ]]));
|
|
|
|
$this->assertTrue(DBStructure::existsColumn('config', [ $fromColumn ]));
|
|
|
|
$this->assertFalse(DBStructure::existsColumn('config', [ $toColumn ]));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
|
|
|
*/
|
|
|
|
public function testChangePrimaryKey() {
|
|
|
|
$oldID = 'client_id';
|
|
|
|
$newID = 'pw';
|
|
|
|
|
|
|
|
$this->assertTrue(DBStructure::rename('clients', [ $newID ], DBStructure::RENAME_PRIMARY_KEY));
|
|
|
|
$this->assertTrue(DBStructure::rename('clients', [ $oldID ], DBStructure::RENAME_PRIMARY_KEY));
|
|
|
|
}
|
|
|
|
}
|