2018-07-21 14:43:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Test\Database;
|
|
|
|
|
2019-02-05 22:03:07 +01:00
|
|
|
use Friendica\App;
|
2018-07-21 14:43:43 +02:00
|
|
|
use Friendica\Core\Config;
|
|
|
|
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;
|
2018-07-21 14:43:43 +02:00
|
|
|
|
|
|
|
class DBStructureTest extends DatabaseTest
|
|
|
|
{
|
|
|
|
public function setUp()
|
|
|
|
{
|
2019-02-05 22:03:07 +01:00
|
|
|
$basedir = BasePath::create(dirname(__DIR__) . '/../../');
|
|
|
|
$configLoader = new Config\ConfigCacheLoader($basedir);
|
|
|
|
$config = Factory\ConfigFactory::createCache($configLoader);
|
|
|
|
$logger = Factory\LoggerFactory::create('test', $config);
|
|
|
|
$this->app = new App($config, $logger, false);
|
|
|
|
$this->logOutput = FActory\LoggerFactory::enableTest($this->app->getLogger());
|
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));
|
|
|
|
}
|
|
|
|
}
|