PageRenderTime 51ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/tests/Core/Config/DatabaseLoaderTest.php

http://github.com/concrete5/concrete5
PHP | 125 lines | 98 code | 25 blank | 2 comment | 0 complexity | c26c10015394926b18f4b9238dab69df MD5 | raw file
Possible License(s): MIT, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. <?php
  2. use Concrete\Core\Config\DatabaseLoader;
  3. class DatabaseLoaderTest extends ConcreteDatabaseTestCase
  4. {
  5. /** @var DatabaseLoader */
  6. protected $loader;
  7. protected $tables = array('Config');
  8. protected $fixtures = array();
  9. public function setUp()
  10. {
  11. parent::setUp();
  12. $this->loader = new DatabaseLoader();
  13. }
  14. public function testLoadingConfig()
  15. {
  16. \Core::make('config/database')->save('test.test.test', $string = uniqid());
  17. $array = $this->loader->load('test', 'test');
  18. $this->assertEquals($string, array_get($array, 'test.test'), 'Failed to read config value from the database.');
  19. }
  20. public function testLoadingLegacyConfig()
  21. {
  22. \Database::query('ALTER TABLE Config DROP PRIMARY KEY');
  23. \Database::query('ALTER TABLE Config MODIFY COLUMN configNamespace VARCHAR (255)');
  24. \Database::insert(
  25. 'Config',
  26. array(
  27. 'configItem' => 'test',
  28. 'configValue' => $value = uniqid(),
  29. 'configGroup' => 'testing',
  30. 'configNamespace' => null,
  31. ));
  32. $array = $this->loader->load('test', 'testing');
  33. $this->assertEquals($value, array_get($array, 'test'));
  34. }
  35. public function testLoadingNamespacedConfig()
  36. {
  37. \Core::make('config/database')->save('namespaced::namespaced.namespaced.namespaced', $value = uniqid());
  38. $array = $this->loader->load('namespaced', 'namespaced', 'namespaced');
  39. $this->assertEquals(
  40. $value,
  41. array_get($array, 'namespaced.namespaced'),
  42. 'Failed to read namespaced config value from the database.');
  43. }
  44. public function testExists()
  45. {
  46. $group = md5(time());
  47. $exists_before = $this->loader->exists($group);
  48. $db = \Database::getActiveConnection();
  49. $db->insert(
  50. 'Config',
  51. array(
  52. 'configItem' => $group,
  53. 'configValue' => 1,
  54. 'configGroup' => $group,
  55. 'configNamespace' => '', ));
  56. $exists_after = $this->loader->exists($group);
  57. $this->assertFalse($exists_before);
  58. $this->assertTrue($exists_after);
  59. }
  60. public function testExistsNamespaced()
  61. {
  62. $group = md5(uniqid());
  63. $namespace = md5(uniqid());
  64. $exists_before = $this->loader->exists($group, $namespace);
  65. $db = \Database::getActiveConnection();
  66. $db->insert(
  67. 'Config',
  68. array(
  69. 'configItem' => $group,
  70. 'configValue' => 1,
  71. 'configGroup' => $group,
  72. 'configNamespace' => $namespace, ));
  73. $exists_after = $this->loader->exists($group, $namespace);
  74. $this->assertFalse($exists_before);
  75. $this->assertTrue($exists_after);
  76. }
  77. public function testAddNamespace()
  78. {
  79. // Satisfy coverage
  80. $this->loader->addNamespace('', '');
  81. $this->assertTrue(true);
  82. }
  83. public function testGetNamespaces()
  84. {
  85. $namespaces_first = $this->loader->getNamespaces();
  86. $namespace = md5(uniqid());
  87. $db = \Database::getActiveConnection();
  88. $db->insert(
  89. 'Config',
  90. array(
  91. 'configItem' => $namespace,
  92. 'configValue' => 1,
  93. 'configGroup' => 'test',
  94. 'configNamespace' => $namespace, ));
  95. $namespaces_after = $this->loader->getNamespaces();
  96. $diff = array_diff($namespaces_after, $namespaces_first);
  97. $value = array_shift($diff);
  98. $this->assertEquals($namespace, $value);
  99. }
  100. }