Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API phpunit 9 support #1117

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
env:
- DB=PGSQL
maxime-rainville marked this conversation as resolved.
Show resolved Hide resolved
- REQUIRE_INSTALLER="4.6.x-dev"
- PHPUNIT_TEST=1
- php: 7.3
env:
- DB=MYSQL
- REQUIRE_INSTALLER="4.7.x-dev"
- DB=PGSQL
- REQUIRE_INSTALLER="4.x-dev"
- PHPUNIT_TEST=1
- PHPCS_TEST=1
- php: 7.3
- php: 7.4
env:
- DB=MYSQL
- REQUIRE_INSTALLER="4.7.x-dev"
- BEHAT_TEST=1
- BEHAT_SUITE="userforms"
- REQUIRE_INSTALLER="4.x-dev"
- PHPUNIT_COVERAGE_TEST=1
- php: 7.4
env:
- DB=MYSQL
- REQUIRE_INSTALLER="4.x-dev"
- PHPUNIT_COVERAGE_TEST=1
- php: nightly
- BEHAT_TEST=1
- BEHAT_SUITE="userforms"
- php: 8.0
env:
- DB=MYSQL
- REQUIRE_INSTALLER="4.x-dev"
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@
}
],
"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",
"silverstripe/versioned": "^1.0",
"silverstripe/mimevalidator": "^2.0"
},
"require-dev": {
"sminnee/phpunit": "^5.7",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.0"
},
"autoload": {
Expand Down
8 changes: 5 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
2 changes: 1 addition & 1 deletion tests/Extension/UserFormFieldEditorExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions tests/Model/Recipient/UserFormRecipientItemRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public function testShowInReportsAffectsPreview()
$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);
}
}
}
10 changes: 5 additions & 5 deletions tests/php/Control/UserDefinedFormAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class UserDefinedFormAdminTest extends FunctionalTest
{
protected static $fixture_file = '../UserFormsTest.yml';

protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down Expand Up @@ -401,7 +401,7 @@ public function testGetFolderPermissionValidRequest()
$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]));
Expand All @@ -410,7 +410,7 @@ public function testGetFolderPermissionValidRequest()
$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]));
Expand All @@ -419,7 +419,7 @@ public function testGetFolderPermissionValidRequest()
$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');
Expand All @@ -429,7 +429,7 @@ public function testGetFolderPermissionValidRequest()
$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()
Expand Down
22 changes: 11 additions & 11 deletions tests/php/Control/UserDefinedFormControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class UserDefinedFormControllerTest extends FunctionalTest

protected static $disable_themes = true;

protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand All @@ -49,7 +49,7 @@ protected function setUp()
Config::modify()->merge(SSViewer::class, 'themes', ['simple', '$default']);
}

public function tearDown()
protected function tearDown(): void
{
TestAssetStore::reset();
parent::tearDown();
Expand Down Expand Up @@ -105,11 +105,11 @@ public function testProcess()
$this->assertEmailSent('[email protected]', '[email protected]', 'Email Subject');
$nohtml = $this->findEmail('[email protected]', '[email protected]', '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('[email protected]', '[email protected]', 'Email Subject');
Expand All @@ -123,7 +123,7 @@ public function testProcess()
// 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
Expand All @@ -142,7 +142,7 @@ public function testValidation()
$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);
Expand All @@ -151,15 +151,15 @@ public function testValidation()
'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);
/** @var HTTPResponse $response */
$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()
Expand All @@ -172,7 +172,7 @@ public function testFinished()

$response = $this->get($form->URLSegment.'/finished');

$this->assertContains($form->OnCompleteMessage, $response->getBody());
$this->assertStringContainsString($form->OnCompleteMessage, $response->getBody());
}

public function testAppendingFinished()
Expand All @@ -185,7 +185,7 @@ public function testAppendingFinished()

$response = $this->get($form->URLSegment.'/finished');

$this->assertNotContains($form->OnCompleteMessage, $response->getBody());
$this->assertStringNotContainsString($form->OnCompleteMessage, $response->getBody());
}

public function testForm()
Expand Down Expand Up @@ -320,7 +320,7 @@ public function testRenderingIntoTemplateWithDisabledInterpolation()
$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
Expand Down
8 changes: 3 additions & 5 deletions tests/php/Model/EditableCustomRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testBuildExpression()
$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');
Expand All @@ -34,7 +34,7 @@ public function testBuildExpression()
$this->assertNotEmpty($result2['operation']);

//Check for greater than sign
$this->assertContains('>', $result2['operation']);
$this->assertStringContainsString('>', $result2['operation']);
}

/**
Expand Down Expand Up @@ -133,11 +133,9 @@ public function testValidateAgainstFormData($condition, $targetValue, $value, $e
);
}

/**
* @expectedException LogicException
*/
public function testValidateAgainstFormDataWithNonSenseRule()
{
$this->expectException(\LogicException::class);
$rule1 = $this->objFromFixture(EditableCustomRule::class, 'rule1');
$rule1->ConditionOption = 'NonSenseRule';
$rule1->validateAgainstFormData(['CountrySelection' => 'booya']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function testGetIcon()
{
$field = new EditableCountryDropdownField;

$this->assertContains('/images/editabledropdown.png', $field->getIcon());
$this->assertStringContainsString('/images/editabledropdown.png', $field->getIcon());
}

public function testAllowEmptyTitle()
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Model/EditableFormField/EditableFileFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -48,7 +48,7 @@ public function testValidateFileSizeFieldValue()
{

$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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
class EditableLiteralFieldTest extends SapphireTest
{
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$cmsConfig = HTMLEditorConfig::get('cms');
Expand Down Expand Up @@ -48,11 +48,11 @@ public function testHideLabel()
'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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testValidateAddsErrorWhenMinValueIsGreaterThanMaxValue()

$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()
Expand Down
8 changes: 4 additions & 4 deletions tests/php/Model/EditableFormFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ public function testUniqueName()
$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);
}

Expand Down Expand Up @@ -238,7 +238,7 @@ public function testGetIcon()
{
$field = new EditableTextField;

$this->assertContains('/images/editabletextfield.png', $field->getIcon());
$this->assertStringContainsString('/images/editabletextfield.png', $field->getIcon());
}

public function displayedProvider()
Expand Down
10 changes: 4 additions & 6 deletions tests/php/Model/Recipient/EmailRecipientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,19 @@ public function testShortcodesAreRenderedInEmailPreviewContent()
$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 = '[email protected]';
$recipient->write();
Expand Down
Loading