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 #329

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
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
}
],
"require": {
"silverstripe/framework": "^4.2",
"php": "^7.3 || ^8.0",
"silverstripe/framework": "^4.10",
"colymba/gridfield-bulk-editing-tools": "^3.0.0-beta4"
},
"suggest": {
"ezyang/htmlpurifier": "Standards compliant HTML filter written in PHP",
"silverstripe/cms": "The SilverStripe Content Management System"
},
"require-dev": {
"sminnee/phpunit": "^5.7",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.0"
},
"extra": {
Expand Down
9 changes: 5 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,8 +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">src/</directory>
Expand Down
6 changes: 3 additions & 3 deletions tests/CommentingControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CommentingControllerTest extends FunctionalTest

protected $securityEnabled;

protected function tearDown()
protected function tearDown(): void
{
if ($this->securityEnabled) {
SecurityToken::inst()->enable();
Expand All @@ -41,7 +41,7 @@ protected function tearDown()
parent::tearDown();
}

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->securityEnabled = SecurityToken::inst()->is_enabled();
Expand Down Expand Up @@ -194,7 +194,7 @@ public function testRSS()
// specific page
$response = $this->get('comments/rss/SilverStripe-Comments-Tests-Stubs-CommentableItem/'.$item->ID);
$this->assertEquals(1, substr_count($response->getBody(), "<item>"));
$this->assertContains('<dc:creator>FA</dc:creator>', $response->getBody());
$this->assertStringContainsString('<dc:creator>FA</dc:creator>', $response->getBody());

// test accessing comments on a type that doesn't exist
$response = $this->get('comments/rss/Fake');
Expand Down
30 changes: 15 additions & 15 deletions tests/CommentsExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CommentsExtensionTest extends FunctionalTest
],
];

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

Expand Down Expand Up @@ -262,44 +262,44 @@ public function testCommentsForm()
$item = $this->objFromFixture(CommentableItem::class, 'first');

// The comments form is HTML to do assertions by contains
$cf = $item->CommentsForm();
$cf = (string) $item->CommentsForm();
$expected = '/comments/CommentsForm/" method="post" enctype="application/x-www-form-urlencoded">';

$this->assertContains($expected, $cf);
$this->assertContains('<h4>Post your comment</h4>', $cf);
$this->assertStringContainsString($expected, $cf);
$this->assertStringContainsString('<h4>Post your comment</h4>', $cf);
// check the comments form exists
$expected = '<input type="text" name="Name"';
$this->assertContains($expected, $cf);
$this->assertStringContainsString($expected, $cf);

$expected = '<input type="email" name="Email"';
$this->assertContains($expected, $cf);
$this->assertStringContainsString($expected, $cf);

$expected = '<input type="text" name="URL"';
$this->assertContains($expected, $cf);
$this->assertStringContainsString($expected, $cf);

$expected = '<input type="hidden" name="ParentID"';
$this->assertContains($expected, $cf);
$this->assertStringContainsString($expected, $cf);

$expected = '<textarea name="Comment"';
$this->assertContains($expected, $cf);
$this->assertStringContainsString($expected, $cf);

$expected = '<input type="submit" name="action_doPostComment" value="Post" class="action"';
$this->assertContains($expected, $cf);
$this->assertStringContainsString($expected, $cf);

$expected = '/comments/spam/';
$this->assertContains($expected, $cf);
$this->assertStringContainsString($expected, $cf);

$expected = '<p>Reply to firstComA 1</p>';
$this->assertContains($expected, $cf);
$this->assertStringContainsString($expected, $cf);

$expected = '/comments/delete';
$this->assertContains($expected, $cf);
$this->assertStringContainsString($expected, $cf);

$expected = '<p>Reply to firstComA 2</p>';
$this->assertContains($expected, $cf);
$this->assertStringContainsString($expected, $cf);

$expected = '<p>Reply to firstComA 3</p>';
$this->assertContains($expected, $cf);
$this->assertStringContainsString($expected, $cf);
}

public function testAttachedToSiteTree()
Expand Down
20 changes: 10 additions & 10 deletions tests/CommentsGridFieldActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CommentsGridFieldActionTest extends SapphireTest
/** @var Form */
protected $form;

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->list = new DataList(Team::class);
Expand Down Expand Up @@ -96,27 +96,27 @@ public function testGetColumnContent()
$record->write();
$recordID = $record->ID;
$html = $action->getColumnContent($this->gridField, $record, Comment::class);
$this->assertContains('data-url="admin/comments/mockform/field/testfield', $html);
$this->assertStringContainsString('data-url="admin/comments/mockform/field/testfield', $html);

$this->assertContains('value="Spam"', $html);
$this->assertContains('id="action_CustomAction' . $recordID . 'Spam"', $html);
$this->assertStringContainsString('value="Spam"', $html);
$this->assertStringContainsString('id="action_CustomAction' . $recordID . 'Spam"', $html);

$this->assertContains('value="Approve"', $html);
$this->assertContains('id="action_CustomAction' . $recordID . 'Approve"', $html);
$this->assertStringContainsString('value="Approve"', $html);
$this->assertStringContainsString('id="action_CustomAction' . $recordID . 'Approve"', $html);

// If marked as spam, only the approve button should be available
$record->markSpam();
$record->write();
$html = $action->getColumnContent($this->gridField, $record, Comment::class);
$this->assertContains('value="Approve"', $html);
$this->assertNotContains('value="Spam"', $html);
$this->assertStringContainsString('value="Approve"', $html);
$this->assertStringNotContainsString('value="Spam"', $html);

// If marked as spam, only the approve button should be available
$record->markApproved();
$record->write();
$html = $action->getColumnContent($this->gridField, $record, Comment::class);
$this->assertNotContains('value="Approve"', $html);
$this->assertContains('value="Spam"', $html);
$this->assertStringNotContainsString('value="Approve"', $html);
$this->assertStringContainsString('value="Spam"', $html);
}

public function testGetActions()
Expand Down
20 changes: 10 additions & 10 deletions tests/CommentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CommentsTest extends FunctionalTest
CommentableItemDisabled::class,
];

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

Expand Down Expand Up @@ -235,7 +235,7 @@ public function testDeleteComment()
$comment = $this->objFromFixture(Comment::class, 'firstComA');
$commentID = $comment->ID;
$adminComment1Link = $comment->DeleteLink();
$this->assertContains('comments/delete/' . $commentID . '?t=', $adminComment1Link);
$this->assertStringContainsString('comments/delete/' . $commentID . '?t=', $adminComment1Link);

// Test that this link can't be shared / XSS exploited
$this->logInAs('commentadmin2');
Expand Down Expand Up @@ -275,7 +275,7 @@ public function testSpamComment()
$comment = $this->objFromFixture(Comment::class, 'firstComA');
$commentID = $comment->ID;
$adminComment1Link = $comment->SpamLink();
$this->assertContains('comments/spam/' . $commentID . '?t=', $adminComment1Link);
$this->assertStringContainsString('comments/spam/' . $commentID . '?t=', $adminComment1Link);

// Test that this link can't be shared / XSS exploited
$this->logInAs('commentadmin2');
Expand Down Expand Up @@ -318,7 +318,7 @@ public function testHamComment()
$comment = $this->objFromFixture(Comment::class, 'secondComC');
$commentID = $comment->ID;
$adminComment1Link = $comment->HamLink();
$this->assertContains('comments/ham/' . $commentID . '?t=', $adminComment1Link);
$this->assertStringContainsString('comments/ham/' . $commentID . '?t=', $adminComment1Link);

// Test that this link can't be shared / XSS exploited
$this->logInAs('commentadmin2');
Expand Down Expand Up @@ -361,7 +361,7 @@ public function testApproveComment()
$comment = $this->objFromFixture(Comment::class, 'secondComB');
$commentID = $comment->ID;
$adminComment1Link = $comment->ApproveLink();
$this->assertContains('comments/approve/' . $commentID . '?t=', $adminComment1Link);
$this->assertStringContainsString('comments/approve/' . $commentID . '?t=', $adminComment1Link);

// Test that this link can't be shared / XSS exploited
$this->logInAs('commentadmin2');
Expand Down Expand Up @@ -775,30 +775,30 @@ public function testLinks()
$method = $this->getMethod('ActionLink');

// test with starts of strings and tokens and salts change each time
$this->assertContains(
$this->assertStringContainsString(
'/comments/theaction/' . $comment->ID,
$method->invokeArgs($comment, array('theaction'))
);

$this->assertContains(
$this->assertStringContainsString(
'/comments/delete/' . $comment->ID,
$comment->DeleteLink()
);

$this->assertContains(
$this->assertStringContainsString(
'/comments/spam/' . $comment->ID,
$comment->SpamLink()
);

$comment->markSpam();
$this->assertContains(
$this->assertStringContainsString(
'/comments/ham/' . $comment->ID,
$comment->HamLink()
);

//markApproved
$comment->markUnapproved();
$this->assertContains(
$this->assertStringContainsString(
'/comments/approve/' . $comment->ID,
$comment->ApproveLink()
);
Expand Down