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.

130 lines
3.4 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
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() should recieve AutoloadBuilder as a parameter
  18. * @TODO: Load->buildAutoload() - uses two paths - PATH . '/' . APP . '/src' and PATH . '/lib' those are not checked. Can couse error.
  19. * @expectedException UnexpectedValueException
  20. * @expectedException PHPUnit_Framework_Error
  21. */
  22. public static function setUpBeforeClass()
  23. {
  24. if (!defined('PATH')) {
  25. define('PATH', realpath(dirname(__FILE__) . '/../../..'));
  26. }
  27. // default application name
  28. if (!defined('APP')) {
  29. define('APP', 'lib/core/tests/face');
  30. }
  31. self::$file = PATH . '/' . APP . '/cache/autoload.php';
  32. // value - if dir exists (to delete it if it was created), default true
  33. self::$inc_dirs[PATH . '/' . APP . '/src'] = true;
  34. self::$inc_dirs[PATH . '/' . APP . '/cache'] = true;
  35. self::$inc_dirs[PATH . '/lib'] = true;
  36. foreach (self::$inc_dirs as $dir => &$is_exist) {
  37. if (!file_exists($dir)) {
  38. $is_exist = false;
  39. mkdir($dir, 0777, true);
  40. }
  41. }
  42. }
  43. public function testSetAutoLoadFrom()
  44. {
  45. // autoload
  46. Load::setAutoloadFrom(self::$file);
  47. $autoload = require(self::$file);
  48. $this->assertNotEmpty($autoload);
  49. Load::autoload('Action');
  50. }
  51. /**
  52. * @TODO: Load::autoload() needs self::$autoload = require(self::$file); after self::buildAutoload();
  53. */
  54. public function testDebugAutoload()
  55. {
  56. Load::setAutoloadFrom(self::$file);
  57. $autoload = require(self::$file);
  58. $this->assertNotEmpty($autoload);
  59. if(!defined('DEBUG')) {
  60. define('DEBUG', true);
  61. }
  62. Load::autoload('Func');
  63. Load::autoload('Captcha');
  64. }
  65. public function testAutoloadArrayExists()
  66. {
  67. $this->assertFileExists(self::$file);
  68. }
  69. /**
  70. * @TODO: Load - check if input file returns array
  71. */
  72. public function testFileForArray()
  73. {
  74. $autoload = require(self::$file);
  75. $this->assertInternalType('array', $autoload);
  76. }
  77. public function testAutoloadArrayNotEmpty()
  78. {
  79. $autoload = require(self::$file);
  80. $this->assertNotEmpty($autoload);
  81. $this->assertArrayHasKey('Action', $autoload);
  82. }
  83. public function testAutoloadGetFilePath()
  84. {
  85. $autoload = require(self::$file);
  86. $this->assertNotEmpty(Load::getFilePath('Registry'));
  87. }
  88. /**
  89. * @TODO: Load::getFilePath - check for wrong index
  90. * @expectedException PHPUnit_Framework_Error
  91. */
  92. public function testAutoloadGetFilePathNullIndex()
  93. {
  94. $autoload = require(self::$file);
  95. $this->assertNotEmpty(Load::getFilePath('anton'));
  96. }
  97. public static function tearDownAfterClass()
  98. {
  99. if (file_exists(self::$file)) {
  100. unlink(self::$file);
  101. }
  102. foreach (self::$inc_dirs as $dir => $is_exist) {
  103. if (!$is_exist) {
  104. rmdir($dir);
  105. }
  106. }
  107. rmdir(PATH . '/' . APP);
  108. }
  109. }