Completed
Pull Request — master (#185)
by Janne
03:01
created

CommentTestHelper::assertFieldNames()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 3
eloc 8
nc 3
nop 3
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
    /*
6
    This only works if the last section is not a field group, e.g. a Comments
7
    field group inside of a Root.Settings tab will not work
8
     */
9
    public static function assertFieldsForTab($context, $tabName, $expected, $fields)
10
    {
11
        $tab = $fields->findOrMakeTab($tabName);
12
        $fields = $tab->FieldList();
13
        CommentTestHelper::assertFieldNames($context, $expected, $fields);
14
    }
15
16
    public static function assertFieldNames($context, $expected, $fields)
17
    {
18
        $actual = array();
19
        foreach ($fields as $field) {
20
            if (get_class($field) == 'FieldGroup') {
21
                array_push($actual, $field->Name());
22
            } else {
23
                array_push($actual, $field->getName());
24
            }
25
        }
26
        $context->assertEquals($expected, $actual);
27
    }
28
}
29