From 40bd88e81c800e11bd2cf69c0b769fa8be0c13e6 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 2 Nov 2021 09:52:58 +1300 Subject: [PATCH] API phpunit 9 support --- .travis.yml | 32 +++++++------------ composer.json | 5 +-- phpunit.xml.dist | 8 +++-- .../UserFormFieldEditorExtensionTest.php | 2 +- .../UserFormRecipientItemRequestTest.php | 4 +-- .../php/Control/UserDefinedFormAdminTest.php | 10 +++--- .../Control/UserDefinedFormControllerTest.php | 22 ++++++------- tests/php/Model/EditableCustomRuleTest.php | 8 ++--- .../EditableCountryDropdownFieldTest.php | 2 +- .../EditableFileFieldTest.php | 4 +-- .../EditableLiteralFieldTest.php | 6 ++-- .../EditableNumericFieldTest.php | 2 +- tests/php/Model/EditableFormFieldTest.php | 8 ++--- .../Model/Recipient/EmailRecipientTest.php | 10 +++--- tests/php/Model/SubmittedFileFieldTest.php | 6 ++-- tests/php/Model/UserDefinedFormTest.php | 16 +++++----- 16 files changed, 67 insertions(+), 78 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3558479..82e46b7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,39 +8,29 @@ import: jobs: include: - - php: 7.4 + - php: 7.3 env: - DB=MYSQL - - REQUIRE_INSTALLER="4.6.x-dev" + - REQUIRE_INSTALLER="4.x-dev" - NPM_TEST=1 - - php: 7.1 - env: - - DB=MYSQL - - REQUIRE_INSTALLER="4.6.x-dev" - - PHPUNIT_TEST=1 - - php: 7.2 + - php: 7.3 env: - DB=PGSQL - - REQUIRE_INSTALLER="4.6.x-dev" - - PHPUNIT_TEST=1 - - php: 7.3 - env: - - DB=MYSQL - - REQUIRE_INSTALLER="4.7.x-dev" + - REQUIRE_INSTALLER="4.x-dev" - PHPUNIT_TEST=1 - PHPCS_TEST=1 - - php: 7.3 - env: - - DB=MYSQL - - REQUIRE_INSTALLER="4.7.x-dev" - - BEHAT_TEST=1 - - BEHAT_SUITE="userforms" - php: 7.4 env: - DB=MYSQL - REQUIRE_INSTALLER="4.x-dev" - PHPUNIT_COVERAGE_TEST=1 - - php: nightly + - php: 7.4 + env: + - DB=MYSQL + - REQUIRE_INSTALLER="4.x-dev" + - BEHAT_TEST=1 + - BEHAT_SUITE="userforms" + - php: 8.0 env: - DB=MYSQL - REQUIRE_INSTALLER="4.x-dev" diff --git a/composer.json b/composer.json index 346e9b2..d5afa19 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ } ], "require": { - "php": ">=7.1", + "php": "^7.3 || ^8.0", + "silverstripe/framework": "^4.10", "silverstripe/cms": "^4.6", "symbiote/silverstripe-gridfieldextensions": "^3.1", "silverstripe/segment-field": "^2.0", @@ -38,7 +39,7 @@ "silverstripe/mimevalidator": "^2.0" }, "require-dev": { - "sminnee/phpunit": "^5.7", + "phpunit/phpunit": "^9.5", "squizlabs/php_codesniffer": "^3.0" }, "autoload": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 50a2f92..777d772 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,9 @@ - - tests/ - + + + tests/ + + code/ diff --git a/tests/Extension/UserFormFieldEditorExtensionTest.php b/tests/Extension/UserFormFieldEditorExtensionTest.php index 18e29a3..067d6e4 100644 --- a/tests/Extension/UserFormFieldEditorExtensionTest.php +++ b/tests/Extension/UserFormFieldEditorExtensionTest.php @@ -15,7 +15,7 @@ class UserFormFieldEditorExtensionTest extends SapphireTest UserFormBlockStub::class, ]; - protected function setUp() + protected function setUp(): void { parent::setUp(); $page = $this->objFromFixture(UserDefinedForm::class, 'page'); diff --git a/tests/Model/Recipient/UserFormRecipientItemRequestTest.php b/tests/Model/Recipient/UserFormRecipientItemRequestTest.php index 65b20b3..ef8e173 100644 --- a/tests/Model/Recipient/UserFormRecipientItemRequestTest.php +++ b/tests/Model/Recipient/UserFormRecipientItemRequestTest.php @@ -38,10 +38,10 @@ class UserFormRecipientItemRequestTest extends SapphireTest $request = new UserFormRecipientItemRequest(null, null, $recipient, null, ''); $html = $request->preview()->getValue(); foreach ($falseClasses as $class) { - $this->assertNotContains('My' . $class, $html); + $this->assertStringNotContainsString('My' . $class, $html); } foreach ($trueClasses as $class) { - $this->assertContains('My' . $class, $html); + $this->assertStringContainsString('My' . $class, $html); } } } diff --git a/tests/php/Control/UserDefinedFormAdminTest.php b/tests/php/Control/UserDefinedFormAdminTest.php index 0f054ea..1effe75 100644 --- a/tests/php/Control/UserDefinedFormAdminTest.php +++ b/tests/php/Control/UserDefinedFormAdminTest.php @@ -38,7 +38,7 @@ class UserDefinedFormAdminTest extends FunctionalTest { protected static $fixture_file = '../UserFormsTest.yml'; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -401,7 +401,7 @@ class UserDefinedFormAdminTest extends FunctionalTest $response->getStatusCode(), 'Valid request is successfull' ); - $this->assertContains('Unrestricted access, uploads will be visible to anyone', $response->getBody()); + $this->assertStringContainsString('Unrestricted access, uploads will be visible to anyone', $response->getBody()); $folder = Folder::find('restricted-folder'); $response = $this->get($url . http_build_query(['FolderID' => 0])); @@ -410,7 +410,7 @@ class UserDefinedFormAdminTest extends FunctionalTest $response->getStatusCode(), 'Valid request for root folder is successful' ); - $this->assertContains('Unrestricted access, uploads will be visible to anyone', $response->getBody()); + $this->assertStringContainsString('Unrestricted access, uploads will be visible to anyone', $response->getBody()); $folder = Folder::find('restricted-folder'); $response = $this->get($url . http_build_query(['FolderID' => $folder->ID])); @@ -419,7 +419,7 @@ class UserDefinedFormAdminTest extends FunctionalTest $response->getStatusCode(), 'Valid request for root folder is successful' ); - $this->assertContains('Restricted access, uploads will be visible to logged-in users ', $response->getBody()); + $this->assertStringContainsString('Restricted access, uploads will be visible to logged-in users ', $response->getBody()); $this->logInWithPermission('ADMIN'); $adminOnlyFolder = Folder::find('admin-only'); @@ -429,7 +429,7 @@ class UserDefinedFormAdminTest extends FunctionalTest $response->getStatusCode(), 'Valid request for folder restricted to group is successful' ); - $this->assertContains('Restricted access, uploads will be visible to the following groups: Administrators', $response->getBody()); + $this->assertStringContainsString('Restricted access, uploads will be visible to the following groups: Administrators', $response->getBody()); } public function testGetFormSubmissionFolder() diff --git a/tests/php/Control/UserDefinedFormControllerTest.php b/tests/php/Control/UserDefinedFormControllerTest.php index b907027..a198f41 100644 --- a/tests/php/Control/UserDefinedFormControllerTest.php +++ b/tests/php/Control/UserDefinedFormControllerTest.php @@ -39,7 +39,7 @@ class UserDefinedFormControllerTest extends FunctionalTest protected static $disable_themes = true; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -49,7 +49,7 @@ class UserDefinedFormControllerTest extends FunctionalTest Config::modify()->merge(SSViewer::class, 'themes', ['simple', '$default']); } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown(); @@ -105,11 +105,11 @@ class UserDefinedFormControllerTest extends FunctionalTest $this->assertEmailSent('nohtml@example.com', 'no-reply@example.com', 'Email Subject'); $nohtml = $this->findEmail('nohtml@example.com', 'no-reply@example.com', 'Email Subject'); - $this->assertContains('Basic Text Field: Basic Value', $nohtml['Content'], 'Email contains no html'); + $this->assertStringContainsString('Basic Text Field: Basic Value', $nohtml['Content'], 'Email contains no html'); // submitted html tags are not escaped because the email is being sent as text/plain $value = 'My body text Basic Value HTML'; - $this->assertContains($value, $nohtml['Content'], 'Email contains the merge field value'); + $this->assertStringContainsString($value, $nohtml['Content'], 'Email contains the merge field value'); // no data $this->assertEmailSent('nodata@example.com', 'no-reply@example.com', 'Email Subject'); @@ -123,7 +123,7 @@ class UserDefinedFormControllerTest extends FunctionalTest // check to see if the user was redirected (301) $this->assertEquals($response->getStatusCode(), 302); $location = $response->getHeader('Location'); - $this->assertContains('finished', $location); + $this->assertStringContainsString('finished', $location); $this->assertStringEndsWith('#uff', $location); // check that multiple email addresses are supported in to and from @@ -142,7 +142,7 @@ class UserDefinedFormControllerTest extends FunctionalTest $this->get($form->URLSegment); /** @var HTTPResponse $response */ $response = $this->submitForm('UserForm_Form_' . $form->ID, null, []); - $this->assertContains('This field is required', $response->getBody()); + $this->assertStringContainsString('This field is required', $response->getBody()); // Post with all fields, but invalid email $this->get($form->URLSegment); @@ -151,7 +151,7 @@ class UserDefinedFormControllerTest extends FunctionalTest 'required-email' => 'invalid', 'required-text' => 'bob' ]); - $this->assertContains('Please enter an email address', $response->getBody()); + $this->assertStringContainsString('Please enter an email address', $response->getBody()); // Post with only required $this->get($form->URLSegment); @@ -159,7 +159,7 @@ class UserDefinedFormControllerTest extends FunctionalTest $response = $this->submitForm('UserForm_Form_' . $form->ID, null, [ 'required-text' => 'bob' ]); - $this->assertContains("Thanks, we've received your submission.", $response->getBody()); + $this->assertStringContainsString("Thanks, we've received your submission.", $response->getBody()); } public function testFinished() @@ -172,7 +172,7 @@ class UserDefinedFormControllerTest extends FunctionalTest $response = $this->get($form->URLSegment.'/finished'); - $this->assertContains($form->OnCompleteMessage, $response->getBody()); + $this->assertStringContainsString($form->OnCompleteMessage, $response->getBody()); } public function testAppendingFinished() @@ -185,7 +185,7 @@ class UserDefinedFormControllerTest extends FunctionalTest $response = $this->get($form->URLSegment.'/finished'); - $this->assertNotContains($form->OnCompleteMessage, $response->getBody()); + $this->assertStringNotContainsString($form->OnCompleteMessage, $response->getBody()); } public function testForm() @@ -320,7 +320,7 @@ class UserDefinedFormControllerTest extends FunctionalTest $parser = new CSSContentParser($html); // Assert Content has been rendered with the shortcode in place - $this->assertContains('

Here is my form

$UserDefinedForm

Thank you for filling it out

', $html); + $this->assertStringContainsString('

Here is my form

$UserDefinedForm

Thank you for filling it out

', $html); // And the form in the $From area $this->assertArrayHasKey(0, $parser->getBySelector('form#UserForm_Form_' . $form->ID)); // check for the input diff --git a/tests/php/Model/EditableCustomRuleTest.php b/tests/php/Model/EditableCustomRuleTest.php index c87b949..e717cd3 100644 --- a/tests/php/Model/EditableCustomRuleTest.php +++ b/tests/php/Model/EditableCustomRuleTest.php @@ -23,7 +23,7 @@ class EditableCustomRuleTest extends SapphireTest $this->assertNotEmpty($result1['operation']); //Check for equals sign - $this->assertContains('==', $result1['operation']); + $this->assertStringContainsString('==', $result1['operation']); /** @var EditableCustomRule $rule2 */ $rule2 = $this->objFromFixture(EditableCustomRule::class, 'rule2'); @@ -34,7 +34,7 @@ class EditableCustomRuleTest extends SapphireTest $this->assertNotEmpty($result2['operation']); //Check for greater than sign - $this->assertContains('>', $result2['operation']); + $this->assertStringContainsString('>', $result2['operation']); } /** @@ -133,11 +133,9 @@ class EditableCustomRuleTest extends SapphireTest ); } - /** - * @expectedException LogicException - */ public function testValidateAgainstFormDataWithNonSenseRule() { + $this->expectException(\LogicException::class); $rule1 = $this->objFromFixture(EditableCustomRule::class, 'rule1'); $rule1->ConditionOption = 'NonSenseRule'; $rule1->validateAgainstFormData(['CountrySelection' => 'booya']); diff --git a/tests/php/Model/EditableFormField/EditableCountryDropdownFieldTest.php b/tests/php/Model/EditableFormField/EditableCountryDropdownFieldTest.php index 4bbd019..4426ead 100644 --- a/tests/php/Model/EditableFormField/EditableCountryDropdownFieldTest.php +++ b/tests/php/Model/EditableFormField/EditableCountryDropdownFieldTest.php @@ -12,7 +12,7 @@ class EditableCountryDropdownFieldTest extends SapphireTest { $field = new EditableCountryDropdownField; - $this->assertContains('/images/editabledropdown.png', $field->getIcon()); + $this->assertStringContainsString('/images/editabledropdown.png', $field->getIcon()); } public function testAllowEmptyTitle() diff --git a/tests/php/Model/EditableFormField/EditableFileFieldTest.php b/tests/php/Model/EditableFormField/EditableFileFieldTest.php index 72b21b0..1b659ac 100644 --- a/tests/php/Model/EditableFormField/EditableFileFieldTest.php +++ b/tests/php/Model/EditableFormField/EditableFileFieldTest.php @@ -22,7 +22,7 @@ class EditableFileFieldTest extends SapphireTest /** * Hold the server default max file size upload limit for later */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -48,7 +48,7 @@ class EditableFileFieldTest extends SapphireTest { $fileField = $this->objFromFixture(EditableFileField::class, 'file-field'); - $this->setExpectedException(ValidationException::class); + $this->expectException(ValidationException::class); $fileField->MaxFileSizeMB = $this->php_max_file_size * 2; $fileField->write(); } diff --git a/tests/php/Model/EditableFormField/EditableLiteralFieldTest.php b/tests/php/Model/EditableFormField/EditableLiteralFieldTest.php index c12f77f..fa27530 100644 --- a/tests/php/Model/EditableFormField/EditableLiteralFieldTest.php +++ b/tests/php/Model/EditableFormField/EditableLiteralFieldTest.php @@ -15,7 +15,7 @@ use SilverStripe\UserForms\Model\EditableFormField\EditableLiteralField; */ class EditableLiteralFieldTest extends SapphireTest { - protected function setUp() + protected function setUp(): void { parent::setUp(); $cmsConfig = HTMLEditorConfig::get('cms'); @@ -48,11 +48,11 @@ class EditableLiteralFieldTest extends SapphireTest 'Title' => 'Test label' ]); - $this->assertContains('Test label', $field->getFormField()->FieldHolder()); + $this->assertStringContainsString('Test label', $field->getFormField()->FieldHolder()); $this->assertEquals('Test label', $field->getFormField()->Title()); $field->HideLabel = true; - $this->assertNotContains('Test label', $field->getFormField()->FieldHolder()); + $this->assertStringNotContainsString('Test label', $field->getFormField()->FieldHolder()); $this->assertEmpty($field->getFormField()->Title()); } diff --git a/tests/php/Model/EditableFormField/EditableNumericFieldTest.php b/tests/php/Model/EditableFormField/EditableNumericFieldTest.php index 035649c..afcd0ad 100644 --- a/tests/php/Model/EditableFormField/EditableNumericFieldTest.php +++ b/tests/php/Model/EditableFormField/EditableNumericFieldTest.php @@ -24,7 +24,7 @@ class EditableNumericFieldTest extends SapphireTest $result = $field->validate(); $this->assertFalse($result->isValid(), 'Validation should fail when min is greater than max'); - $this->assertContains('Minimum length should be less than the maximum length', $result->serialize()); + $this->assertStringContainsString('Minimum length should be less than the maximum length', $result->serialize()); } public function testValidate() diff --git a/tests/php/Model/EditableFormFieldTest.php b/tests/php/Model/EditableFormFieldTest.php index 3058c86..7bda250 100644 --- a/tests/php/Model/EditableFormFieldTest.php +++ b/tests/php/Model/EditableFormFieldTest.php @@ -184,9 +184,9 @@ class EditableFormFieldTest extends FunctionalTest $checkboxField->write(); // Test values are in the expected format - $this->assertRegExp('/^EditableTextField_.+/', $textfield1->Name); - $this->assertRegExp('/^EditableTextField_.+/', $textfield2->Name); - $this->assertRegExp('/^EditableCheckbox_.+/', $checkboxField->Name); + $this->assertMatchesRegularExpression('/^EditableTextField_.+/', $textfield1->Name); + $this->assertMatchesRegularExpression('/^EditableTextField_.+/', $textfield2->Name); + $this->assertMatchesRegularExpression('/^EditableCheckbox_.+/', $checkboxField->Name); $this->assertNotEquals($textfield1->Name, $textfield2->Name); } @@ -238,7 +238,7 @@ class EditableFormFieldTest extends FunctionalTest { $field = new EditableTextField; - $this->assertContains('/images/editabletextfield.png', $field->getIcon()); + $this->assertStringContainsString('/images/editabletextfield.png', $field->getIcon()); } public function displayedProvider() diff --git a/tests/php/Model/Recipient/EmailRecipientTest.php b/tests/php/Model/Recipient/EmailRecipientTest.php index 0de6ae8..481d0cc 100644 --- a/tests/php/Model/Recipient/EmailRecipientTest.php +++ b/tests/php/Model/Recipient/EmailRecipientTest.php @@ -20,21 +20,19 @@ class EmailRecipientTest extends SapphireTest $recipient->EmailBodyHtml = '

Some email content. About us: [sitetree_link,id=' . $page->ID . '].

'; $result = $recipient->getEmailBodyContent(); - $this->assertContains('/about-us/', $result); + $this->assertStringContainsString('/about-us/', $result); $recipient->SendPlain = true; $recipient->EmailBody = 'Some email content. About us: [sitetree_link,id=' . $page->ID . '].'; $result = $recipient->getEmailBodyContent(); - $this->assertContains('/about-us/', $result); + $this->assertStringContainsString('/about-us/', $result); } - /** - * @expectedException \SilverStripe\ORM\ValidationException - * @expectedExceptionMessage "Send email to" address or field is required - */ public function testEmptyRecipientFailsValidation() { + $this->expectException(\SilverStripe\ORM\ValidationException::class); + $this->expectExceptionMessage('"Send email to" address or field is required'); $recipient = new EmailRecipient(); $recipient->EmailFrom = 'test@example.com'; $recipient->write(); diff --git a/tests/php/Model/SubmittedFileFieldTest.php b/tests/php/Model/SubmittedFileFieldTest.php index 91db2f9..397dcc0 100644 --- a/tests/php/Model/SubmittedFileFieldTest.php +++ b/tests/php/Model/SubmittedFileFieldTest.php @@ -11,14 +11,14 @@ use SilverStripe\Versioned\Versioned; class SubmittedFileFieldTest extends SapphireTest { - public function setUp() + protected function setUp(): void { parent::setUp(); TestAssetStore::activate('SubmittedFileFieldTest'); } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); @@ -40,7 +40,7 @@ class SubmittedFileFieldTest extends SapphireTest $submittedFile->ParentID = $submittedForm->ID; $submittedFile->write(); - $this->assertContains('test-SubmittedFileFieldTest', $submittedFile->getFileName(), 'Submitted file is linked'); + $this->assertStringContainsString('test-SubmittedFileFieldTest', $submittedFile->getFileName(), 'Submitted file is linked'); $submittedForm->delete(); $fileId = $file->ID; diff --git a/tests/php/Model/UserDefinedFormTest.php b/tests/php/Model/UserDefinedFormTest.php index 1c0e7b9..6f040f4 100644 --- a/tests/php/Model/UserDefinedFormTest.php +++ b/tests/php/Model/UserDefinedFormTest.php @@ -37,7 +37,7 @@ class UserDefinedFormTest extends FunctionalTest UserDefinedForm::class => [UserFormFieldEditorExtension::class], ]; - protected function setUp() + protected function setUp(): void { parent::setUp(); Email::config()->update('admin_email', 'no-reply@example.com'); @@ -526,12 +526,12 @@ class UserDefinedFormTest extends FunctionalTest $result = $this->get($page->Link()); $body = Convert::nl2os($result->getBody(), ''); // strip out newlines $this->assertFalse($result->isError()); - $this->assertContains('

Here is my form

assertContains('

Thank you for filling it out

', $body); + $this->assertStringContainsString('

Here is my form

assertStringContainsString('

Thank you for filling it out

', $body); - $this->assertNotContains('

$UserDefinedForm

', $body); - $this->assertNotContains('

', $body); - $this->assertNotContains('

Thank you for filling it out

', $body); + $this->assertStringNotContainsString('

$UserDefinedForm

', $body); + $this->assertStringNotContainsString('

', $body); + $this->assertStringNotContainsString('

Thank you for filling it out

', $body); } public function testEmailAddressValidation() @@ -546,8 +546,8 @@ class UserDefinedFormTest extends FunctionalTest $result = $recipient->validate(); $this->assertFalse($result->isValid()); $this->assertNotEmpty($result->getMessages()); - $this->assertContains('filtered.example.com', $result->getMessages()[0]['message']); - $this->assertNotContains('filtered2@example.com', $result->getMessages()[0]['message']); + $this->assertStringContainsString('filtered.example.com', $result->getMessages()[0]['message']); + $this->assertStringNotContainsString('filtered2@example.com', $result->getMessages()[0]['message']); // test valid email addresses pass validation $recipient = $this->objFromFixture(