mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
bf142eb6ef
This was previously broken in a regression from https://github.com/silverstripe/silverstripe-userforms/pull/575 where the fields themselves could still be toggled, but the jQuery event dispatches for the form steps were removed. This pull request re-introduces those jQuery event triggers when hiding and showing editable form fields via display rules.
64 lines
2.4 KiB
PHP
64 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\UserForms\Tests\Model;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
use SilverStripe\UserForms\Model\EditableCustomRule;
|
|
|
|
/**
|
|
* Class EditableCustomRulesTest
|
|
*/
|
|
class EditableCustomRuleTest extends SapphireTest
|
|
{
|
|
protected static $fixture_file = 'EditableCustomRuleTest.yml';
|
|
|
|
public function testBuildExpression()
|
|
{
|
|
/** @var EditableCustomRule $rule1 */
|
|
$rule1 = $this->objFromFixture(EditableCustomRule::class, 'rule1');
|
|
$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 */
|
|
$rule2 = $this->objFromFixture(EditableCustomRule::class, 'rule2');
|
|
$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']);
|
|
}
|
|
|
|
/**
|
|
* 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()
|
|
{
|
|
/** @var EditableCustomRule $rule1 */
|
|
$rule1 = $this->objFromFixture(EditableCustomRule::class, 'rule1');
|
|
$this->assertSame('addClass("hide")', $rule1->toggleDisplayText('show'));
|
|
$this->assertSame('removeClass("hide")', $rule1->toggleDisplayText('hide'));
|
|
$this->assertSame('removeClass("hide")', $rule1->toggleDisplayText('show', true));
|
|
$this->assertSame('addClass("hide")', $rule1->toggleDisplayText('hide', true));
|
|
}
|
|
|
|
public function testToggleDisplayEvent()
|
|
{
|
|
/** @var EditableCustomRule $rule1 */
|
|
$rule1 = $this->objFromFixture(EditableCustomRule::class, 'rule1');
|
|
$this->assertSame('userform.field.hide', $rule1->toggleDisplayEvent('show'));
|
|
$this->assertSame('userform.field.show', $rule1->toggleDisplayEvent('hide'));
|
|
$this->assertSame('userform.field.show', $rule1->toggleDisplayEvent('show', true));
|
|
$this->assertSame('userform.field.hide', $rule1->toggleDisplayEvent('hide', true));
|
|
}
|
|
}
|