From 7d086ceb821e1f5e7435a1c90bb68016cb88150d Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 18 Sep 2024 13:53:15 +1200 Subject: [PATCH] DEP Use PHPUnit 11 --- tests/php/ContentReviewBaseTest.php | 18 -------- ...ContentReviewCMSPageEditControllerTest.php | 3 +- .../ContentReviewCMSExtensionTest.php | 8 ++-- tests/php/Forms/ReviewContentHandlerTest.php | 2 +- tests/php/SiteTreeContentReviewTest.php | 18 ++++---- tests/php/SiteTreeContentReviewTestPage.php | 41 +++++++++++++++++++ 6 files changed, 57 insertions(+), 33 deletions(-) delete mode 100644 tests/php/ContentReviewBaseTest.php create mode 100644 tests/php/SiteTreeContentReviewTestPage.php diff --git a/tests/php/ContentReviewBaseTest.php b/tests/php/ContentReviewBaseTest.php deleted file mode 100644 index 0ac0015..0000000 --- a/tests/php/ContentReviewBaseTest.php +++ /dev/null @@ -1,18 +0,0 @@ -getMockBuilder(ContentReviewCMSExtension::class) - ->setMethods(['getReviewContentForm']) + ->onlyMethods(['getReviewContentForm']) ->getMock(); $mock->expects($this->once())->method('getReviewContentForm')->with(123)->willReturn(true); @@ -45,7 +45,7 @@ public function testGetReviewContentFormThrowsExceptionWhenObjectCannotBeReviewe $this->logOut(); $mock = $this->getMockBuilder(ContentReviewCMSExtension::class) - ->setMethods(['findRecord']) + ->onlyMethods(['findRecord']) ->getMock(); $mock->setOwner(new Controller); @@ -62,7 +62,7 @@ public function testGetReviewContentFormThrowsExceptionWhenObjectCannotBeReviewe public function testSaveReviewCallsHandler() { $mock = $this->getMockBuilder(ContentReviewCMSExtension::class) - ->setMethods(['findRecord', 'getReviewContentHandler']) + ->onlyMethods(['findRecord', 'getReviewContentHandler']) ->getMock(); $mock->setOwner(new Controller); @@ -71,7 +71,7 @@ public function testSaveReviewCallsHandler() $mock->expects($this->once())->method('findRecord')->willReturn($mockPage); $mockHandler = $this->getMockBuilder(ReviewContentHandler::class) - ->setMethods(['submitReview']) + ->onlyMethods(['submitReview']) ->getMock(); $mockHandler->expects($this->once()) diff --git a/tests/php/Forms/ReviewContentHandlerTest.php b/tests/php/Forms/ReviewContentHandlerTest.php index a544562..76e4904 100644 --- a/tests/php/Forms/ReviewContentHandlerTest.php +++ b/tests/php/Forms/ReviewContentHandlerTest.php @@ -63,7 +63,7 @@ public function testAddReviewNoteCalledWhenSubmittingReview() $mock = $this->getMockBuilder(ReviewContentHandler::class) ->setConstructorArgs([$controller]) - ->setMethods(['canSubmitReview']) + ->onlyMethods(['canSubmitReview']) ->getMock(); $mock->expects($this->exactly(3))->method('canSubmitReview')->willReturn(true); diff --git a/tests/php/SiteTreeContentReviewTest.php b/tests/php/SiteTreeContentReviewTest.php index 3b1eb20..51935ba 100644 --- a/tests/php/SiteTreeContentReviewTest.php +++ b/tests/php/SiteTreeContentReviewTest.php @@ -18,11 +18,17 @@ use SilverStripe\SiteConfig\SiteConfig; use SilverStripe\Versioned\Versioned; use SilverStripe\ORM\ArrayList; +use SilverStripe\Dev\FunctionalTest; +use SilverStripe\ContentReview\Tests\SiteTreeContentReviewTestPage; -class SiteTreeContentReviewTest extends ContentReviewBaseTest +class SiteTreeContentReviewTest extends FunctionalTest { protected $usesTransactions = false; + protected static $extra_dataobjects = [ + SiteTreeContentReviewTestPage::class, + ]; + /** * @var string */ @@ -372,14 +378,8 @@ public function testPermissionCheckByOnDataObject() { $reviewer = $this->objFromFixture(Member::class, 'editor'); - // Mock Page class with canReviewContent method to return true on first call and false on second call - $mock = $this->getMockBuilder(Page::class) - ->setMethods(['canReviewContent', 'NextReviewDate', 'OwnerUsers']) - ->getMock(); - $mock->expects($this->exactly(2))->method('canReviewContent')->willReturnOnConsecutiveCalls(false, true); - $mock->method('NextReviewDate')->willReturn('2020-02-20 12:00:00'); - $mock->method('OwnerUsers')->willReturn(ArrayList::create([$reviewer])); - $mock->ContentReviewType = 'Custom'; + $mock = new SiteTreeContentReviewTestPage(); + $mock->setReviewer($reviewer); /** @var SiteTreeContentReview $extension */ $extension = Injector::inst()->get(SiteTreeContentReview::class); diff --git a/tests/php/SiteTreeContentReviewTestPage.php b/tests/php/SiteTreeContentReviewTestPage.php new file mode 100644 index 0000000..5412fad --- /dev/null +++ b/tests/php/SiteTreeContentReviewTestPage.php @@ -0,0 +1,41 @@ +reviewer = $reviewer; + } + + public function canReviewContent() + { + $this->i++; + return $this->i === 1 ? false : true; + } + + public function NextReviewDate() + { + return '2020-02-20 12:00:00'; + } + + public function OwnerUsers() + { + return ArrayList::create([$this->reviewer]); + } +}