|
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
|
|
|
/** |
|
52
|
|
|
* Test that methods are returned for manipulating the presence of the "hide" CSS class depending |
|
53
|
|
|
* on whether the field should be hidden or shown |
|
54
|
|
|
*/ |
|
55
|
|
|
public function testValidateAgainstFormData() |
|
56
|
|
|
{ |
|
57
|
|
|
$rule1 = $this->objFromFixture(EditableCustomRule::class, 'rule1'); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertFalse($rule1->validateAgainstFormData([])); |
|
60
|
|
|
$this->assertFalse($rule1->validateAgainstFormData(['CountrySelection' => 'AU'])); |
|
61
|
|
|
$this->assertTrue($rule1->validateAgainstFormData(['CountrySelection' => 'NZ'])); |
|
62
|
|
|
|
|
63
|
|
|
$rule2 = $this->objFromFixture(EditableCustomRule::class, 'rule2'); |
|
64
|
|
|
|
|
65
|
|
|
$this->assertFalse($rule2->validateAgainstFormData([])); |
|
66
|
|
|
$this->assertFalse($rule2->validateAgainstFormData(['CountryTextSelection' => 0])); |
|
67
|
|
|
$this->assertFalse($rule2->validateAgainstFormData(['CountryTextSelection' => 1])); |
|
68
|
|
|
$this->assertTrue($rule2->validateAgainstFormData(['CountryTextSelection' => 2])); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|