mirror of
https://github.com/silverstripe/silverstripe-contentreview
synced 2024-10-22 17:05:47 +02:00
Merge pull request #256 from creative-commoners/pulls/6/phpunit11
DEP Use PHPUnit 11
This commit is contained in:
commit
4f164fca78
@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace SilverStripe\ContentReview\Tests;
|
|
||||||
|
|
||||||
use SilverStripe\Dev\FunctionalTest;
|
|
||||||
use SilverStripe\CMS\Model\SiteTree;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extend this class when writing unit tests which are compatible with other modules.
|
|
||||||
* All compatibility code goes here.
|
|
||||||
*/
|
|
||||||
abstract class ContentReviewBaseTest extends FunctionalTest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
protected $translatableEnabledBefore;
|
|
||||||
}
|
|
@ -16,8 +16,9 @@ use SilverStripe\Forms\Form;
|
|||||||
use SilverStripe\Security\Group;
|
use SilverStripe\Security\Group;
|
||||||
use SilverStripe\Security\Member;
|
use SilverStripe\Security\Member;
|
||||||
use SilverStripe\SiteConfig\SiteConfig;
|
use SilverStripe\SiteConfig\SiteConfig;
|
||||||
|
use SilverStripe\Dev\FunctionalTest;
|
||||||
|
|
||||||
class ContentReviewCMSPageEditControllerTest extends ContentReviewBaseTest
|
class ContentReviewCMSPageEditControllerTest extends FunctionalTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
|
@ -21,7 +21,7 @@ class ContentReviewCMSExtensionTest extends SapphireTest
|
|||||||
public function testReviewContentForm()
|
public function testReviewContentForm()
|
||||||
{
|
{
|
||||||
$mock = $this->getMockBuilder(ContentReviewCMSExtension::class)
|
$mock = $this->getMockBuilder(ContentReviewCMSExtension::class)
|
||||||
->setMethods(['getReviewContentForm'])
|
->onlyMethods(['getReviewContentForm'])
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$mock->expects($this->once())->method('getReviewContentForm')->with(123)->willReturn(true);
|
$mock->expects($this->once())->method('getReviewContentForm')->with(123)->willReturn(true);
|
||||||
@ -45,7 +45,7 @@ class ContentReviewCMSExtensionTest extends SapphireTest
|
|||||||
$this->logOut();
|
$this->logOut();
|
||||||
|
|
||||||
$mock = $this->getMockBuilder(ContentReviewCMSExtension::class)
|
$mock = $this->getMockBuilder(ContentReviewCMSExtension::class)
|
||||||
->setMethods(['findRecord'])
|
->onlyMethods(['findRecord'])
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$mock->setOwner(new Controller);
|
$mock->setOwner(new Controller);
|
||||||
@ -62,7 +62,7 @@ class ContentReviewCMSExtensionTest extends SapphireTest
|
|||||||
public function testSaveReviewCallsHandler()
|
public function testSaveReviewCallsHandler()
|
||||||
{
|
{
|
||||||
$mock = $this->getMockBuilder(ContentReviewCMSExtension::class)
|
$mock = $this->getMockBuilder(ContentReviewCMSExtension::class)
|
||||||
->setMethods(['findRecord', 'getReviewContentHandler'])
|
->onlyMethods(['findRecord', 'getReviewContentHandler'])
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$mock->setOwner(new Controller);
|
$mock->setOwner(new Controller);
|
||||||
@ -71,7 +71,7 @@ class ContentReviewCMSExtensionTest extends SapphireTest
|
|||||||
$mock->expects($this->once())->method('findRecord')->willReturn($mockPage);
|
$mock->expects($this->once())->method('findRecord')->willReturn($mockPage);
|
||||||
|
|
||||||
$mockHandler = $this->getMockBuilder(ReviewContentHandler::class)
|
$mockHandler = $this->getMockBuilder(ReviewContentHandler::class)
|
||||||
->setMethods(['submitReview'])
|
->onlyMethods(['submitReview'])
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$mockHandler->expects($this->once())
|
$mockHandler->expects($this->once())
|
||||||
|
@ -63,7 +63,7 @@ class ReviewContentHandlerTest extends SapphireTest
|
|||||||
|
|
||||||
$mock = $this->getMockBuilder(ReviewContentHandler::class)
|
$mock = $this->getMockBuilder(ReviewContentHandler::class)
|
||||||
->setConstructorArgs([$controller])
|
->setConstructorArgs([$controller])
|
||||||
->setMethods(['canSubmitReview'])
|
->onlyMethods(['canSubmitReview'])
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$mock->expects($this->exactly(3))->method('canSubmitReview')->willReturn(true);
|
$mock->expects($this->exactly(3))->method('canSubmitReview')->willReturn(true);
|
||||||
|
@ -18,11 +18,17 @@ use SilverStripe\Security\Member;
|
|||||||
use SilverStripe\SiteConfig\SiteConfig;
|
use SilverStripe\SiteConfig\SiteConfig;
|
||||||
use SilverStripe\Versioned\Versioned;
|
use SilverStripe\Versioned\Versioned;
|
||||||
use SilverStripe\ORM\ArrayList;
|
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 $usesTransactions = false;
|
||||||
|
|
||||||
|
protected static $extra_dataobjects = [
|
||||||
|
SiteTreeContentReviewTestPage::class,
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@ -372,14 +378,8 @@ class SiteTreeContentReviewTest extends ContentReviewBaseTest
|
|||||||
{
|
{
|
||||||
$reviewer = $this->objFromFixture(Member::class, 'editor');
|
$reviewer = $this->objFromFixture(Member::class, 'editor');
|
||||||
|
|
||||||
// Mock Page class with canReviewContent method to return true on first call and false on second call
|
$mock = new SiteTreeContentReviewTestPage();
|
||||||
$mock = $this->getMockBuilder(Page::class)
|
$mock->setReviewer($reviewer);
|
||||||
->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';
|
|
||||||
|
|
||||||
/** @var SiteTreeContentReview $extension */
|
/** @var SiteTreeContentReview $extension */
|
||||||
$extension = Injector::inst()->get(SiteTreeContentReview::class);
|
$extension = Injector::inst()->get(SiteTreeContentReview::class);
|
||||||
|
41
tests/php/SiteTreeContentReviewTestPage.php
Normal file
41
tests/php/SiteTreeContentReviewTestPage.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\ContentReview\Tests;
|
||||||
|
|
||||||
|
use Page;
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
use SilverStripe\ORM\ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock Page class with canReviewContent method to return false on first call
|
||||||
|
* and true on second call
|
||||||
|
*/
|
||||||
|
class SiteTreeContentReviewTestPage extends Page implements TestOnly
|
||||||
|
{
|
||||||
|
public $ContentReviewType = 'Custom';
|
||||||
|
|
||||||
|
private $i = 0;
|
||||||
|
|
||||||
|
private $reviewer;
|
||||||
|
|
||||||
|
public function setReviewer($reviewer)
|
||||||
|
{
|
||||||
|
$this->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]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user