3 namespace Friendica\Test\src\Database;
6 use Friendica\Core\Config\Cache;
7 use Friendica\Database\DBStructure;
9 use Friendica\Test\DatabaseTest;
10 use Friendica\Util\BasePath;
12 class DBStructureTest extends DatabaseTest
14 public function setUp()
16 $basePath = BasePath::create(dirname(__DIR__) . '/../../');
17 $configLoader = new Cache\ConfigCacheLoader($basePath);
18 $configCache = Factory\ConfigFactory::createCache($configLoader);
19 $profiler = Factory\ProfilerFactory::create($configCache);
20 Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
21 $config = Factory\ConfigFactory::createConfig($configCache);
22 Factory\ConfigFactory::createPConfig($configCache);
23 $logger = Factory\LoggerFactory::create('test', $config);
24 $this->app = new App($basePath, $config, $logger, $profiler, false);
32 public function testExists() {
33 $this->assertTrue(DBStructure::existsTable('config'));
35 $this->assertFalse(DBStructure::existsTable('notatable'));
37 $this->assertTrue(DBStructure::existsColumn('config', ['k']));
38 $this->assertFalse(DBStructure::existsColumn('config', ['nonsense']));
39 $this->assertFalse(DBStructure::existsColumn('config', ['k', 'nonsense']));
45 public function testRename() {
48 $fromType = 'varbinary(255) not null';
49 $toType = 'varbinary(255) not null comment \'Test To Type\'';
51 $this->assertTrue(DBStructure::rename('config', [ $fromColumn => [ $toColumn, $toType ]]));
52 $this->assertTrue(DBStructure::existsColumn('config', [ $toColumn ]));
53 $this->assertFalse(DBStructure::existsColumn('config', [ $fromColumn ]));
55 $this->assertTrue(DBStructure::rename('config', [ $toColumn => [ $fromColumn, $fromType ]]));
56 $this->assertTrue(DBStructure::existsColumn('config', [ $fromColumn ]));
57 $this->assertFalse(DBStructure::existsColumn('config', [ $toColumn ]));
63 public function testChangePrimaryKey() {
67 $this->assertTrue(DBStructure::rename('clients', [ $newID ], DBStructure::RENAME_PRIMARY_KEY));
68 $this->assertTrue(DBStructure::rename('clients', [ $oldID ], DBStructure::RENAME_PRIMARY_KEY));