Conditions | 3 |
Paths | 3 |
Total Lines | 26 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
8 | public function testGridFieldHasCustomisedAddNewButton() |
||
9 | { |
||
10 | $modelAdmin = new DMSDocumentAdmin; |
||
11 | // SS < 3.3 doesn't have a response setter, this initialises it |
||
12 | $modelAdmin->handleRequest(new SS_HTTPRequest('GET', '/'), DataModel::inst()); |
||
13 | $modelAdmin->init(); |
||
14 | |||
15 | $form = $modelAdmin->getEditForm(); |
||
16 | $gridFieldConfig = $form->Fields()->first()->getConfig(); |
||
17 | |||
18 | // Our button is an instance of the original, so is returned when asking for the original |
||
19 | $addNewButtons = $gridFieldConfig->getComponentsByType('GridFieldAddNewButton'); |
||
20 | foreach ($addNewButtons as $key => $addNewButton) { |
||
21 | if ($addNewButton instanceof DMSGridFieldAddNewButton) { |
||
22 | // Remove our version for testing's sake |
||
23 | $addNewButtons->remove($addNewButton); |
||
24 | } |
||
25 | } |
||
26 | |||
27 | $this->assertCount(0, $addNewButtons, 'Original add new button is removed'); |
||
28 | $this->assertInstanceOf( |
||
29 | 'DMSGridFieldAddNewButton', |
||
30 | $gridFieldConfig->getComponentByType('DMSGridFieldAddNewButton'), |
||
31 | 'Model admin for documents contains customised DMS add new button' |
||
32 | ); |
||
33 | } |
||
34 | } |
||
35 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.