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.

appconfig.php 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Christopher Schäpers <christopher@schaepers.it>
  4. * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
  5. * This file is licensed under the Affero General Public License version 3 or
  6. * later.
  7. * See the COPYING-README file.
  8. */
  9. class Test_Appconfig extends PHPUnit_Framework_TestCase {
  10. public static function setUpBeforeClass() {
  11. $query = \OC_DB::prepare('INSERT INTO `*PREFIX*appconfig` VALUES (?, ?, ?)');
  12. $query->execute(array('testapp', 'enabled', 'true'));
  13. $query->execute(array('testapp', 'installed_version', '1.2.3'));
  14. $query->execute(array('testapp', 'depends_on', 'someapp'));
  15. $query->execute(array('testapp', 'deletethis', 'deletethis'));
  16. $query->execute(array('testapp', 'key', 'value'));
  17. $query->execute(array('someapp', 'key', 'value'));
  18. $query->execute(array('someapp', 'otherkey', 'othervalue'));
  19. $query->execute(array('123456', 'key', 'value'));
  20. $query->execute(array('123456', 'enabled', 'false'));
  21. $query->execute(array('anotherapp', 'key', 'value'));
  22. $query->execute(array('anotherapp', 'enabled', 'false'));
  23. }
  24. public static function tearDownAfterClass() {
  25. $query = \OC_DB::prepare('DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ?');
  26. $query->execute(array('testapp'));
  27. $query->execute(array('someapp'));
  28. $query->execute(array('123456'));
  29. $query->execute(array('anotherapp'));
  30. }
  31. public function testGetApps() {
  32. $query = \OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*appconfig` ORDER BY `appid`');
  33. $result = $query->execute();
  34. $expected = array();
  35. while ($row = $result->fetchRow()) {
  36. $expected[] = $row['appid'];
  37. }
  38. sort($expected);
  39. $apps = \OC_Appconfig::getApps();
  40. $this->assertEquals($expected, $apps);
  41. }
  42. public function testGetKeys() {
  43. $query = \OC_DB::prepare('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?');
  44. $result = $query->execute(array('testapp'));
  45. $expected = array();
  46. while($row = $result->fetchRow()) {
  47. $expected[] = $row["configkey"];
  48. }
  49. sort($expected);
  50. $keys = \OC_Appconfig::getKeys('testapp');
  51. $this->assertEquals($expected, $keys);
  52. }
  53. public function testGetValue() {
  54. $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
  55. $result = $query->execute(array('testapp', 'installed_version'));
  56. $expected = $result->fetchRow();
  57. $value = \OC_Appconfig::getValue('testapp', 'installed_version');
  58. $this->assertEquals($expected['configvalue'], $value);
  59. $value = \OC_Appconfig::getValue('testapp', 'nonexistant');
  60. $this->assertNull($value);
  61. $value = \OC_Appconfig::getValue('testapp', 'nonexistant', 'default');
  62. $this->assertEquals('default', $value);
  63. }
  64. public function testHasKey() {
  65. $value = \OC_Appconfig::hasKey('testapp', 'installed_version');
  66. $this->assertTrue($value);
  67. $value = \OC_Appconfig::hasKey('nonexistant', 'nonexistant');
  68. $this->assertFalse($value);
  69. }
  70. public function testSetValue() {
  71. \OC_Appconfig::setValue('testapp', 'installed_version', '1.33.7');
  72. $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
  73. $result = $query->execute(array('testapp', 'installed_version'));
  74. $value = $result->fetchRow();
  75. $this->assertEquals('1.33.7', $value['configvalue']);
  76. \OC_Appconfig::setValue('someapp', 'somekey', 'somevalue');
  77. $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
  78. $result = $query->execute(array('someapp', 'somekey'));
  79. $value = $result->fetchRow();
  80. $this->assertEquals('somevalue', $value['configvalue']);
  81. }
  82. public function testDeleteKey() {
  83. \OC_Appconfig::deleteKey('testapp', 'deletethis');
  84. $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
  85. $query->execute(array('testapp', 'deletethis'));
  86. $result = (bool)$query->fetchRow();
  87. $this->assertFalse($result);
  88. }
  89. public function testDeleteApp() {
  90. \OC_Appconfig::deleteApp('someapp');
  91. $query = \OC_DB::prepare('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?');
  92. $query->execute(array('someapp'));
  93. $result = (bool)$query->fetchRow();
  94. $this->assertFalse($result);
  95. }
  96. public function testGetValues() {
  97. $this->assertFalse(\OC_Appconfig::getValues('testapp', 'enabled'));
  98. $query = \OC_DB::prepare('SELECT `configkey`, `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ?');
  99. $query->execute(array('testapp'));
  100. $expected = array();
  101. while ($row = $query->fetchRow()) {
  102. $expected[$row['configkey']] = $row['configvalue'];
  103. }
  104. $values = \OC_Appconfig::getValues('testapp', false);
  105. $this->assertEquals($expected, $values);
  106. $query = \OC_DB::prepare('SELECT `appid`, `configvalue` FROM `*PREFIX*appconfig` WHERE `configkey` = ?');
  107. $query->execute(array('enabled'));
  108. $expected = array();
  109. while ($row = $query->fetchRow()) {
  110. $expected[$row['appid']] = $row['configvalue'];
  111. }
  112. $values = \OC_Appconfig::getValues(false, 'enabled');
  113. $this->assertEquals($expected, $values);
  114. }
  115. }