]> git.mxchange.org Git - friendica.git/blob - tests/src/Database/DBStructureTest.php
Merge remote-tracking branch 'upstream/master' into develop
[friendica.git] / tests / src / Database / DBStructureTest.php
1 <?php
2
3 namespace Friendica\Test\Database;
4
5 use Friendica\BaseObject;
6 use Friendica\Core\Config;
7 use Friendica\Database\DBStructure;
8 use Friendica\Test\DatabaseTest;
9
10 class DBStructureTest extends DatabaseTest
11 {
12         public function setUp()
13         {
14                 parent::setUp();
15
16                 // Reusable App object
17                 $this->app = BaseObject::getApp();
18
19                 // Default config
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');
25         }
26
27         /**
28          * @small
29          */
30         public function testExists() {
31                 $this->assertTrue(DBStructure::existsTable('config'));
32
33                 $this->assertFalse(DBStructure::existsTable('notatable'));
34
35                 $this->assertTrue(DBStructure::existsColumn('config', ['k']));
36                 $this->assertFalse(DBStructure::existsColumn('config', ['nonsense']));
37                 $this->assertFalse(DBStructure::existsColumn('config', ['k', 'nonsense']));
38         }
39
40         /**
41          * @small
42          */
43         public function testRename() {
44                 $fromColumn = 'k';
45                 $toColumn = 'key';
46                 $fromType = 'varbinary(255) not null';
47                 $toType = 'varbinary(255) not null comment \'Test To Type\'';
48
49                 $this->assertTrue(DBStructure::rename('config', [ $fromColumn => [ $toColumn, $toType ]]));
50                 $this->assertTrue(DBStructure::existsColumn('config', [ $toColumn ]));
51                 $this->assertFalse(DBStructure::existsColumn('config', [ $fromColumn ]));
52
53                 $this->assertTrue(DBStructure::rename('config', [ $toColumn => [ $fromColumn, $fromType ]]));
54                 $this->assertTrue(DBStructure::existsColumn('config', [ $fromColumn ]));
55                 $this->assertFalse(DBStructure::existsColumn('config', [ $toColumn ]));
56         }
57
58         /**
59          * @small
60          */
61         public function testChangePrimaryKey() {
62                 $oldID = 'client_id';
63                 $newID = 'pw';
64
65                 $this->assertTrue(DBStructure::rename('clients', [ $newID ], DBStructure::RENAME_PRIMARY_KEY));
66                 $this->assertTrue(DBStructure::rename('clients', [ $oldID ], DBStructure::RENAME_PRIMARY_KEY));
67         }
68 }