2018-07-21 08:43:43 -04:00
|
|
|
<?php
|
|
|
|
|
2019-02-27 06:32:56 -05:00
|
|
|
namespace Friendica\Test\src\Database;
|
2018-07-21 08:43:43 -04:00
|
|
|
|
2019-02-05 16:03:07 -05:00
|
|
|
use Friendica\App;
|
2019-07-12 16:38:50 -04:00
|
|
|
use Friendica\Core\Config\Cache\PConfigCache;
|
2018-07-21 08:43:43 -04:00
|
|
|
use Friendica\Database\DBStructure;
|
2019-02-05 16:03:07 -05:00
|
|
|
use Friendica\Factory;
|
2018-07-21 08:43:43 -04:00
|
|
|
use Friendica\Test\DatabaseTest;
|
2019-04-08 17:12:34 -04:00
|
|
|
use Friendica\Util\BaseURL;
|
2018-07-21 08:43:43 -04:00
|
|
|
|
|
|
|
class DBStructureTest extends DatabaseTest
|
|
|
|
{
|
|
|
|
public function setUp()
|
|
|
|
{
|
2019-07-04 15:39:49 -04:00
|
|
|
$configModel = new \Friendica\Model\Config\Config(self::$dba);
|
|
|
|
$config = Factory\ConfigFactory::createConfig(self::$configCache, $configModel);
|
|
|
|
Factory\ConfigFactory::createPConfig(new PConfigCache());
|
|
|
|
$logger = Factory\LoggerFactory::create('test', self::$dba, $config, self::$profiler);
|
2019-04-08 17:12:34 -04:00
|
|
|
$baseUrl = new BaseURL($config, $_SERVER);
|
2019-07-04 15:39:49 -04:00
|
|
|
$router = new App\Router();
|
|
|
|
$this->app = new App(self::$dba, $config, self::$mode, $router, $baseUrl, $logger, self::$profiler, false);
|
2018-07-21 08:43:43 -04:00
|
|
|
|
2019-02-05 16:03:07 -05:00
|
|
|
parent::setUp();
|
2018-07-21 08:43:43 -04: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));
|
|
|
|
}
|
|
|
|
}
|