Laravel3-Blade /tests/LoaderTest.php

Language PHP Lines 96
MD5 Hash 0efa7c3ba0be209988b953f2d887f5d4
Repository https://github.com/clauddiu/Laravel3-Blade.git View Raw File
 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
<?php

use Mockery as m;

class LoaderTest extends PHPUnit_Framework_TestCase {

	public function tearDown()
	{
		m::close();
	}


	/**
	 * @expectedException Illuminate\Blade\InvalidViewException
	 */
	public function testExceptionsIsThrownForViewsThatDontExist()
	{
		$loader = $this->getLoader();
		$loader->getFilesystem()->shouldReceive('exists')->once()->with(__DIR__.'/foo.blade.php')->andReturn(false);
		$loader->getPath('foo');
	}


	public function testWhenViewIsExpiredItIsCompiled()
	{
		list($compiler, $files) = $this->getMocks();
		$loader = $this->getMock('Illuminate\Blade\Loader', array('isExpired'), array($compiler, $files, __DIR__, __DIR__));
		$loader->expects($this->once())->method('isExpired')->will($this->returnValue(true));
		$loader->getFilesystem()->shouldReceive('exists')->once()->andReturn(true);
		$loader->getFilesystem()->shouldReceive('get')->once()->with(__DIR__.'/foo.blade.php')->andReturn('bar');
		$loader->getFilesystem()->shouldReceive('put')->once()->with(__DIR__.'/'.md5(__DIR__.'/foo.blade.php'), 'bar');
		$loader->getCompiler()->shouldReceive('compile')->once()->with('bar')->andReturn('bar');
		$return = $loader->getPath('foo');
		$this->assertEquals(__DIR__.'/'.md5(__DIR__.'/foo.blade.php'), $return);
	}


	public function testCompilerIsNotCalledWhenTemplateIsntExpired()
	{
		list($compiler, $files) = $this->getMocks();
		$loader = $this->getMock('Illuminate\Blade\Loader', array('isExpired'), array($compiler, $files, __DIR__, __DIR__));
		$loader->expects($this->once())->method('isExpired')->will($this->returnValue(false));
		$loader->getFilesystem()->shouldReceive('exists')->once()->andReturn(true);
		$loader->getCompiler()->shouldReceive('compile')->never();
		$this->assertEquals(__DIR__.'/'.md5(__DIR__.'/foo.blade.php'), $loader->getPath('foo'));
	}


	public function testNamedViewsMayBeCompiled()
	{
		list($compiler, $files) = $this->getMocks();
		$loader = $this->getMock('Illuminate\Blade\Loader', array('isExpired'), array($compiler, $files, __DIR__, __DIR__));
		$loader->expects($this->once())->method('isExpired')->will($this->returnValue(true));
		$loader->getFilesystem()->shouldReceive('exists')->once()->andReturn(true);
		$loader->getFilesystem()->shouldReceive('get')->once()->with(__DIR__.'/name/foo.blade.php')->andReturn('bar');
		$loader->getFilesystem()->shouldReceive('put')->once()->with(__DIR__.'/'.md5(__DIR__.'/name/foo.blade.php'), 'bar');
		$loader->getCompiler()->shouldReceive('compile')->once()->with('bar')->andReturn('bar');
		$loader->addTemplatePath('name', __DIR__.'/name');
		$return = $loader->getPath('name::foo');
		$this->assertEquals(__DIR__.'/'.md5(__DIR__.'/name/foo.blade.php'), $return);
	}


	public function testNestedViewsMayBeCompiled()
	{
		list($compiler, $files) = $this->getMocks();
		$loader = $this->getMock('Illuminate\Blade\Loader', array('isExpired'), array($compiler, $files, __DIR__, __DIR__));
		$loader->expects($this->once())->method('isExpired')->will($this->returnValue(true));
		$loader->getFilesystem()->shouldReceive('exists')->once()->andReturn(true);
		$loader->getFilesystem()->shouldReceive('get')->once()->with(__DIR__.'/foo/bar.blade.php')->andReturn('bar');
		$loader->getFilesystem()->shouldReceive('put')->once()->with(__DIR__.'/'.md5(__DIR__.'/foo/bar.blade.php'), 'bar');
		$loader->getCompiler()->shouldReceive('compile')->once()->with('bar')->andReturn('bar');
		$return = $loader->getPath('foo.bar');
		$this->assertEquals(__DIR__.'/'.md5(__DIR__.'/foo/bar.blade.php'), $return);
	}

	public function testRawPathViewPathsAreCorrectlyHandled()
	{
		$loader = $this->getLoader();
		$this->assertEquals('bar', $loader->getFullPath('path: bar'));
	}

	protected function getLoader()
	{
		list($compiler, $files) = $this->getMocks();
		return new Illuminate\Blade\Loader($compiler, $files, __DIR__, __DIR__);
	}


	protected function getMocks()
	{
		return array(m::mock('Illuminate\Blade\Compiler'), m::mock('Illuminate\Filesystem'));
	}

}
Back to Top