Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.9 KiB

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