Merge pull request #534 from tractorcow/pulls/fix-checkbox-validation

BUG Fix issue with UserFormsCheckboxSetField
This commit is contained in:
Daniel Hensby 2016-12-20 20:16:52 +00:00 committed by GitHub
commit 8e4ad8f4df
3 changed files with 33 additions and 19 deletions

View File

@ -7,17 +7,13 @@ language: php
matrix: matrix:
include: include:
- php: 5.3 - php: 5.3
env: DB=MYSQL CORE_RELEASE=3.1 env: DB=MYSQL CORE_RELEASE=3.4
- php: 5.4 - php: 5.4
env: DB=MYSQL CORE_RELEASE=3.2 env: DB=MYSQL CORE_RELEASE=3.5
- php: 5.5
env: DB=MYSQL CORE_RELEASE=3.3
- php: 5.6 - php: 5.6
env: DB=MYSQL CORE_RELEASE=3 env: DB=MYSQL CORE_RELEASE=3
- php: 5.6 - php: 5.6
env: DB=MYSQL CORE_RELEASE=3.1 SECUREASSETS=1 env: DB=MYSQL CORE_RELEASE=3.5 SECUREASSETS=1
- php: 5.6
env: DB=PGSQL CORE_RELEASE=3.3
before_script: before_script:
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support - git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
@ -28,6 +24,7 @@ before_script:
script: script:
- vendor/bin/phpunit --coverage-clover coverage.clover userforms/tests - vendor/bin/phpunit --coverage-clover coverage.clover userforms/tests
- wget https://scrutinizer-ci.com/ocular.phar - wget https://scrutinizer-ci.com/ocular.phar
- cd ./userforms
- git remote rm origin - git remote rm origin
- git remote add origin git@github.com:silverstripe/silverstripe-userforms.git - git remote add origin git@github.com:silverstripe/silverstripe-userforms.git
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover - php ocular.phar code-coverage:upload --format=php-clover coverage.clover

View File

@ -23,18 +23,6 @@ class UserFormsCheckboxSetField extends CheckboxSetField
return $options; return $options;
} }
/**
* @inheritdoc
*
* @return array
*/
public function getSourceAsArray()
{
$array = parent::getSourceAsArray();
return array_values($array);
}
/** /**
* @inheritdoc * @inheritdoc
* *

View File

@ -0,0 +1,29 @@
<?php
class UserFormsCheckboxSetFieldTest extends SapphireTest
{
public function testValidate() {
$field = new UserFormsCheckboxSetField('Field', 'My field', array('One' => 'One', 'Two' => 'Two'));
$validator = new RequiredFields();
// String values
$field->setValue('One');
$this->assertTrue($field->validate($validator));
$field->setValue('One,Two');
$this->assertTrue($field->validate($validator));
$field->setValue('Three,Four');
$this->assertFalse($field->validate($validator));
// Array values
$field->setValue(array('One'));
$this->assertTrue($field->validate($validator));
$field->setValue(array('One', 'Two'));
$this->assertTrue($field->validate($validator));
// Invalid
$field->setValue('Three');
$this->assertFalse($field->validate($validator));
$field->setValue(array('Three', 'Four'));
$this->assertFalse($field->validate($validator));
}
}