|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bundle\WidgetMapBundle\Tests\Builder; |
|
4
|
|
|
|
|
5
|
|
|
use Victoire\Bundle\CoreBundle\Entity\View; |
|
6
|
|
|
use Victoire\Bundle\PageBundle\Entity\Page; |
|
7
|
|
|
use Victoire\Bundle\TemplateBundle\Entity\Template; |
|
8
|
|
|
use Victoire\Bundle\WidgetBundle\Entity\Widget; |
|
9
|
|
|
use Victoire\Bundle\WidgetMapBundle\Builder\WidgetMapBuilder; |
|
10
|
|
|
use Victoire\Bundle\WidgetMapBundle\Entity\WidgetMap; |
|
11
|
|
|
use Victoire\Widget\TextBundle\Entity\WidgetText; |
|
12
|
|
|
|
|
13
|
|
|
class WidgetMapBuilderTest extends \PHPUnit_Framework_TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
public function testBuildPage() |
|
16
|
|
|
{ |
|
17
|
|
|
$builder = new WidgetMapBuilder(); |
|
18
|
|
|
$view = new Page(); |
|
19
|
|
|
$widget3 = $this->newWidgetMap(3, null, null, $view, $this->newWidget(3)); |
|
20
|
|
|
$widget2 = $this->newWidgetMap(2, $widget3, WidgetMap::POSITION_BEFORE, $view, $this->newWidget(2)); |
|
21
|
|
|
$widget1 = $this->newWidgetMap(1, $widget2, WidgetMap::POSITION_AFTER, $view, $this->newWidget(1)); |
|
|
|
|
|
|
22
|
|
|
$widget4 = $this->newWidgetMap(4, $widget3, WidgetMap::POSITION_AFTER, $view, $this->newWidget(4)); |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
$builtWidgetMap = $builder->build($view); |
|
25
|
|
|
|
|
26
|
|
|
$order = [2, 1, 3, 4]; |
|
27
|
|
|
$i = 0; |
|
28
|
|
|
foreach ($builtWidgetMap['content'] as $widgetMap) { |
|
29
|
|
|
$this->assertEquals($order[$i++], $widgetMap->getWidget()->getId()); |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testBuildPageWithTemplate() |
|
34
|
|
|
{ |
|
35
|
|
|
$builder = new WidgetMapBuilder(); |
|
36
|
|
|
$template = new Template(); |
|
37
|
|
|
$view = new Page(); |
|
38
|
|
|
$view->setTemplate($template); |
|
39
|
|
|
|
|
40
|
|
|
$widget3 = $this->newWidgetMap(3, null, null, $template, $this->newWidget(3)); |
|
41
|
|
|
$widget2 = $this->newWidgetMap(2, $widget3, WidgetMap::POSITION_BEFORE, $view, $this->newWidget(2)); |
|
42
|
|
|
$widget1 = $this->newWidgetMap(1, $widget2, WidgetMap::POSITION_AFTER, $view, $this->newWidget(1)); |
|
|
|
|
|
|
43
|
|
|
$widget4 = $this->newWidgetMap(4, $widget3, WidgetMap::POSITION_AFTER, $view, $this->newWidget(4)); |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
$builtWidgetMap = $builder->build($view); |
|
46
|
|
|
|
|
47
|
|
|
$order = [2, 1, 3, 4]; |
|
48
|
|
|
$i = 0; |
|
49
|
|
|
foreach ($builtWidgetMap['content'] as $widgetMap) { |
|
50
|
|
|
$this->assertEquals($order[$i++], $widgetMap->getWidget()->getId()); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testBuildPageWithTemplateTemplate() |
|
55
|
|
|
{ |
|
56
|
|
|
$builder = new WidgetMapBuilder(); |
|
57
|
|
|
$grandtemplate = new Template(); |
|
58
|
|
|
$template = new Template(); |
|
59
|
|
|
$template->setTemplate($grandtemplate); |
|
60
|
|
|
$view = new Page(); |
|
61
|
|
|
$view->setTemplate($template); |
|
62
|
|
|
|
|
63
|
|
|
$widget3 = $this->newWidgetMap(3, null, null, $grandtemplate, $this->newWidget(3)); |
|
64
|
|
|
$widget2 = $this->newWidgetMap(2, $widget3, WidgetMap::POSITION_BEFORE, $template, $this->newWidget(2)); |
|
65
|
|
|
$widget1 = $this->newWidgetMap(1, $widget2, WidgetMap::POSITION_AFTER, $view, $this->newWidget(1)); |
|
|
|
|
|
|
66
|
|
|
$widget4 = $this->newWidgetMap(4, $widget3, WidgetMap::POSITION_AFTER, $view, $this->newWidget(4)); |
|
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
$builtWidgetMap = $builder->build($view); |
|
69
|
|
|
|
|
70
|
|
|
$order = [2, 1, 3, 4]; |
|
71
|
|
|
$i = 0; |
|
72
|
|
|
foreach ($builtWidgetMap['content'] as $widgetMap) { |
|
73
|
|
|
$this->assertEquals($order[$i++], $widgetMap->getWidget()->getId()); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param integer $id |
|
79
|
|
|
* @param null|WidgetMap $parent |
|
80
|
|
|
*/ |
|
81
|
|
View Code Duplication |
protected function newWidgetMap($id, $parent, $position, View $view, Widget $widget) |
|
|
|
|
|
|
82
|
|
|
{ |
|
83
|
|
|
$widgetMap = new WidgetMap(); |
|
84
|
|
|
$widgetMap->setId($id); |
|
85
|
|
|
if ($parent) { |
|
86
|
|
|
$widgetMap->setParent($parent); |
|
87
|
|
|
$parent->addChild($widgetMap); |
|
88
|
|
|
} |
|
89
|
|
|
$widgetMap->setPosition($position); |
|
90
|
|
|
$widgetMap->setWidget($widget); |
|
91
|
|
|
$widgetMap->setSlot('content'); |
|
92
|
|
|
$view->addWidgetMap($widgetMap); |
|
93
|
|
|
|
|
94
|
|
|
return $widgetMap; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param integer $id |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function newWidget($id) |
|
101
|
|
|
{ |
|
102
|
|
|
$widget = new WidgetText(); |
|
103
|
|
|
$widget->setId($id); |
|
104
|
|
|
|
|
105
|
|
|
return $widget; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.