API phpunit 9 support

This commit is contained in:
Steve Boyd 2021-11-02 09:52:58 +13:00
parent 60931791fb
commit 40bd88e81c
16 changed files with 67 additions and 78 deletions

View File

@ -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"

View File

@ -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": {

View File

@ -1,7 +1,9 @@
<phpunit bootstrap="vendor/silverstripe/cms/tests/bootstrap.php" colors="true">
<testsuite name="Default">
<directory>tests/</directory>
</testsuite>
<testsuites>
<testsuite name="Default">
<directory>tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">code/</directory>

View File

@ -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');

View File

@ -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);
}
}
}

View File

@ -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()

View File

@ -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 <b>HTML</b>';
$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('<p>Here is my form</p><p>$UserDefinedForm</p><p>Thank you for filling it out</p>', $html);
$this->assertStringContainsString('<p>Here is my form</p><p>$UserDefinedForm</p><p>Thank you for filling it out</p>', $html);
// And the form in the $From area
$this->assertArrayHasKey(0, $parser->getBySelector('form#UserForm_Form_' . $form->ID));
// check for the input

View File

@ -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']);

View File

@ -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()

View File

@ -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();
}

View File

@ -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());
}

View File

@ -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()

View File

@ -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()

View File

@ -20,21 +20,19 @@ class EmailRecipientTest extends SapphireTest
$recipient->EmailBodyHtml = '<p>Some email content. About us: [sitetree_link,id=' . $page->ID . '].</p>';
$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();

View File

@ -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;

View File

@ -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('<p>Here is my form</p><form', $body);
$this->assertContains('</form><p>Thank you for filling it out</p>', $body);
$this->assertStringContainsString('<p>Here is my form</p><form', $body);
$this->assertStringContainsString('</form><p>Thank you for filling it out</p>', $body);
$this->assertNotContains('<p>$UserDefinedForm</p>', $body);
$this->assertNotContains('<p></p>', $body);
$this->assertNotContains('</p><p>Thank you for filling it out</p>', $body);
$this->assertStringNotContainsString('<p>$UserDefinedForm</p>', $body);
$this->assertStringNotContainsString('<p></p>', $body);
$this->assertStringNotContainsString('</p><p>Thank you for filling it out</p>', $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(