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.

125 lines
3.2 KiB

13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
  1. <?php
  2. /*
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage UnitTests
  7. * @since 2011-10-..
  8. *
  9. * Unit tests for Load class
  10. */
  11. require dirname(__FILE__) . '/../Load.php';
  12. class LoadTest extends PHPUnit_Framework_TestCase
  13. {
  14. private static $inc_dirs = array();
  15. private static $file;
  16. /**
  17. * @TODO: Load->buildAutoload() - uses two paths - PATH . '/' . APP . '/src' and PATH . '/lib' those are not checked. Can couse error.
  18. * @expectedException UnexpectedValueException
  19. * @expectedException PHPUnit_Framework_Error
  20. */
  21. public static function setUpBeforeClass()
  22. {
  23. if (!defined('PATH')) {
  24. define('PATH', realpath(dirname(__FILE__) . '/../../..'));
  25. }
  26. // default application name
  27. if (!defined('APP')) {
  28. define('APP', 'lib/core/tests/face');
  29. }
  30. self::$file = PATH . '/' . APP . '/cache/autoload.php';
  31. // value - if dir exists (to delete it if it was created), default true
  32. self::$inc_dirs[PATH . '/' . APP . '/src'] = true;
  33. self::$inc_dirs[PATH . '/' . APP . '/cache'] = true;
  34. self::$inc_dirs[PATH . '/lib'] = true;
  35. foreach (self::$inc_dirs as $dir => &$is_exist) {
  36. if (!file_exists($dir)) {
  37. $is_exist = false;
  38. mkdir($dir, 0777, true);
  39. }
  40. }
  41. }
  42. public function testSetAutoLoadFrom()
  43. {
  44. // autoload
  45. Load::setAutoloadFrom(self::$file);
  46. $autoload = require(self::$file);
  47. $this->assertNotEmpty($autoload);
  48. Load::autoload('Action');
  49. }
  50. public function testDebugAutoload()
  51. {
  52. Load::setAutoloadFrom(self::$file);
  53. $autoload = require(self::$file);
  54. $this->assertNotEmpty($autoload);
  55. define('DEBUG', true);
  56. Load::autoload('Func');
  57. Load::autoload('Captcha');
  58. }
  59. public function testAutoloadArrayExists()
  60. {
  61. $this->assertFileExists(self::$file);
  62. }
  63. /**
  64. * @TODO: Load - check if input file returns array
  65. */
  66. public function testFileForArray()
  67. {
  68. $autoload = require(self::$file);
  69. $this->assertInternalType('array', $autoload);
  70. }
  71. public function testAutoloadArrayNotEmpty()
  72. {
  73. $autoload = require(self::$file);
  74. $this->assertNotEmpty($autoload);
  75. $this->assertArrayHasKey('Action', $autoload);
  76. }
  77. public function testAutoloadGetFilePath()
  78. {
  79. $autoload = require(self::$file);
  80. $this->assertNotEmpty(Load::getFilePath('Registry'));
  81. }
  82. /**
  83. * @TODO: Load::getFilePath - check for wrong index
  84. * @expectedException PHPUnit_Framework_Error
  85. */
  86. public function testAutoloadGetFilePathNullIndex()
  87. {
  88. $autoload = require(self::$file);
  89. $this->assertNotEmpty(Load::getFilePath('anton'));
  90. }
  91. public static function tearDownAfterClass()
  92. {
  93. if (file_exists(self::$file)) {
  94. unlink(self::$file);
  95. }
  96. foreach (self::$inc_dirs as $dir => $is_exist) {
  97. if (!$is_exist) {
  98. rmdir($dir);
  99. }
  100. }
  101. rmdir(PATH . '/' . APP);
  102. }
  103. }