Completed
Push — master ( 02d548...e42a4c )
by Damian
02:25
created

CommentTestHelper::assertFieldsForTab()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 5
rs 9.4285
cc 1
eloc 4
nc 1
nop 4
1
<?php
2
3
class CommentTestHelper {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
    /*
5
    This only works if the last section is not a field group, e.g. a Comments
6
    field group inside of a Root.Settings tab will not work
7
     */
8
    public static function assertFieldsForTab($context, $tabName, $expected, $fields) {
9
        $tab = $fields->findOrMakeTab($tabName);
10
        $fields = $tab->FieldList();
11
        CommentTestHelper::assertFieldNames($context, $expected, $fields);
12
    }
13
14
    public static function assertFieldNames($context, $expected, $fields) {
15
        $actual = array();
16
        foreach ($fields as $field) {
17
            if (get_class($field) == 'FieldGroup') {
18
                array_push($actual, $field->Name());
19
            } else {
20
                array_push($actual, $field->getName());
21
            }
22
        }
23
        $context->assertEquals($expected, $actual);
24
    }
25
}
26