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;
|
2019-07-12 22:38:50 +02:00
|
|
|
use Friendica\Core\Config\Cache\PConfigCache;
|
2019-07-09 21:44:02 +02:00
|
|
|
use Friendica\Core\L10n\L10n;
|
2018-07-21 14:43:43 +02:00
|
|
|
use Friendica\Database\DBStructure;
|
2019-02-05 22:03:07 +01:00
|
|
|
use Friendica\Factory;
|
2019-07-14 22:19:16 +02:00
|
|
|
use Friendica\Model\Config\Config;
|
2018-07-21 14:43:43 +02:00
|
|
|
use Friendica\Test\DatabaseTest;
|
2019-04-08 23:12:34 +02:00
|
|
|
use Friendica\Util\BaseURL;
|
2018-07-21 14:43:43 +02:00
|
|
|
|
|
|
|
class DBStructureTest extends DatabaseTest
|
|
|
|
{
|
2019-07-14 22:19:16 +02:00
|
|
|
/**
|
|
|
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
|
|
|
*/
|
2018-07-21 14:43:43 +02:00
|
|
|
public function setUp()
|
|
|
|
{
|
2019-07-14 22:19:16 +02:00
|
|
|
$configModel = new Config(self::$dba);
|
2019-07-21 14:20:45 +02:00
|
|
|
$configFactory = new Factory\ConfigFactory();
|
|
|
|
$config = $configFactory->createConfig(self::$configCache, $configModel);
|
2019-07-15 20:13:53 +02:00
|
|
|
$pconfigModel = new \Friendica\Model\Config\PConfig(self::$dba);
|
2019-07-21 14:20:45 +02:00
|
|
|
$configFactory->createPConfig(self::$configCache, new PConfigCache(), $pconfigModel);
|
|
|
|
$loggerFactory = new Factory\LoggerFactory();
|
|
|
|
$logger = $loggerFactory->create('test', self::$dba, $config, self::$profiler);
|
2019-04-08 23:12:34 +02:00
|
|
|
$baseUrl = new BaseURL($config, $_SERVER);
|
2019-07-04 21:39:49 +02:00
|
|
|
$router = new App\Router();
|
2019-07-21 01:22:10 +02:00
|
|
|
$l10n = new L10n($config,
|
2019-07-09 21:44:02 +02:00
|
|
|
self::$dba,
|
|
|
|
$logger);
|
|
|
|
$this->app = new App(self::$dba, $config, self::$mode, $router, $baseUrl, $logger, self::$profiler, $l10n, false);
|
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));
|
|
|
|
}
|
|
|
|
}
|