]> git.mxchange.org Git - friendica.git/blob - tests/src/Database/DBStructureTest.php
Fix tests
[friendica.git] / tests / src / Database / DBStructureTest.php
1 <?php
2
3 namespace Friendica\Test\src\Database;
4
5 use Dice\Dice;
6 use Friendica\BaseObject;
7 use Friendica\Database\DBStructure;
8 use Friendica\Test\DatabaseTest;
9
10 class DBStructureTest extends DatabaseTest
11 {
12         /**
13          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
14          */
15         public function setUp()
16         {
17                 parent::setUp();
18
19                 $dice = new Dice();
20                 $dice = $dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php');
21                 BaseObject::setDependencyInjection($dice);
22         }
23
24         /**
25          * @small
26          */
27         public function testExists() {
28                 $this->assertTrue(DBStructure::existsTable('config'));
29
30                 $this->assertFalse(DBStructure::existsTable('notatable'));
31
32                 $this->assertTrue(DBStructure::existsColumn('config', ['k']));
33                 $this->assertFalse(DBStructure::existsColumn('config', ['nonsense']));
34                 $this->assertFalse(DBStructure::existsColumn('config', ['k', 'nonsense']));
35         }
36
37         /**
38          * @small
39          */
40         public function testRename() {
41                 $fromColumn = 'k';
42                 $toColumn = 'key';
43                 $fromType = 'varbinary(255) not null';
44                 $toType = 'varbinary(255) not null comment \'Test To Type\'';
45
46                 $this->assertTrue(DBStructure::rename('config', [ $fromColumn => [ $toColumn, $toType ]]));
47                 $this->assertTrue(DBStructure::existsColumn('config', [ $toColumn ]));
48                 $this->assertFalse(DBStructure::existsColumn('config', [ $fromColumn ]));
49
50                 $this->assertTrue(DBStructure::rename('config', [ $toColumn => [ $fromColumn, $fromType ]]));
51                 $this->assertTrue(DBStructure::existsColumn('config', [ $fromColumn ]));
52                 $this->assertFalse(DBStructure::existsColumn('config', [ $toColumn ]));
53         }
54
55         /**
56          * @small
57          */
58         public function testChangePrimaryKey() {
59                 $oldID = 'client_id';
60                 $newID = 'pw';
61
62                 $this->assertTrue(DBStructure::rename('clients', [ $newID ], DBStructure::RENAME_PRIMARY_KEY));
63                 $this->assertTrue(DBStructure::rename('clients', [ $oldID ], DBStructure::RENAME_PRIMARY_KEY));
64         }
65 }