friendica/tests/src/Database/DBStructureTest.php

72 lines
2.3 KiB
PHP
Raw Normal View History

<?php
2019-02-27 06:32:56 -05:00
namespace Friendica\Test\src\Database;
2019-02-05 16:03:07 -05:00
use Friendica\App;
use Friendica\Database\DBStructure;
2019-02-05 16:03:07 -05:00
use Friendica\Factory;
use Friendica\Test\DatabaseTest;
2019-02-05 16:03:07 -05:00
use Friendica\Util\BasePath;
2019-03-24 07:54:26 -04:00
use Friendica\Util\Config\ConfigFileLoader;
class DBStructureTest extends DatabaseTest
{
public function setUp()
{
$basePath = BasePath::create(dirname(__DIR__) . '/../../');
2019-03-13 21:36:49 -04:00
$mode = new App\Mode($basePath);
2019-03-24 07:54:26 -04:00
$configLoader = new ConfigFileLoader($basePath, $mode);
$configCache = Factory\ConfigFactory::createCache($configLoader);
$profiler = Factory\ProfilerFactory::create($configCache);
Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
$config = Factory\ConfigFactory::createConfig($configCache);
Factory\ConfigFactory::createPConfig($configCache);
2019-02-28 03:41:31 -05:00
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
$this->app = new App($config, $mode, $logger, $profiler, false);
2019-02-05 16:03:07 -05:00
parent::setUp();
}
/**
* @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));
}
}