Completed
Pull Request — master (#195)
by Robbie
02:05
created

CommentTestHelper::assertFieldNames()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 3
1
<?php
2
3
namespace SilverStripe\Comments\Tests;
4
5
use SilverStripe\Dev\TestOnly;
6
use SilverStripe\Forms\FieldGroup;
7
8
class CommentTestHelper implements TestOnly
9
{
10
    /**
11
     * This only works if the last section is not a field group, e.g. a Comments
12
     * field group inside of a Root.Settings tab will not work
13
     */
14
    public static function assertFieldsForTab($context, $tabName, $expected, $fields)
15
    {
16
        $tab = $fields->findOrMakeTab($tabName);
17
        $fields = $tab->FieldList();
18
        self::assertFieldNames($context, $expected, $fields);
19
    }
20
21
    public static function assertFieldNames($context, $expected, $fields)
22
    {
23
        $actual = array();
24
        foreach ($fields as $field) {
25
            array_push($actual, $field->getName());
26
        }
27
        $context->assertEquals($expected, $actual);
28
    }
29
}
30