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.

111 lines
2.9 KiB

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