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-07-26 09:54:14 -04:00
|
|
|
use Dice\Dice;
|
2019-07-28 11:40:42 -04:00
|
|
|
use Friendica\Database\Database;
|
2018-07-21 08:43:43 -04:00
|
|
|
use Friendica\Database\DBStructure;
|
2019-12-15 17:28:01 -05:00
|
|
|
use Friendica\DI;
|
2018-07-21 08:43:43 -04:00
|
|
|
use Friendica\Test\DatabaseTest;
|
2019-07-28 11:40:42 -04:00
|
|
|
use Friendica\Test\Util\Database\StaticDatabase;
|
2018-07-21 08:43:43 -04:00
|
|
|
|
|
|
|
class DBStructureTest extends DatabaseTest
|
|
|
|
{
|
2019-07-28 11:40:42 -04:00
|
|
|
protected function setUp()
|
2018-07-21 08:43:43 -04:00
|
|
|
{
|
2019-02-05 16:03:07 -05:00
|
|
|
parent::setUp();
|
2019-07-26 09:54:14 -04:00
|
|
|
|
2019-08-05 03:02:55 -04:00
|
|
|
$dice = (new Dice())
|
|
|
|
->addRules(include __DIR__ . '/../../../static/dependencies.config.php')
|
|
|
|
->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]);
|
2019-12-15 17:28:01 -05:00
|
|
|
DI::init($dice);
|
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));
|
|
|
|
}
|
|
|
|
}
|