PageRenderTime 47ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/Cake/Test/Case/Configure/PhpReaderTest.php

https://bitbucket.org/udeshika/fake_twitter
PHP | 98 lines | 40 code | 8 blank | 50 comment | 0 complexity | 93103f816def35312ae9ef23dd82997d MD5 | raw file
  1. <?php
  2. /**
  3. * PhpConfigReaderTest
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
  8. * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice
  12. *
  13. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
  15. * @package Cake.Test.Case.Configure
  16. * @since CakePHP(tm) v 2.0
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('PhpReader', 'Configure');
  20. class PhpReaderTest extends CakeTestCase {
  21. /**
  22. * setup
  23. *
  24. * @return void
  25. */
  26. public function setUp() {
  27. parent::setUp();
  28. $this->path = CAKE . 'Test' . DS . 'test_app' . DS . 'Config'. DS;
  29. }
  30. /**
  31. * test reading files
  32. *
  33. * @return void
  34. */
  35. public function testRead() {
  36. $reader = new PhpReader($this->path);
  37. $values = $reader->read('var_test');
  38. $this->assertEquals('value', $values['Read']);
  39. $this->assertEquals('buried', $values['Deep']['Deeper']['Deepest']);
  40. $values = $reader->read('var_test.php');
  41. $this->assertEquals('value', $values['Read']);
  42. }
  43. /**
  44. * Test an exception is thrown by reading files that don't exist.
  45. *
  46. * @expectedException ConfigureException
  47. * @return void
  48. */
  49. public function testReadWithNonExistantFile() {
  50. $reader = new PhpReader($this->path);
  51. $reader->read('fake_values');
  52. }
  53. /**
  54. * test reading an empty file.
  55. *
  56. * @expectedException RuntimeException
  57. * @return void
  58. */
  59. public function testReadEmptyFile() {
  60. $reader = new PhpReader($this->path);
  61. $reader->read('empty');
  62. }
  63. /**
  64. * test reading keys with ../ doesn't work
  65. *
  66. * @expectedException ConfigureException
  67. * @return void
  68. */
  69. public function testReadWithDots() {
  70. $reader = new PhpReader($this->path);
  71. $reader->read('../empty');
  72. }
  73. /**
  74. * test reading from plugins
  75. *
  76. * @return void
  77. */
  78. public function testReadPluginValue() {
  79. App::build(array(
  80. 'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
  81. ), true);
  82. CakePlugin::load('TestPlugin');
  83. $reader = new PhpReader($this->path);
  84. $result = $reader->read('TestPlugin.load');
  85. $this->assertTrue(isset($result['plugin_load']));
  86. $result = $reader->read('TestPlugin.load.php');
  87. $this->assertTrue(isset($result['plugin_load']));
  88. CakePlugin::unload();
  89. }
  90. }