mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #8124 from creative-commoners/pulls/4.1/test-fixes
FIX Minor updates to unit tests to pass with HTML5 parser and various themes
This commit is contained in:
commit
2bceabe454
@ -67,23 +67,16 @@ class EmailFieldTest extends FunctionalTest
|
||||
*
|
||||
* @see SimpleTagBuilder::_createInputTag()
|
||||
*/
|
||||
function testEmailFieldPopulation()
|
||||
public function testEmailFieldPopulation()
|
||||
{
|
||||
|
||||
$this->get('EmailFieldTest_Controller');
|
||||
$this->submitForm(
|
||||
|
||||
$response = $this->submitForm(
|
||||
'Form_Form',
|
||||
null,
|
||||
array(
|
||||
'Email' => 'test@test.com'
|
||||
)
|
||||
['Email' => 'test@test.com']
|
||||
);
|
||||
|
||||
$this->assertPartialMatchBySelector(
|
||||
'p.good',
|
||||
array(
|
||||
'Test save was successful'
|
||||
)
|
||||
);
|
||||
$this->assertContains('Test save was successful', $response->getBody());
|
||||
}
|
||||
}
|
||||
|
@ -2,33 +2,31 @@
|
||||
|
||||
namespace SilverStripe\Forms\Tests;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Dev\CSSContentParser;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\Forms\DateField;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\FileField;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\FormAction;
|
||||
use SilverStripe\Forms\HeaderField;
|
||||
use SilverStripe\Forms\LookupField;
|
||||
use SilverStripe\Forms\NumericField;
|
||||
use SilverStripe\Forms\PasswordField;
|
||||
use SilverStripe\Forms\Tests\FormTest\TestController;
|
||||
use SilverStripe\Forms\Tests\FormTest\ControllerWithSecurityToken;
|
||||
use SilverStripe\Forms\Tests\FormTest\ControllerWithStrictPostCheck;
|
||||
use SilverStripe\Forms\Tests\FormTest\Player;
|
||||
use SilverStripe\Forms\Tests\FormTest\Team;
|
||||
use SilverStripe\Forms\Tests\FormTest\TestController;
|
||||
use SilverStripe\Forms\TextareaField;
|
||||
use SilverStripe\Forms\TextField;
|
||||
use SilverStripe\ORM\ValidationResult;
|
||||
use SilverStripe\Security\NullSecurityToken;
|
||||
use SilverStripe\Security\Security;
|
||||
use SilverStripe\Security\SecurityToken;
|
||||
use SilverStripe\Security\RandomGenerator;
|
||||
use SilverStripe\Dev\CSSContentParser;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Forms\TextField;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\HeaderField;
|
||||
use SilverStripe\Forms\TextareaField;
|
||||
use SilverStripe\Forms\DateField;
|
||||
use SilverStripe\Forms\NumericField;
|
||||
use SilverStripe\Forms\LookupField;
|
||||
use SilverStripe\Forms\FileField;
|
||||
use SilverStripe\Forms\FormAction;
|
||||
use SilverStripe\Security\SecurityToken;
|
||||
use SilverStripe\View\SSViewer;
|
||||
|
||||
/**
|
||||
@ -50,6 +48,8 @@ class FormTest extends FunctionalTest
|
||||
ControllerWithStrictPostCheck::class,
|
||||
];
|
||||
|
||||
protected static $disable_themes = true;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
@ -2,20 +2,19 @@
|
||||
|
||||
namespace SilverStripe\Forms\Tests\GridField;
|
||||
|
||||
use SilverStripe\Dev\CSSContentParser;
|
||||
use SilverStripe\Dev\Debug;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Forms\HiddenField;
|
||||
use SilverStripe\Forms\GridField\GridFieldDetailForm;
|
||||
use SilverStripe\Dev\CSSContentParser;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\GridField\GridFieldDetailForm;
|
||||
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
|
||||
use SilverStripe\Forms\HiddenField;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldDetailFormTest\Category;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldDetailFormTest\CategoryController;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldDetailFormTest\TestController;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldDetailFormTest\GroupController;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldDetailFormTest\PeopleGroup;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldDetailFormTest\Person;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldDetailFormTest\TestController;
|
||||
|
||||
/**
|
||||
* @skipUpgrade
|
||||
@ -36,6 +35,8 @@ class GridFieldDetailFormTest extends FunctionalTest
|
||||
GroupController::class,
|
||||
];
|
||||
|
||||
protected static $disable_themes = true;
|
||||
|
||||
public function testValidator()
|
||||
{
|
||||
$this->logInWithPermission('ADMIN');
|
||||
|
@ -5,90 +5,85 @@ namespace SilverStripe\Forms\Tests;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Forms\LookupField;
|
||||
use SilverStripe\Security\Member;
|
||||
|
||||
class LookupFieldTest extends SapphireTest
|
||||
{
|
||||
|
||||
protected static $fixture_file = 'LookupFieldTest.yml';
|
||||
|
||||
public function testNullValueWithNumericArraySource()
|
||||
{
|
||||
$source = array(1 => 'one', 2 => 'two', 3 => 'three');
|
||||
$f = new LookupField('test', 'test', $source);
|
||||
$f->setValue(null);
|
||||
$field = new LookupField('test', 'test', $source);
|
||||
$field->setValue(null);
|
||||
$result = trim($field->Field()->getValue());
|
||||
|
||||
$this->assertEquals(
|
||||
'<span class="readonly" id="test"><i>(none)</i></span><input type="hidden" name="test" value="" />',
|
||||
trim($f->Field()->getValue())
|
||||
);
|
||||
$this->assertContains('<span class="readonly" id="test"><i>(none)</i></span>', $result);
|
||||
$this->assertContains('<input type="hidden" name="test" value="" />', $result);
|
||||
}
|
||||
|
||||
public function testStringValueWithNumericArraySource()
|
||||
{
|
||||
$source = array(1 => 'one', 2 => 'two', 3 => 'three');
|
||||
$f = new LookupField('test', 'test', $source);
|
||||
$f->setValue(1);
|
||||
$this->assertEquals(
|
||||
'<span class="readonly" id="test">one</span><input type="hidden" name="test" value="1" />',
|
||||
trim($f->Field()->getValue())
|
||||
);
|
||||
$field = new LookupField('test', 'test', $source);
|
||||
$field->setValue(1);
|
||||
$result = trim($field->Field()->getValue());
|
||||
$this->assertContains('<span class="readonly" id="test">one</span>', $result);
|
||||
$this->assertContains('<input type="hidden" name="test" value="1" />', $result);
|
||||
}
|
||||
|
||||
public function testUnknownStringValueWithNumericArraySource()
|
||||
{
|
||||
$source = array(1 => 'one', 2 => 'two', 3 => 'three');
|
||||
$f = new LookupField('test', 'test', $source);
|
||||
$f->setValue('w00t');
|
||||
$this->assertEquals(
|
||||
'<span class="readonly" id="test">w00t</span><input type="hidden" name="test" value="" />',
|
||||
trim($f->Field()->getValue())
|
||||
);
|
||||
$field = new LookupField('test', 'test', $source);
|
||||
$field->setValue('w00t');
|
||||
$result = trim($field->Field()->getValue());
|
||||
|
||||
$this->assertContains('<span class="readonly" id="test">w00t</span>', $result);
|
||||
$this->assertContains('<input type="hidden" name="test" value="" />', $result);
|
||||
}
|
||||
|
||||
public function testArrayValueWithAssociativeArraySource()
|
||||
{
|
||||
// Array values (= multiple selections) might be set e.g. from ListboxField
|
||||
$source = array('one' => 'one val', 'two' => 'two val', 'three' => 'three val');
|
||||
$f = new LookupField('test', 'test', $source);
|
||||
$f->setValue(array('one','two'));
|
||||
$this->assertEquals(
|
||||
'<span class="readonly" id="test">one val, two val</span>'
|
||||
. '<input type="hidden" name="test" value="one, two" />',
|
||||
trim($f->Field()->getValue())
|
||||
);
|
||||
$field = new LookupField('test', 'test', $source);
|
||||
$field->setValue(array('one','two'));
|
||||
$result = trim($field->Field()->getValue());
|
||||
|
||||
$this->assertContains('<span class="readonly" id="test">one val, two val</span>', $result);
|
||||
$this->assertContains('<input type="hidden" name="test" value="one, two" />', $result);
|
||||
}
|
||||
|
||||
public function testArrayValueWithNumericArraySource()
|
||||
{
|
||||
// Array values (= multiple selections) might be set e.g. from ListboxField
|
||||
$source = array(1 => 'one', 2 => 'two', 3 => 'three');
|
||||
$f = new LookupField('test', 'test', $source);
|
||||
$f->setValue(array(1,2));
|
||||
$this->assertEquals(
|
||||
'<span class="readonly" id="test">one, two</span><input type="hidden" name="test" value="1, 2" />',
|
||||
trim($f->Field()->getValue())
|
||||
);
|
||||
$field = new LookupField('test', 'test', $source);
|
||||
$field->setValue(array(1,2));
|
||||
$result = trim($field->Field()->getValue());
|
||||
|
||||
$this->assertContains('<span class="readonly" id="test">one, two</span>', $result);
|
||||
$this->assertContains('<input type="hidden" name="test" value="1, 2" />', $result);
|
||||
}
|
||||
|
||||
public function testArrayValueWithSqlMapSource()
|
||||
{
|
||||
$member1 = $this->objFromFixture('SilverStripe\\Security\\Member', 'member1');
|
||||
$member2 = $this->objFromFixture('SilverStripe\\Security\\Member', 'member2');
|
||||
$member3 = $this->objFromFixture('SilverStripe\\Security\\Member', 'member3');
|
||||
$member1 = $this->objFromFixture(Member::class, 'member1');
|
||||
$member2 = $this->objFromFixture(Member::class, 'member2');
|
||||
$member3 = $this->objFromFixture(Member::class, 'member3');
|
||||
|
||||
$source = DataObject::get('SilverStripe\\Security\\Member');
|
||||
$f = new LookupField('test', 'test', $source->map('ID', 'FirstName'));
|
||||
$f->setValue(array($member1->ID, $member2->ID));
|
||||
$source = DataObject::get(Member::class);
|
||||
$field = new LookupField('test', 'test', $source->map('ID', 'FirstName'));
|
||||
$field->setValue(array($member1->ID, $member2->ID));
|
||||
$result = trim($field->Field()->getValue());
|
||||
|
||||
$this->assertEquals(
|
||||
sprintf(
|
||||
'<span class="readonly" id="test">member1, member2</span>'
|
||||
. '<input type="hidden" name="test" value="%s, %s" />',
|
||||
$member1->ID,
|
||||
$member2->ID
|
||||
),
|
||||
trim($f->Field()->getValue())
|
||||
);
|
||||
$this->assertContains('<span class="readonly" id="test">member1, member2</span>', $result);
|
||||
$this->assertContains(sprintf(
|
||||
'<input type="hidden" name="test" value="%s, %s" />',
|
||||
$member1->ID,
|
||||
$member2->ID
|
||||
), $result);
|
||||
}
|
||||
|
||||
public function testWithMultiDimensionalSource()
|
||||
@ -105,23 +100,17 @@ class LookupFieldTest extends SapphireTest
|
||||
)
|
||||
);
|
||||
|
||||
$f = new LookupField('test', 'test', $choices);
|
||||
$f->setValue(3);
|
||||
$field = new LookupField('test', 'test', $choices);
|
||||
$field->setValue(3);
|
||||
$result = trim($field->Field()->getValue());
|
||||
|
||||
$this->assertEquals(
|
||||
'<span class="readonly" id="test">Carrots</span><input type="hidden" name="test" value="3" />',
|
||||
trim($f->Field()->getValue())
|
||||
);
|
||||
$this->assertContains('<span class="readonly" id="test">Carrots</span>', $result);
|
||||
$this->assertContains('<input type="hidden" name="test" value="3" />', $result);
|
||||
|
||||
$f->setValue(
|
||||
array(
|
||||
3, 9
|
||||
)
|
||||
);
|
||||
$field->setValue([3, 9]);
|
||||
$result = trim($field->Field()->getValue());
|
||||
|
||||
$this->assertEquals(
|
||||
'<span class="readonly" id="test">Carrots, Vegan</span><input type="hidden" name="test" value="3, 9" />',
|
||||
trim($f->Field()->getValue())
|
||||
);
|
||||
$this->assertContains('<span class="readonly" id="test">Carrots, Vegan</span>', $result);
|
||||
$this->assertContains('<input type="hidden" name="test" value="3, 9" />', $result);
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ class SelectionGroupTest extends SapphireTest
|
||||
$field->setValue('two');
|
||||
|
||||
$parser = new CSSContentParser($field->FieldHolder());
|
||||
|
||||
$listEls = $parser->getBySelector('li');
|
||||
$listElOne = $listEls[0];
|
||||
$listElTwo = $listEls[1];
|
||||
|
@ -196,15 +196,17 @@ class TreeDropdownFieldTest extends SapphireTest
|
||||
public function testReadonly()
|
||||
{
|
||||
$field = new TreeDropdownField('TestTree', 'Test tree', File::class);
|
||||
$asdf = $this->objFromFixture(File::class, 'asdf');
|
||||
$field->setValue($asdf->ID);
|
||||
$fileMock = $this->objFromFixture(File::class, 'asdf');
|
||||
$field->setValue($fileMock->ID);
|
||||
$readonlyField = $field->performReadonlyTransformation();
|
||||
$this->assertEquals(
|
||||
<<<"HTML"
|
||||
<span class="readonly" id="TestTree"><Special & characters></span><input type="hidden" name="TestTree" value="{$asdf->ID}" />
|
||||
HTML
|
||||
,
|
||||
(string)$readonlyField->Field()
|
||||
$result = (string) $readonlyField->Field();
|
||||
$this->assertContains(
|
||||
'<span class="readonly" id="TestTree"><Special & characters></span>',
|
||||
$result
|
||||
);
|
||||
$this->assertContains(
|
||||
'<input type="hidden" name="TestTree" value="' . $fileMock->ID . '" />',
|
||||
$result
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user