/
MenuWidgetHandlerTest.php
90 lines (79 loc) · 2.52 KB
/
MenuWidgetHandlerTest.php
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
<?php namespace Orchestra\Widget\TestCase;
use Mockery as m;
use Orchestra\Widget\MenuWidgetHandler;
use Orchestra\Support\Collection;
use Illuminate\Support\Fluent;
class MenuWidgetHandlerTest extends \PHPUnit_Framework_TestCase
{
/**
* Teardown the test environment.
*/
public function tearDown()
{
m::close();
}
/**
* Test construct a Orchestra\Widget\MenuWidgetHandler
*
* @test
*/
public function testConstructMethod()
{
$stub = new MenuWidgetHandler('foo', array());
$refl = new \ReflectionObject($stub);
$config = $refl->getProperty('config');
$name = $refl->getProperty('name');
$nesty = $refl->getProperty('nesty');
$type = $refl->getProperty('type');
$config->setAccessible(true);
$name->setAccessible(true);
$nesty->setAccessible(true);
$type->setAccessible(true);
$expected = array(
'defaults' => array(
'attributes' => array(),
'icon' => '',
'link' => '#',
'title' => '',
),
);
$this->assertEquals($expected, $config->getValue($stub));
$this->assertEquals('foo', $name->getValue($stub));
$this->assertInstanceOf('\Orchestra\Support\Nesty', $nesty->getValue($stub));
$this->assertEquals('menu', $type->getValue($stub));
}
/**
* Test Orchestra\Widget\MenuWidgetHandler::add() method.
*
* @test
*/
public function testAddMethod()
{
$stub = new MenuWidgetHandler('foo', array());
$expected = new Collection(array(
'foo' => new Fluent(array(
'attributes' => array(),
'childs' => array(),
'icon' => '',
'id' => 'foo',
'link' => '#',
'title' => 'hello world',
)),
'foobar' => new Fluent(array(
'attributes' => array(),
'childs' => array(),
'icon' => '',
'id' => 'foobar',
'link' => '#',
'title' => 'hello world 2',
)),
));
$stub->add('foo', function ($item) {
$item->title = 'hello world';
});
$stub->add('foobar', '>:foo', function ($item) {
$item->title = 'hello world 2';
});
$this->assertEquals($expected, $stub->getItems());
}
}