2017-04-28 00:22:15 +02:00
|
|
|
<?php
|
|
|
|
|
2017-08-09 01:55:09 +02:00
|
|
|
namespace SilverStripe\UserForms\Test\Model;
|
|
|
|
|
|
|
|
|
|
|
|
use SilverStripe\UserForms\Model\EditableCustomRule;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-04-28 00:22:15 +02:00
|
|
|
/**
|
|
|
|
* Class EditableCustomRulesTest
|
|
|
|
*/
|
|
|
|
class EditableCustomRuleTest extends SapphireTest
|
|
|
|
{
|
|
|
|
protected static $fixture_file = 'userforms/tests/EditableCustomRuleTest.yml';
|
|
|
|
|
|
|
|
public function testBuildExpression()
|
|
|
|
{
|
|
|
|
/** @var EditableCustomRule $rule1 */
|
2017-08-09 01:55:09 +02:00
|
|
|
$rule1 = $this->objFromFixture(EditableCustomRule::class, 'rule1');
|
2017-04-28 00:22:15 +02:00
|
|
|
$result1 = $rule1->buildExpression();
|
|
|
|
|
|
|
|
//Dropdowns expect change event
|
|
|
|
$this->assertEquals('change', $result1['event']);
|
|
|
|
$this->assertNotEmpty($result1['operation']);
|
|
|
|
//Check for equals sign
|
|
|
|
$this->assertContains('==', $result1['operation']);
|
|
|
|
|
|
|
|
/** @var EditableCustomRule $rule2 */
|
2017-08-09 01:55:09 +02:00
|
|
|
$rule2 = $this->objFromFixture(EditableCustomRule::class, 'rule2');
|
2017-04-28 00:22:15 +02:00
|
|
|
$result2 = $rule2->buildExpression();
|
|
|
|
//TextField expect change event
|
|
|
|
$this->assertEquals('keyup', $result2['event']);
|
|
|
|
$this->assertNotEmpty($result2['operation']);
|
|
|
|
//Check for greater than sign
|
|
|
|
$this->assertContains('>', $result2['operation']);
|
|
|
|
}
|
2017-05-22 05:54:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that methods are returned for manipulating the presence of the "hide" CSS class depending
|
|
|
|
* on whether the field should be hidden or shown
|
|
|
|
*/
|
|
|
|
public function testToggleDisplayText()
|
|
|
|
{
|
2017-08-09 01:55:09 +02:00
|
|
|
$rule1 = $this->objFromFixture(EditableCustomRule::class, 'rule1');
|
2017-05-22 05:54:28 +02:00
|
|
|
$this->assertSame('addClass("hide")', $rule1->toggleDisplayText('show'));
|
|
|
|
$this->assertSame('removeClass("hide")', $rule1->toggleDisplayText('hide'));
|
|
|
|
}
|
|
|
|
}
|