bundle.test.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. class BundleTest extends PHPUnit_Framework_TestCase {
  3. /**
  4. * Setup the test environment.
  5. */
  6. public function setUp()
  7. {
  8. Bundle::$started = array();
  9. Bundle::$elements = array();
  10. unset(Bundle::$bundles['foo']);
  11. }
  12. /**
  13. * Tear down the test environment.
  14. */
  15. public function tearDown()
  16. {
  17. Bundle::$started = array();
  18. Bundle::$elements = array();
  19. unset(Bundle::$bundles['foo']);
  20. }
  21. /**
  22. * Test Bundle::register method.
  23. *
  24. * @group laravel
  25. */
  26. public function testRegisterMethodCorrectlyRegistersBundle()
  27. {
  28. Bundle::register('foo-baz', array('handles' => 'foo-baz'));
  29. $this->assertEquals('foo-baz', Bundle::$bundles['foo-baz']['handles']);
  30. $this->assertFalse(Bundle::$bundles['foo-baz']['auto']);
  31. Bundle::register('foo-bar', array());
  32. $this->assertFalse(Bundle::$bundles['foo-baz']['auto']);
  33. $this->assertNull(Bundle::$bundles['foo-bar']['handles']);
  34. unset(Bundle::$bundles['foo-baz']);
  35. unset(Bundle::$bundles['foo-bar']);
  36. }
  37. /**
  38. * Test the Bundle::start method.
  39. *
  40. * @group laravel
  41. */
  42. public function testStartMethodStartsBundle()
  43. {
  44. $_SERVER['bundle.dummy.start'] = 0;
  45. $_SERVER['bundle.dummy.routes'] = 0;
  46. $_SERVER['started.dummy'] = false;
  47. Event::listen('laravel.started: dummy', function()
  48. {
  49. $_SERVER['started.dummy'] = true;
  50. });
  51. Bundle::register('dummy');
  52. Bundle::start('dummy');
  53. $this->assertTrue($_SERVER['started.dummy']);
  54. $this->assertEquals(1, $_SERVER['bundle.dummy.start']);
  55. $this->assertEquals(1, $_SERVER['bundle.dummy.routes']);
  56. Bundle::start('dummy');
  57. $this->assertEquals(1, $_SERVER['bundle.dummy.start']);
  58. $this->assertEquals(1, $_SERVER['bundle.dummy.routes']);
  59. }
  60. /**
  61. * Test Bundle::handles method.
  62. *
  63. * @group laravel
  64. */
  65. public function testHandlesMethodReturnsBundleThatHandlesURI()
  66. {
  67. Bundle::register('foo', array('handles' => 'foo-bar'));
  68. $this->assertEquals('foo', Bundle::handles('foo-bar/admin'));
  69. unset(Bundle::$bundles['foo']);
  70. }
  71. /**
  72. * Test the Bundle::exist method.
  73. *
  74. * @group laravel
  75. */
  76. public function testExistMethodIndicatesIfBundleExist()
  77. {
  78. $this->assertTrue(Bundle::exists('dashboard'));
  79. $this->assertFalse(Bundle::exists('foo'));
  80. }
  81. /**
  82. * Test the Bundle::started method.
  83. *
  84. * @group laravel
  85. */
  86. public function testStartedMethodIndicatesIfBundleIsStarted()
  87. {
  88. Bundle::register('dummy');
  89. Bundle::start('dummy');
  90. $this->assertTrue(Bundle::started('dummy'));
  91. }
  92. /**
  93. * Test the Bundle::prefix method.
  94. *
  95. * @group laravel
  96. */
  97. public function testPrefixMethodReturnsCorrectPrefix()
  98. {
  99. $this->assertEquals('dummy::', Bundle::prefix('dummy'));
  100. $this->assertEquals('', Bundle::prefix(DEFAULT_BUNDLE));
  101. }
  102. /**
  103. * Test the Bundle::class_prefix method.
  104. *
  105. * @group laravel
  106. */
  107. public function testClassPrefixMethodReturnsProperClassPrefixForBundle()
  108. {
  109. $this->assertEquals('Dummy_', Bundle::class_prefix('dummy'));
  110. $this->assertEquals('', Bundle::class_prefix(DEFAULT_BUNDLE));
  111. }
  112. /**
  113. * Test the Bundle::path method.
  114. *
  115. * @group laravel
  116. */
  117. public function testPathMethodReturnsCorrectPath()
  118. {
  119. $this->assertEquals(path('app'), Bundle::path(null));
  120. $this->assertEquals(path('app'), Bundle::path(DEFAULT_BUNDLE));
  121. $this->assertEquals(path('bundle').'dashboard'.DS, Bundle::path('dashboard'));
  122. }
  123. /**
  124. * Test the Bundle::asset method.
  125. *
  126. * @group laravel
  127. */
  128. public function testAssetPathReturnsPathToBundlesAssets()
  129. {
  130. Config::set('application.url', 'http://localhost');
  131. $this->assertEquals('http://localhost/bundles/dashboard/', Bundle::assets('dashboard'));
  132. $this->assertEquals('http://localhost/', Bundle::assets(DEFAULT_BUNDLE));
  133. Config::set('application.url', '');
  134. }
  135. /**
  136. * Test the Bundle::name method.
  137. *
  138. * @group laravel
  139. */
  140. public function testBundleNameCanBeRetrievedFromIdentifier()
  141. {
  142. $this->assertEquals(DEFAULT_BUNDLE, Bundle::name('something'));
  143. $this->assertEquals(DEFAULT_BUNDLE, Bundle::name('something.else'));
  144. $this->assertEquals('bundle', Bundle::name('bundle::something.else'));
  145. }
  146. /**
  147. * Test the Bundle::element method.
  148. *
  149. * @group laravel
  150. */
  151. public function testElementCanBeRetrievedFromIdentifier()
  152. {
  153. $this->assertEquals('something', Bundle::element('something'));
  154. $this->assertEquals('something.else', Bundle::element('something.else'));
  155. $this->assertEquals('something.else', Bundle::element('bundle::something.else'));
  156. }
  157. /**
  158. * Test the Bundle::identifier method.
  159. *
  160. * @group laravel
  161. */
  162. public function testIdentifierCanBeConstructed()
  163. {
  164. $this->assertEquals('something.else', Bundle::identifier(DEFAULT_BUNDLE, 'something.else'));
  165. $this->assertEquals('dashboard::something', Bundle::identifier('dashboard', 'something'));
  166. $this->assertEquals('dashboard::something.else', Bundle::identifier('dashboard', 'something.else'));
  167. }
  168. /**
  169. * Test the Bundle::resolve method.
  170. *
  171. * @group laravel
  172. */
  173. public function testBundleNamesCanBeResolved()
  174. {
  175. $this->assertEquals(DEFAULT_BUNDLE, Bundle::resolve('foo'));
  176. $this->assertEquals('dashboard', Bundle::resolve('dashboard'));
  177. }
  178. /**
  179. * Test the Bundle::parse method.
  180. *
  181. * @group laravel
  182. */
  183. public function testParseMethodReturnsElementAndIdentifier()
  184. {
  185. $this->assertEquals(array('application', 'something'), Bundle::parse('something'));
  186. $this->assertEquals(array('application', 'something.else'), Bundle::parse('something.else'));
  187. $this->assertEquals(array('dashboard', 'something'), Bundle::parse('dashboard::something'));
  188. $this->assertEquals(array('dashboard', 'something.else'), Bundle::parse('dashboard::something.else'));
  189. }
  190. /**
  191. * Test the Bundle::get method.
  192. *
  193. * @group laravel
  194. */
  195. public function testOptionMethodReturnsBundleOption()
  196. {
  197. $this->assertFalse(Bundle::option('dashboard', 'auto'));
  198. $this->assertEquals('dashboard', Bundle::option('dashboard', 'location'));
  199. }
  200. /**
  201. * Test the Bundle::all method.
  202. *
  203. * @group laravel
  204. */
  205. public function testAllMethodReturnsBundleArray()
  206. {
  207. Bundle::register('foo');
  208. $this->assertEquals(Bundle::$bundles, Bundle::all());
  209. unset(Bundle::$bundles['foo']);
  210. }
  211. /**
  212. * Test the Bundle::names method.
  213. *
  214. * @group laravel
  215. */
  216. public function testNamesMethodReturnsBundleNames()
  217. {
  218. Bundle::register('foo');
  219. $this->assertEquals(array('dashboard', 'dummy', 'foo'), Bundle::names());
  220. unset(Bundle::$bundles['foo']);
  221. }
  222. }