Completed
Pull Request — master (#647)
by Robbie
20:35 queued 18:30
created

EditableCustomRuleTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B testBuildExpression() 0 24 1
A testToggleDisplayText() 0 6 1
1
<?php
2
3
namespace SilverStripe\UserForms\Tests\Model;
4
5
use SilverStripe\Dev\SapphireTest;
6
use SilverStripe\UserForms\Model\EditableCustomRule;
7
8
/**
9
 * Class EditableCustomRulesTest
10
 */
11
class EditableCustomRuleTest extends SapphireTest
12
{
13
    protected static $fixture_file = 'EditableCustomRuleTest.yml';
14
15
    public function testBuildExpression()
16
    {
17
        /** @var EditableCustomRule $rule1 */
18
        $rule1 = $this->objFromFixture(EditableCustomRule::class, 'rule1');
19
        $result1 = $rule1->buildExpression();
20
21
        //Dropdowns expect change event
22
        $this->assertEquals('change', $result1['event']);
23
        $this->assertNotEmpty($result1['operation']);
24
25
        //Check for equals sign
26
        $this->assertContains('==', $result1['operation']);
27
28
        /** @var EditableCustomRule $rule2 */
29
        $rule2 = $this->objFromFixture(EditableCustomRule::class, 'rule2');
30
        $result2 = $rule2->buildExpression();
31
32
        //TextField expect change event
33
        $this->assertEquals('keyup', $result2['event']);
34
        $this->assertNotEmpty($result2['operation']);
35
36
        //Check for greater than sign
37
        $this->assertContains('>', $result2['operation']);
38
    }
39
40
    /**
41
     * Test that methods are returned for manipulating the presence of the "hide" CSS class depending
42
     * on whether the field should be hidden or shown
43
     */
44
    public function testToggleDisplayText()
45
    {
46
        $rule1 = $this->objFromFixture(EditableCustomRule::class, 'rule1');
47
        $this->assertSame('addClass("hide")', $rule1->toggleDisplayText('show'));
48
        $this->assertSame('removeClass("hide")', $rule1->toggleDisplayText('hide'));
49
    }
50
}
51