mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Merge pull request #1326 from creative-commoners/pulls/7/phpunit11
DEP Use PHPUnit 11
This commit is contained in:
commit
9e61ae3b96
@ -39,7 +39,7 @@
|
|||||||
"silverstripe/mimevalidator": "^4"
|
"silverstripe/mimevalidator": "^4"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^9.6",
|
"phpunit/phpunit": "^11.3",
|
||||||
"squizlabs/php_codesniffer": "^3",
|
"squizlabs/php_codesniffer": "^3",
|
||||||
"silverstripe/documentation-lint": "^1",
|
"silverstripe/documentation-lint": "^1",
|
||||||
"silverstripe/standards": "^1",
|
"silverstripe/standards": "^1",
|
||||||
|
@ -30,6 +30,7 @@ use SilverStripe\Versioned\Versioned;
|
|||||||
use SilverStripe\View\ArrayData;
|
use SilverStripe\View\ArrayData;
|
||||||
use SilverStripe\View\SSViewer;
|
use SilverStripe\View\SSViewer;
|
||||||
use function filesize;
|
use function filesize;
|
||||||
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package userforms
|
* @package userforms
|
||||||
@ -525,7 +526,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
|
|||||||
$this->assertSame(5 * 1024 * 1024, $udfController->getMaximumAllowedEmailAttachmentSize());
|
$this->assertSame(5 * 1024 * 1024, $udfController->getMaximumAllowedEmailAttachmentSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getParseByteSizeStringTestValues()
|
public static function getParseByteSizeStringTestValues()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
['9846', 9846],
|
['9846', 9846],
|
||||||
@ -549,16 +550,14 @@ class UserDefinedFormControllerTest extends FunctionalTest
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
#[DataProvider('getParseByteSizeStringTestValues')]
|
||||||
* @dataProvider getParseByteSizeStringTestValues
|
|
||||||
*/
|
|
||||||
public function testParseByteSizeString($input, $expectedOutput)
|
public function testParseByteSizeString($input, $expectedOutput)
|
||||||
{
|
{
|
||||||
$controller = new SizeStringTestableController(); // extends UserDefinedFormController
|
$controller = new SizeStringTestableController(); // extends UserDefinedFormController
|
||||||
$this->assertSame($expectedOutput, $controller->convertSizeStringToBytes($input));
|
$this->assertSame($expectedOutput, $controller->convertSizeStringToBytes($input));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getParseByteSizeStringTestBadValues()
|
public static function getParseByteSizeStringTestBadValues()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
['1234b'],
|
['1234b'],
|
||||||
@ -572,9 +571,9 @@ class UserDefinedFormControllerTest extends FunctionalTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider getParseByteSizeStringTestBadValues
|
|
||||||
* @expectedException \InvalidArgumentException
|
* @expectedException \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
|
#[DataProvider('getParseByteSizeStringTestBadValues')]
|
||||||
public function testParseByteSizeStringBadValuesThrowException($input)
|
public function testParseByteSizeStringBadValuesThrowException($input)
|
||||||
{
|
{
|
||||||
$this->expectException('\InvalidArgumentException');
|
$this->expectException('\InvalidArgumentException');
|
||||||
@ -582,7 +581,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
|
|||||||
$controller->convertSizeStringToBytes($input);
|
$controller->convertSizeStringToBytes($input);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function provideValidEmailsToArray()
|
public static function provideValidEmailsToArray()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[[], [null]],
|
[[], [null]],
|
||||||
@ -600,9 +599,9 @@ class UserDefinedFormControllerTest extends FunctionalTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideValidEmailsToArray
|
|
||||||
* Test that provided email is valid
|
* Test that provided email is valid
|
||||||
*/
|
*/
|
||||||
|
#[DataProvider('provideValidEmailsToArray')]
|
||||||
public function testValidEmailsToArray(array $expectedOutput, array $input)
|
public function testValidEmailsToArray(array $expectedOutput, array $input)
|
||||||
{
|
{
|
||||||
$class = new ReflectionClass(UserDefinedFormController::class);
|
$class = new ReflectionClass(UserDefinedFormController::class);
|
||||||
|
@ -8,6 +8,7 @@ use SilverStripe\Dev\SapphireTest;
|
|||||||
use SilverStripe\UserForms\Form\UserFormsRequiredFields;
|
use SilverStripe\UserForms\Form\UserFormsRequiredFields;
|
||||||
use SilverStripe\UserForms\Model\UserDefinedForm;
|
use SilverStripe\UserForms\Model\UserDefinedForm;
|
||||||
use SilverStripe\UserForms\Form\UserForm;
|
use SilverStripe\UserForms\Form\UserForm;
|
||||||
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
|
|
||||||
class UserFormsRequiredFieldsTest extends SapphireTest
|
class UserFormsRequiredFieldsTest extends SapphireTest
|
||||||
{
|
{
|
||||||
@ -29,7 +30,7 @@ class UserFormsRequiredFieldsTest extends SapphireTest
|
|||||||
$this->assertInstanceOf(UserFormsRequiredFields::class, $validator, 'Uses UserFormsRequiredFields validator');
|
$this->assertInstanceOf(UserFormsRequiredFields::class, $validator, 'Uses UserFormsRequiredFields validator');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataProviderValidationOfConditionalRequiredFields()
|
public static function dataProviderValidationOfConditionalRequiredFields()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'Passes when non-conditional required field has a value' => [
|
'Passes when non-conditional required field has a value' => [
|
||||||
@ -62,8 +63,8 @@ class UserFormsRequiredFieldsTest extends SapphireTest
|
|||||||
/**
|
/**
|
||||||
* @param $data
|
* @param $data
|
||||||
* @param $expected
|
* @param $expected
|
||||||
* @dataProvider dataProviderValidationOfConditionalRequiredFields
|
|
||||||
*/
|
*/
|
||||||
|
#[DataProvider('dataProviderValidationOfConditionalRequiredFields')]
|
||||||
public function testValidationOfConditionalRequiredFields($data, $expected)
|
public function testValidationOfConditionalRequiredFields($data, $expected)
|
||||||
{
|
{
|
||||||
$page = $this->objFromFixture(UserDefinedForm::class, 'required-custom-rules-form');
|
$page = $this->objFromFixture(UserDefinedForm::class, 'required-custom-rules-form');
|
||||||
@ -78,7 +79,7 @@ class UserFormsRequiredFieldsTest extends SapphireTest
|
|||||||
$this->assertEquals($expected, $validator->php($data));
|
$this->assertEquals($expected, $validator->php($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataProviderValidationOfNestedConditionalRequiredFields()
|
public static function dataProviderValidationOfNestedConditionalRequiredFields()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'Fails when non-conditional required field is empty' => [[], false],
|
'Fails when non-conditional required field is empty' => [[], false],
|
||||||
@ -133,8 +134,8 @@ class UserFormsRequiredFieldsTest extends SapphireTest
|
|||||||
/**
|
/**
|
||||||
* @param string $data
|
* @param string $data
|
||||||
* @param array $expected
|
* @param array $expected
|
||||||
* @dataProvider dataProviderValidationOfNestedConditionalRequiredFields
|
|
||||||
*/
|
*/
|
||||||
|
#[DataProvider('dataProviderValidationOfNestedConditionalRequiredFields')]
|
||||||
public function testValidationOfNestedConditionalRequiredFields($data, $expected)
|
public function testValidationOfNestedConditionalRequiredFields($data, $expected)
|
||||||
{
|
{
|
||||||
$page = $this->objFromFixture(UserDefinedForm::class, 'required-nested-custom-rules-form');
|
$page = $this->objFromFixture(UserDefinedForm::class, 'required-nested-custom-rules-form');
|
||||||
|
@ -4,6 +4,7 @@ namespace SilverStripe\UserForms\Tests\Model;
|
|||||||
|
|
||||||
use SilverStripe\Dev\SapphireTest;
|
use SilverStripe\Dev\SapphireTest;
|
||||||
use SilverStripe\UserForms\Model\EditableCustomRule;
|
use SilverStripe\UserForms\Model\EditableCustomRule;
|
||||||
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class EditableCustomRulesTest
|
* Class EditableCustomRulesTest
|
||||||
@ -61,7 +62,7 @@ class EditableCustomRuleTest extends SapphireTest
|
|||||||
$this->assertSame('userform.field.hide', $rule1->toggleDisplayEvent('hide', true));
|
$this->assertSame('userform.field.hide', $rule1->toggleDisplayEvent('hide', true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataProviderValidateAgainstFormData()
|
public static function dataProviderValidateAgainstFormData()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'IsNotBlank with blank value' =>
|
'IsNotBlank with blank value' =>
|
||||||
@ -114,8 +115,8 @@ class EditableCustomRuleTest extends SapphireTest
|
|||||||
/**
|
/**
|
||||||
* Test that methods are returned for manipulating the presence of the "hide" CSS class depending
|
* Test that methods are returned for manipulating the presence of the "hide" CSS class depending
|
||||||
* on whether the field should be hidden or shown
|
* on whether the field should be hidden or shown
|
||||||
* @dataProvider dataProviderValidateAgainstFormData
|
|
||||||
*/
|
*/
|
||||||
|
#[DataProvider('dataProviderValidateAgainstFormData')]
|
||||||
public function testValidateAgainstFormData($condition, $targetValue, $value, $expected)
|
public function testValidateAgainstFormData($condition, $targetValue, $value, $expected)
|
||||||
{
|
{
|
||||||
$rule1 = $this->objFromFixture(EditableCustomRule::class, 'rule1');
|
$rule1 = $this->objFromFixture(EditableCustomRule::class, 'rule1');
|
||||||
|
@ -59,7 +59,7 @@ class EditableLiteralFieldTest extends SapphireTest
|
|||||||
public function testLiteralFieldHasUpdateFormFieldMethodCalled()
|
public function testLiteralFieldHasUpdateFormFieldMethodCalled()
|
||||||
{
|
{
|
||||||
$field = $this->getMockBuilder(EditableLiteralField::class)
|
$field = $this->getMockBuilder(EditableLiteralField::class)
|
||||||
->setMethods(array('doUpdateFormField'))
|
->onlyMethods(array('doUpdateFormField'))
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$field->expects($this->once())->method('doUpdateFormField');
|
$field->expects($this->once())->method('doUpdateFormField');
|
||||||
|
@ -15,6 +15,7 @@ use SilverStripe\UserForms\Model\EditableFormField\EditableOption;
|
|||||||
use SilverStripe\UserForms\Model\EditableFormField\EditableRadioField;
|
use SilverStripe\UserForms\Model\EditableFormField\EditableRadioField;
|
||||||
use SilverStripe\UserForms\Model\EditableFormField\EditableTextField;
|
use SilverStripe\UserForms\Model\EditableFormField\EditableTextField;
|
||||||
use SilverStripe\UserForms\Model\EditableCustomRule;
|
use SilverStripe\UserForms\Model\EditableCustomRule;
|
||||||
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package userforms
|
* @package userforms
|
||||||
@ -257,7 +258,7 @@ class EditableFormFieldTest extends FunctionalTest
|
|||||||
$this->assertStringContainsString('/images/editabletextfield.png', $field->getIcon());
|
$this->assertStringContainsString('/images/editabletextfield.png', $field->getIcon());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function displayedProvider()
|
public static function displayedProvider()
|
||||||
{
|
{
|
||||||
$one = ['basic_text_name' => 'foobar'];
|
$one = ['basic_text_name' => 'foobar'];
|
||||||
$two = array_merge($one, ['basic_text_name_2' => 'foobar']);
|
$two = array_merge($one, ['basic_text_name_2' => 'foobar']);
|
||||||
@ -301,8 +302,8 @@ class EditableFormFieldTest extends FunctionalTest
|
|||||||
* @param $fieldName
|
* @param $fieldName
|
||||||
* @param $data
|
* @param $data
|
||||||
* @param $expected
|
* @param $expected
|
||||||
* @dataProvider displayedProvider
|
|
||||||
*/
|
*/
|
||||||
|
#[DataProvider('displayedProvider')]
|
||||||
public function testIsDisplayed($fieldName, $data, $expected)
|
public function testIsDisplayed($fieldName, $data, $expected)
|
||||||
{
|
{
|
||||||
/** @var EditableFormField $field */
|
/** @var EditableFormField $field */
|
||||||
|
Loading…
Reference in New Issue
Block a user