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

CommentTestHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A assertFieldsForTab() 0 5 1
A assertFieldNames() 0 11 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
    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