bundle.test.php 6.14 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
<?php

class BundleTest extends PHPUnit_Framework_TestCase {

	/**
	 * Setup the test environment.
	 */
	public function setUp()
	{
		Bundle::$started = array();
		Bundle::$elements = array();
		unset(Bundle::$bundles['foo']);
	}

	/**
	 * Tear down the test environment.
	 */
	public function tearDown()
	{
		Bundle::$started = array();
		Bundle::$elements = array();
		unset(Bundle::$bundles['foo']);
	}

	/**
	 * Test Bundle::register method.
	 *
	 * @group laravel
	 */
	public function testRegisterMethodCorrectlyRegistersBundle()
	{
		Bundle::register('foo-baz', array('handles' => 'foo-baz'));
		$this->assertEquals('foo-baz', Bundle::$bundles['foo-baz']['handles']);
		$this->assertFalse(Bundle::$bundles['foo-baz']['auto']);

		Bundle::register('foo-bar', array());
		$this->assertFalse(Bundle::$bundles['foo-baz']['auto']);
		$this->assertNull(Bundle::$bundles['foo-bar']['handles']);

		unset(Bundle::$bundles['foo-baz']);
		unset(Bundle::$bundles['foo-bar']);
	}

	/**
	 * Test the Bundle::start method.
	 *
	 * @group laravel
	 */
	public function testStartMethodStartsBundle()
	{
		$_SERVER['bundle.dummy.start'] = 0;
		$_SERVER['bundle.dummy.routes'] = 0;

		$_SERVER['started.dummy'] = false;

		Event::listen('laravel.started: dummy', function()
		{
			$_SERVER['started.dummy'] = true;
		});

		Bundle::register('dummy');
		Bundle::start('dummy');

		$this->assertTrue($_SERVER['started.dummy']);
		$this->assertEquals(1, $_SERVER['bundle.dummy.start']);
		$this->assertEquals(1, $_SERVER['bundle.dummy.routes']);

		Bundle::start('dummy');

		$this->assertEquals(1, $_SERVER['bundle.dummy.start']);
		$this->assertEquals(1, $_SERVER['bundle.dummy.routes']);
	}

	/**
	 * Test Bundle::handles method.
	 *
	 * @group laravel
	 */
	public function testHandlesMethodReturnsBundleThatHandlesURI()
	{
		Bundle::register('foo', array('handles' => 'foo-bar'));
		$this->assertEquals('foo', Bundle::handles('foo-bar/admin'));
		unset(Bundle::$bundles['foo']);
	}

	/**
	 * Test the Bundle::exist method.
	 *
	 * @group laravel
	 */
	public function testExistMethodIndicatesIfBundleExist()
	{
		$this->assertTrue(Bundle::exists('dashboard'));
		$this->assertFalse(Bundle::exists('foo'));
	}

	/**
	 * Test the Bundle::started method.
	 *
	 * @group laravel
	 */
	public function testStartedMethodIndicatesIfBundleIsStarted()
	{
		Bundle::register('dummy');
		Bundle::start('dummy');
		$this->assertTrue(Bundle::started('dummy'));
	}

	/**
	 * Test the Bundle::prefix method.
	 *
	 * @group laravel
	 */
	public function testPrefixMethodReturnsCorrectPrefix()
	{
		$this->assertEquals('dummy::', Bundle::prefix('dummy'));
		$this->assertEquals('', Bundle::prefix(DEFAULT_BUNDLE));
	}

	/**
	 * Test the Bundle::class_prefix method.
	 *
	 * @group laravel
	 */
	public function testClassPrefixMethodReturnsProperClassPrefixForBundle()
	{
		$this->assertEquals('Dummy_', Bundle::class_prefix('dummy'));
		$this->assertEquals('', Bundle::class_prefix(DEFAULT_BUNDLE));
	}

	/**
	 * Test the Bundle::path method.
	 *
	 * @group laravel
	 */
	public function testPathMethodReturnsCorrectPath()
	{
		$this->assertEquals(path('app'), Bundle::path(null));
		$this->assertEquals(path('app'), Bundle::path(DEFAULT_BUNDLE));
		$this->assertEquals(path('bundle').'dashboard'.DS, Bundle::path('dashboard'));
	}

	/**
	 * Test the Bundle::asset method.
	 *
	 * @group laravel
	 */
	public function testAssetPathReturnsPathToBundlesAssets()
	{
150 151
		$this->assertEquals('/bundles/dashboard/', Bundle::assets('dashboard'));
		$this->assertEquals('/', Bundle::assets(DEFAULT_BUNDLE));
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251

		Config::set('application.url', '');
	}

	/**
	 * Test the Bundle::name method.
	 *
	 * @group laravel
	 */
	public function testBundleNameCanBeRetrievedFromIdentifier()
	{
		$this->assertEquals(DEFAULT_BUNDLE, Bundle::name('something'));
		$this->assertEquals(DEFAULT_BUNDLE, Bundle::name('something.else'));
		$this->assertEquals('bundle', Bundle::name('bundle::something.else'));
	}

	/**
	 * Test the Bundle::element method.
	 *
	 * @group laravel
	 */
	public function testElementCanBeRetrievedFromIdentifier()
	{
		$this->assertEquals('something', Bundle::element('something'));
		$this->assertEquals('something.else', Bundle::element('something.else'));
		$this->assertEquals('something.else', Bundle::element('bundle::something.else'));
	}

	/**
	 * Test the Bundle::identifier method.
	 *
	 * @group laravel
	 */
	public function testIdentifierCanBeConstructed()
	{
		$this->assertEquals('something.else', Bundle::identifier(DEFAULT_BUNDLE, 'something.else'));
		$this->assertEquals('dashboard::something', Bundle::identifier('dashboard', 'something'));
		$this->assertEquals('dashboard::something.else', Bundle::identifier('dashboard', 'something.else'));
	}

	/**
	 * Test the Bundle::resolve method.
	 *
	 * @group laravel
	 */
	public function testBundleNamesCanBeResolved()
	{
		$this->assertEquals(DEFAULT_BUNDLE, Bundle::resolve('foo'));
		$this->assertEquals('dashboard', Bundle::resolve('dashboard'));
	}

	/**
	 * Test the Bundle::parse method.
	 *
	 * @group laravel
	 */
	public function testParseMethodReturnsElementAndIdentifier()
	{
		$this->assertEquals(array('application', 'something'), Bundle::parse('something'));
		$this->assertEquals(array('application', 'something.else'), Bundle::parse('something.else'));
		$this->assertEquals(array('dashboard', 'something'), Bundle::parse('dashboard::something'));
		$this->assertEquals(array('dashboard', 'something.else'), Bundle::parse('dashboard::something.else'));
	}

	/**
	 * Test the Bundle::get method.
	 *
	 * @group laravel
	 */
	public function testOptionMethodReturnsBundleOption()
	{
		$this->assertFalse(Bundle::option('dashboard', 'auto'));
		$this->assertEquals('dashboard', Bundle::option('dashboard', 'location'));
	}

	/**
	 * Test the Bundle::all method.
	 *
	 * @group laravel
	 */
	public function testAllMethodReturnsBundleArray()
	{
		Bundle::register('foo');
		$this->assertEquals(Bundle::$bundles, Bundle::all());
		unset(Bundle::$bundles['foo']);
	}

	/**
	 * Test the Bundle::names method.
	 *
	 * @group laravel
	 */
	public function testNamesMethodReturnsBundleNames()
	{
		Bundle::register('foo');
		$this->assertEquals(array('dashboard', 'dummy', 'foo'), Bundle::names());
		unset(Bundle::$bundles['foo']);
	}

}