forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewTest.php
More file actions
executable file
·115 lines (87 loc) · 3.82 KB
/
ViewTest.php
File metadata and controls
executable file
·115 lines (87 loc) · 3.82 KB
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
<?php
use Mockery as m;
use Illuminate\View\View;
use Illuminate\Support\Contracts\ArrayableInterface;
class ViewTest extends PHPUnit_Framework_TestCase {
public function __construct()
{
m::close();
}
public function testDataCanBeSetOnView()
{
$view = new View(m::mock('Illuminate\View\Environment'), m::mock('Illuminate\View\Engines\EngineInterface'), 'view', 'path', array());
$view->with('foo', 'bar');
$view->with(array('baz' => 'boom'));
$this->assertEquals(array('foo' => 'bar', 'baz' => 'boom'), $view->getData());
$view = new View(m::mock('Illuminate\View\Environment'), m::mock('Illuminate\View\Engines\EngineInterface'), 'view', 'path', array());
$view->withFoo('bar')->withBaz('boom');
$this->assertEquals(array('foo' => 'bar', 'baz' => 'boom'), $view->getData());
}
public function testRenderProperlyRendersView()
{
$view = $this->getView();
$view->getEnvironment()->shouldReceive('incrementRender')->once()->ordered();
$view->getEnvironment()->shouldReceive('callComposer')->once()->ordered()->with($view);
$view->getEnvironment()->shouldReceive('getShared')->once()->andReturn(array('shared' => 'foo'));
$view->getEngine()->shouldReceive('get')->once()->with('path', array('foo' => 'bar', 'shared' => 'foo'))->andReturn('contents');
$view->getEnvironment()->shouldReceive('decrementRender')->once()->ordered();
$view->getEnvironment()->shouldReceive('flushSectionsIfDoneRendering')->once();
$me = $this;
$callback = function(View $rendered, $contents) use ($me, $view)
{
$me->assertEquals($view, $rendered);
$me->assertEquals('contents', $contents);
};
$this->assertEquals('contents', $view->render($callback));
}
public function testRenderSectionsReturnsEnvironmentSections()
{
$view = m::mock('Illuminate\View\View[render]');
$view->__construct(m::mock('Illuminate\View\Environment'), m::mock('Illuminate\View\Engines\EngineInterface'), 'view', 'path', array());
$view->shouldReceive('render')->with(m::type('Closure'))->once()->andReturn($sections = array('foo' => 'bar'));
$view->getEnvironment()->shouldReceive('getSections')->once()->andReturn($sections);
$this->assertEquals($sections, $view->renderSections());
}
public function testSectionsAreNotFlushedWhenNotDoneRendering()
{
$view = $this->getView();
$view->getEnvironment()->shouldReceive('incrementRender')->once();
$view->getEnvironment()->shouldReceive('callComposer')->once()->with($view);
$view->getEnvironment()->shouldReceive('getShared')->once()->andReturn(array('shared' => 'foo'));
$view->getEngine()->shouldReceive('get')->once()->with('path', array('foo' => 'bar', 'shared' => 'foo'))->andReturn('contents');
$view->getEnvironment()->shouldReceive('decrementRender')->once();
$view->getEnvironment()->shouldReceive('flushSectionsIfDoneRendering')->once();
$this->assertEquals('contents', $view->render());
}
public function testViewNestBindsASubView()
{
$view = $this->getView();
$view->getEnvironment()->shouldReceive('make')->once()->with('foo', array('data'));
$result = $view->nest('key', 'foo', array('data'));
$this->assertInstanceOf('Illuminate\View\View', $result);
}
public function testViewAcceptsArrayableImplementations()
{
$arrayable = m::mock('Illuminate\Support\Contracts\ArrayableInterface');
$arrayable->shouldReceive('toArray')->once()->andReturn(array('foo' => 'bar', 'baz' => array('qux', 'corge')));
$view = new View(
m::mock('Illuminate\View\Environment'),
m::mock('Illuminate\View\Engines\EngineInterface'),
'view',
'path',
$arrayable
);
$this->assertEquals('bar', $view->foo);
$this->assertEquals(array('qux', 'corge'), $view->baz);
}
protected function getView()
{
return new View(
m::mock('Illuminate\View\Environment'),
m::mock('Illuminate\View\Engines\EngineInterface'),
'view',
'path',
array('foo' => 'bar')
);
}
}