3 namespace Friendica\Test\Database;
5 use Friendica\BaseObject;
6 use Friendica\Core\Config;
7 use Friendica\Database\DBStructure;
8 use Friendica\Test\DatabaseTest;
10 class DBStructureTest extends DatabaseTest
12 public function setUp()
16 // Reusable App object
17 $this->app = BaseObject::getApp();
20 Config::set('config', 'hostname', 'localhost');
21 Config::set('system', 'throttle_limit_day', 100);
22 Config::set('system', 'throttle_limit_week', 100);
23 Config::set('system', 'throttle_limit_month', 100);
24 Config::set('system', 'theme', 'system_theme');
30 public function testExists() {
31 $this->assertTrue(DBStructure::existsTable('config'));
33 $this->assertFalse(DBStructure::existsTable('notatable'));
35 $this->assertTrue(DBStructure::existsColumn('config', ['k']));
36 $this->assertFalse(DBStructure::existsColumn('config', ['nonsense']));
37 $this->assertFalse(DBStructure::existsColumn('config', ['k', 'nonsense']));
43 public function testRename() {
46 $fromType = 'varbinary(255) not null';
47 $toType = 'varbinary(255) not null comment \'Test To Type\'';
49 $this->assertTrue(DBStructure::rename('config', [ $fromColumn => [ $toColumn, $toType ]]));
50 $this->assertTrue(DBStructure::existsColumn('config', [ $toColumn ]));
51 $this->assertFalse(DBStructure::existsColumn('config', [ $fromColumn ]));
53 $this->assertTrue(DBStructure::rename('config', [ $toColumn => [ $fromColumn, $fromType ]]));
54 $this->assertTrue(DBStructure::existsColumn('config', [ $fromColumn ]));
55 $this->assertFalse(DBStructure::existsColumn('config', [ $toColumn ]));
61 public function testChangePrimaryKey() {
65 $this->assertTrue(DBStructure::rename('clients', [ $newID ], DBStructure::RENAME_PRIMARY_KEY));
66 $this->assertTrue(DBStructure::rename('clients', [ $oldID ], DBStructure::RENAME_PRIMARY_KEY));