Merge pull request #329 from creative-commoners/pulls/3/sapphire-test-nine

API phpunit 9 support
This commit is contained in:
Maxime Rainville 2021-11-01 17:52:24 +13:00 committed by GitHub
commit 7eb8ebedf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 46 additions and 44 deletions

View File

@ -13,7 +13,8 @@
} }
], ],
"require": { "require": {
"silverstripe/framework": "^4.2", "php": "^7.3 || ^8.0",
"silverstripe/framework": "^4.10",
"colymba/gridfield-bulk-editing-tools": "^3.0.0-beta4" "colymba/gridfield-bulk-editing-tools": "^3.0.0-beta4"
}, },
"suggest": { "suggest": {
@ -21,7 +22,7 @@
"silverstripe/cms": "The SilverStripe Content Management System" "silverstripe/cms": "The SilverStripe Content Management System"
}, },
"require-dev": { "require-dev": {
"sminnee/phpunit": "^5.7", "phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.0" "squizlabs/php_codesniffer": "^3.0"
}, },
"extra": { "extra": {

View File

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

View File

@ -31,7 +31,7 @@ class CommentingControllerTest extends FunctionalTest
protected $securityEnabled; protected $securityEnabled;
protected function tearDown() protected function tearDown(): void
{ {
if ($this->securityEnabled) { if ($this->securityEnabled) {
SecurityToken::inst()->enable(); SecurityToken::inst()->enable();
@ -41,7 +41,7 @@ class CommentingControllerTest extends FunctionalTest
parent::tearDown(); parent::tearDown();
} }
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->securityEnabled = SecurityToken::inst()->is_enabled(); $this->securityEnabled = SecurityToken::inst()->is_enabled();
@ -194,7 +194,7 @@ class CommentingControllerTest extends FunctionalTest
// specific page // specific page
$response = $this->get('comments/rss/SilverStripe-Comments-Tests-Stubs-CommentableItem/'.$item->ID); $response = $this->get('comments/rss/SilverStripe-Comments-Tests-Stubs-CommentableItem/'.$item->ID);
$this->assertEquals(1, substr_count($response->getBody(), "<item>")); $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 // test accessing comments on a type that doesn't exist
$response = $this->get('comments/rss/Fake'); $response = $this->get('comments/rss/Fake');

View File

@ -32,7 +32,7 @@ class CommentsExtensionTest extends FunctionalTest
], ],
]; ];
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -262,44 +262,44 @@ class CommentsExtensionTest extends FunctionalTest
$item = $this->objFromFixture(CommentableItem::class, 'first'); $item = $this->objFromFixture(CommentableItem::class, 'first');
// The comments form is HTML to do assertions by contains // 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">'; $expected = '/comments/CommentsForm/" method="post" enctype="application/x-www-form-urlencoded">';
$this->assertContains($expected, $cf); $this->assertStringContainsString($expected, $cf);
$this->assertContains('<h4>Post your comment</h4>', $cf); $this->assertStringContainsString('<h4>Post your comment</h4>', $cf);
// check the comments form exists // check the comments form exists
$expected = '<input type="text" name="Name"'; $expected = '<input type="text" name="Name"';
$this->assertContains($expected, $cf); $this->assertStringContainsString($expected, $cf);
$expected = '<input type="email" name="Email"'; $expected = '<input type="email" name="Email"';
$this->assertContains($expected, $cf); $this->assertStringContainsString($expected, $cf);
$expected = '<input type="text" name="URL"'; $expected = '<input type="text" name="URL"';
$this->assertContains($expected, $cf); $this->assertStringContainsString($expected, $cf);
$expected = '<input type="hidden" name="ParentID"'; $expected = '<input type="hidden" name="ParentID"';
$this->assertContains($expected, $cf); $this->assertStringContainsString($expected, $cf);
$expected = '<textarea name="Comment"'; $expected = '<textarea name="Comment"';
$this->assertContains($expected, $cf); $this->assertStringContainsString($expected, $cf);
$expected = '<input type="submit" name="action_doPostComment" value="Post" class="action"'; $expected = '<input type="submit" name="action_doPostComment" value="Post" class="action"';
$this->assertContains($expected, $cf); $this->assertStringContainsString($expected, $cf);
$expected = '/comments/spam/'; $expected = '/comments/spam/';
$this->assertContains($expected, $cf); $this->assertStringContainsString($expected, $cf);
$expected = '<p>Reply to firstComA 1</p>'; $expected = '<p>Reply to firstComA 1</p>';
$this->assertContains($expected, $cf); $this->assertStringContainsString($expected, $cf);
$expected = '/comments/delete'; $expected = '/comments/delete';
$this->assertContains($expected, $cf); $this->assertStringContainsString($expected, $cf);
$expected = '<p>Reply to firstComA 2</p>'; $expected = '<p>Reply to firstComA 2</p>';
$this->assertContains($expected, $cf); $this->assertStringContainsString($expected, $cf);
$expected = '<p>Reply to firstComA 3</p>'; $expected = '<p>Reply to firstComA 3</p>';
$this->assertContains($expected, $cf); $this->assertStringContainsString($expected, $cf);
} }
public function testAttachedToSiteTree() public function testAttachedToSiteTree()

View File

@ -37,7 +37,7 @@ class CommentsGridFieldActionTest extends SapphireTest
/** @var Form */ /** @var Form */
protected $form; protected $form;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->list = new DataList(Team::class); $this->list = new DataList(Team::class);
@ -96,27 +96,27 @@ class CommentsGridFieldActionTest extends SapphireTest
$record->write(); $record->write();
$recordID = $record->ID; $recordID = $record->ID;
$html = $action->getColumnContent($this->gridField, $record, Comment::class); $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->assertStringContainsString('value="Spam"', $html);
$this->assertContains('id="action_CustomAction' . $recordID . 'Spam"', $html); $this->assertStringContainsString('id="action_CustomAction' . $recordID . 'Spam"', $html);
$this->assertContains('value="Approve"', $html); $this->assertStringContainsString('value="Approve"', $html);
$this->assertContains('id="action_CustomAction' . $recordID . 'Approve"', $html); $this->assertStringContainsString('id="action_CustomAction' . $recordID . 'Approve"', $html);
// If marked as spam, only the approve button should be available // If marked as spam, only the approve button should be available
$record->markSpam(); $record->markSpam();
$record->write(); $record->write();
$html = $action->getColumnContent($this->gridField, $record, Comment::class); $html = $action->getColumnContent($this->gridField, $record, Comment::class);
$this->assertContains('value="Approve"', $html); $this->assertStringContainsString('value="Approve"', $html);
$this->assertNotContains('value="Spam"', $html); $this->assertStringNotContainsString('value="Spam"', $html);
// If marked as spam, only the approve button should be available // If marked as spam, only the approve button should be available
$record->markApproved(); $record->markApproved();
$record->write(); $record->write();
$html = $action->getColumnContent($this->gridField, $record, Comment::class); $html = $action->getColumnContent($this->gridField, $record, Comment::class);
$this->assertNotContains('value="Approve"', $html); $this->assertStringNotContainsString('value="Approve"', $html);
$this->assertContains('value="Spam"', $html); $this->assertStringContainsString('value="Spam"', $html);
} }
public function testGetActions() public function testGetActions()

View File

@ -26,7 +26,7 @@ class CommentsTest extends FunctionalTest
CommentableItemDisabled::class, CommentableItemDisabled::class,
]; ];
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -235,7 +235,7 @@ class CommentsTest extends FunctionalTest
$comment = $this->objFromFixture(Comment::class, 'firstComA'); $comment = $this->objFromFixture(Comment::class, 'firstComA');
$commentID = $comment->ID; $commentID = $comment->ID;
$adminComment1Link = $comment->DeleteLink(); $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 // Test that this link can't be shared / XSS exploited
$this->logInAs('commentadmin2'); $this->logInAs('commentadmin2');
@ -275,7 +275,7 @@ class CommentsTest extends FunctionalTest
$comment = $this->objFromFixture(Comment::class, 'firstComA'); $comment = $this->objFromFixture(Comment::class, 'firstComA');
$commentID = $comment->ID; $commentID = $comment->ID;
$adminComment1Link = $comment->SpamLink(); $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 // Test that this link can't be shared / XSS exploited
$this->logInAs('commentadmin2'); $this->logInAs('commentadmin2');
@ -318,7 +318,7 @@ class CommentsTest extends FunctionalTest
$comment = $this->objFromFixture(Comment::class, 'secondComC'); $comment = $this->objFromFixture(Comment::class, 'secondComC');
$commentID = $comment->ID; $commentID = $comment->ID;
$adminComment1Link = $comment->HamLink(); $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 // Test that this link can't be shared / XSS exploited
$this->logInAs('commentadmin2'); $this->logInAs('commentadmin2');
@ -361,7 +361,7 @@ class CommentsTest extends FunctionalTest
$comment = $this->objFromFixture(Comment::class, 'secondComB'); $comment = $this->objFromFixture(Comment::class, 'secondComB');
$commentID = $comment->ID; $commentID = $comment->ID;
$adminComment1Link = $comment->ApproveLink(); $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 // Test that this link can't be shared / XSS exploited
$this->logInAs('commentadmin2'); $this->logInAs('commentadmin2');
@ -775,30 +775,30 @@ class CommentsTest extends FunctionalTest
$method = $this->getMethod('ActionLink'); $method = $this->getMethod('ActionLink');
// test with starts of strings and tokens and salts change each time // test with starts of strings and tokens and salts change each time
$this->assertContains( $this->assertStringContainsString(
'/comments/theaction/' . $comment->ID, '/comments/theaction/' . $comment->ID,
$method->invokeArgs($comment, array('theaction')) $method->invokeArgs($comment, array('theaction'))
); );
$this->assertContains( $this->assertStringContainsString(
'/comments/delete/' . $comment->ID, '/comments/delete/' . $comment->ID,
$comment->DeleteLink() $comment->DeleteLink()
); );
$this->assertContains( $this->assertStringContainsString(
'/comments/spam/' . $comment->ID, '/comments/spam/' . $comment->ID,
$comment->SpamLink() $comment->SpamLink()
); );
$comment->markSpam(); $comment->markSpam();
$this->assertContains( $this->assertStringContainsString(
'/comments/ham/' . $comment->ID, '/comments/ham/' . $comment->ID,
$comment->HamLink() $comment->HamLink()
); );
//markApproved //markApproved
$comment->markUnapproved(); $comment->markUnapproved();
$this->assertContains( $this->assertStringContainsString(
'/comments/approve/' . $comment->ID, '/comments/approve/' . $comment->ID,
$comment->ApproveLink() $comment->ApproveLink()
); );