@@ -2,69 +2,69 @@ discard block |
||
2 | 2 | |
3 | 3 | class GridRowsExtensionTest extends FunctionalTest |
4 | 4 | { |
5 | - protected static $fixture_file = 'GridRowsExtensionTest.yml'; |
|
5 | + protected static $fixture_file = 'GridRowsExtensionTest.yml'; |
|
6 | 6 | |
7 | - protected $extraDataObjects = array( |
|
7 | + protected $extraDataObjects = array( |
|
8 | 8 | 'GridRowItemTO' |
9 | 9 | ); |
10 | 10 | |
11 | 11 | public function setUp() { |
12 | - $this->requiredExtensions = array( |
|
13 | - 'GridRowItemTO' => array('GridRowsExtension') |
|
14 | - ); |
|
12 | + $this->requiredExtensions = array( |
|
13 | + 'GridRowItemTO' => array('GridRowsExtension') |
|
14 | + ); |
|
15 | 15 | |
16 | - parent::setUp(); |
|
16 | + parent::setUp(); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | |
20 | 20 | public function testSplitDataListMethodDoesNotExist() |
21 | 21 | { |
22 | - $message = 'Method not found. A grid cannot be formed from the method' |
|
23 | - . ' GridRowItemsTHISMETHODDOESNOTEXIST'; |
|
24 | - $this->setExpectedException('InvalidArgumentException', $message); |
|
22 | + $message = 'Method not found. A grid cannot be formed from the method' |
|
23 | + . ' GridRowItemsTHISMETHODDOESNOTEXIST'; |
|
24 | + $this->setExpectedException('InvalidArgumentException', $message); |
|
25 | 25 | |
26 | - $page = $this->objFromFixture('GridRowItemPageTO', 'page001'); |
|
27 | - $page->doPublish(); |
|
26 | + $page = $this->objFromFixture('GridRowItemPageTO', 'page001'); |
|
27 | + $page->doPublish(); |
|
28 | 28 | $controller = new GridRowItemPageTO_Controller(); |
29 | 29 | $controller->setDataModel($page); |
30 | 30 | |
31 | 31 | for ($columns=1; $columns < 15; $columns++) { |
32 | - $grid = $controller->SplitDataListIntoGridRows( |
|
33 | - 'GridRowItemsTHISMETHODDOESNOTEXIST', // method from model |
|
34 | - $columns |
|
35 | - ); |
|
36 | - $this->checkGrid($grid, $columns, 10); |
|
32 | + $grid = $controller->SplitDataListIntoGridRows( |
|
33 | + 'GridRowItemsTHISMETHODDOESNOTEXIST', // method from model |
|
34 | + $columns |
|
35 | + ); |
|
36 | + $this->checkGrid($grid, $columns, 10); |
|
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | - public function testSplitDataListFromModelIntoGridRows() |
|
40 | + public function testSplitDataListFromModelIntoGridRows() |
|
41 | 41 | { |
42 | - $page = $this->objFromFixture('GridRowItemPageTO', 'page001'); |
|
43 | - $page->doPublish(); |
|
42 | + $page = $this->objFromFixture('GridRowItemPageTO', 'page001'); |
|
43 | + $page->doPublish(); |
|
44 | 44 | $controller = new GridRowItemPageTO_Controller(); |
45 | 45 | $controller->setDataModel($page); |
46 | 46 | |
47 | 47 | for ($columns=1; $columns < 15; $columns++) { |
48 | - $grid = $controller->SplitDataListIntoGridRows( |
|
49 | - 'GridRowItems', // method from model |
|
50 | - $columns |
|
51 | - ); |
|
52 | - $this->checkGrid($grid, $columns, 10); |
|
48 | + $grid = $controller->SplitDataListIntoGridRows( |
|
49 | + 'GridRowItems', // method from model |
|
50 | + $columns |
|
51 | + ); |
|
52 | + $this->checkGrid($grid, $columns, 10); |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 | |
56 | 56 | public function testSplitDataListFromControllerIntoGridRows() |
57 | 57 | { |
58 | - $page = $this->objFromFixture('GridRowItemPageTO', 'page001'); |
|
59 | - $page->doPublish(); |
|
58 | + $page = $this->objFromFixture('GridRowItemPageTO', 'page001'); |
|
59 | + $page->doPublish(); |
|
60 | 60 | $controller = new GridRowItemPageTO_Controller(); |
61 | 61 | $controller->setDataModel($page); |
62 | 62 | for ($columns=1; $columns < 15; $columns++) { |
63 | - $grid = $controller->SplitDataListIntoGridRows( |
|
64 | - 'GridItems', // method from controller |
|
65 | - $columns |
|
66 | - ); |
|
67 | - $this->checkGrid($grid, $columns, 10); |
|
63 | + $grid = $controller->SplitDataListIntoGridRows( |
|
64 | + 'GridItems', // method from controller |
|
65 | + $columns |
|
66 | + ); |
|
67 | + $this->checkGrid($grid, $columns, 10); |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
@@ -74,67 +74,67 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function testSplitClassNameDataListIntoGridRows() |
76 | 76 | { |
77 | - $page = $this->objFromFixture('GridRowItemPageTO', 'page001'); |
|
78 | - $page->doPublish(); |
|
77 | + $page = $this->objFromFixture('GridRowItemPageTO', 'page001'); |
|
78 | + $page->doPublish(); |
|
79 | 79 | $controller = new Page_Controller(); |
80 | 80 | $controller->setDataModel($page); |
81 | 81 | for ($columns=1; $columns < 15; $columns++) { |
82 | - for ($i=1; $i < 15; $i++) { |
|
83 | - $grid = $controller->SplitClassNameDataListIntoGridRows( |
|
84 | - 'GridRowItemTO', |
|
85 | - $columns, |
|
86 | - $i, |
|
87 | - $sort = 'LastEdited DESC'); |
|
88 | - $amount = $i > 12 ? 12: $i; |
|
89 | - $this->checkGrid($grid, $columns, $amount); |
|
90 | - } |
|
82 | + for ($i=1; $i < 15; $i++) { |
|
83 | + $grid = $controller->SplitClassNameDataListIntoGridRows( |
|
84 | + 'GridRowItemTO', |
|
85 | + $columns, |
|
86 | + $i, |
|
87 | + $sort = 'LastEdited DESC'); |
|
88 | + $amount = $i > 12 ? 12: $i; |
|
89 | + $this->checkGrid($grid, $columns, $amount); |
|
90 | + } |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | 94 | |
95 | 95 | private function checkGrid($grid, $maxWidth, $amount) { |
96 | - $items = 0; |
|
97 | - $rows = 0; |
|
98 | - $widths = array(); |
|
99 | - foreach ($grid->getIterator() as $row) { |
|
100 | - $rows++; |
|
101 | - $width = 0; |
|
102 | - foreach ($row->Columns->getIterator() as $column) { |
|
103 | - $items++; |
|
104 | - $width++; |
|
105 | - } |
|
106 | - array_push($widths, $width); |
|
107 | - } |
|
108 | - |
|
109 | - // last value will be <= max width |
|
110 | - $lastVal = array_pop($widths); |
|
111 | - $this->assertLessThanOrEqual($maxWidth, $lastVal); |
|
112 | - |
|
113 | - // All but the last row should equal the expected width, $maxWidth |
|
114 | - foreach ($widths as $width) { |
|
115 | - $this->assertEquals($maxWidth, $width); |
|
116 | - } |
|
117 | - $this->assertEquals($amount, $items); |
|
96 | + $items = 0; |
|
97 | + $rows = 0; |
|
98 | + $widths = array(); |
|
99 | + foreach ($grid->getIterator() as $row) { |
|
100 | + $rows++; |
|
101 | + $width = 0; |
|
102 | + foreach ($row->Columns->getIterator() as $column) { |
|
103 | + $items++; |
|
104 | + $width++; |
|
105 | + } |
|
106 | + array_push($widths, $width); |
|
107 | + } |
|
108 | + |
|
109 | + // last value will be <= max width |
|
110 | + $lastVal = array_pop($widths); |
|
111 | + $this->assertLessThanOrEqual($maxWidth, $lastVal); |
|
112 | + |
|
113 | + // All but the last row should equal the expected width, $maxWidth |
|
114 | + foreach ($widths as $width) { |
|
115 | + $this->assertEquals($maxWidth, $width); |
|
116 | + } |
|
117 | + $this->assertEquals($amount, $items); |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
121 | 121 | |
122 | 122 | class GridRowItemTO extends DataObject implements TestOnly { |
123 | - private static $db = array('Name' => 'Varchar'); |
|
123 | + private static $db = array('Name' => 'Varchar'); |
|
124 | 124 | |
125 | - private static $has_one = array('GridRowItemPage' => 'GridRowItemPageTO'); |
|
125 | + private static $has_one = array('GridRowItemPage' => 'GridRowItemPageTO'); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | class GridRowItemPageTO extends Page implements TestOnly { |
129 | - private static $has_many = array('GridRowItems' => 'GridRowItemTO'); |
|
129 | + private static $has_many = array('GridRowItems' => 'GridRowItemTO'); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | class GridRowItemPageTO_Controller extends Page_Controller implements TestOnly { |
133 | 133 | |
134 | - /* |
|
134 | + /* |
|
135 | 135 | This is a test method on the *controller* |
136 | 136 | */ |
137 | - public function GridItems() { |
|
138 | - return $this->model->GridRowItems(); |
|
139 | - } |
|
137 | + public function GridItems() { |
|
138 | + return $this->model->GridRowItems(); |
|
139 | + } |
|
140 | 140 | } |