2014-02-18 21:51:54 +01:00
|
|
|
<?php
|
|
|
|
|
2017-09-06 05:49:23 +02:00
|
|
|
namespace SilverStripe\ContentReview\Tests;
|
|
|
|
|
|
|
|
use Page;
|
|
|
|
use SilverStripe\CMS\Controllers\CMSPageEditController;
|
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
|
|
|
use SilverStripe\ContentReview\Extensions\SiteTreeContentReview;
|
|
|
|
use SilverStripe\ContentReview\Extensions\ContentReviewOwner;
|
|
|
|
use SilverStripe\ContentReview\Extensions\ContentReviewCMSExtension;
|
|
|
|
use SilverStripe\ContentReview\Extensions\ContentReviewDefaultSettings;
|
2017-09-06 06:53:45 +02:00
|
|
|
use SilverStripe\Control\HTTPRequest;
|
2017-09-06 05:49:23 +02:00
|
|
|
use SilverStripe\Control\HTTPResponse_Exception;
|
|
|
|
use SilverStripe\Forms\FieldList;
|
|
|
|
use SilverStripe\Forms\Form;
|
|
|
|
use SilverStripe\Security\Group;
|
|
|
|
use SilverStripe\Security\Member;
|
|
|
|
use SilverStripe\SiteConfig\SiteConfig;
|
|
|
|
|
2015-11-02 00:27:42 +01:00
|
|
|
class ContentReviewCMSPageEditControllerTest extends ContentReviewBaseTest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2017-09-06 05:49:23 +02:00
|
|
|
protected static $fixture_file = 'ContentReviewTest.yml';
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-09-06 05:49:23 +02:00
|
|
|
protected static $required_extensions = [
|
|
|
|
SiteTree::class => [SiteTreeContentReview::class],
|
|
|
|
Group::class => [ContentReviewOwner::class],
|
|
|
|
Member::class => [ContentReviewOwner::class],
|
|
|
|
CMSPageEditController::class => [ContentReviewCMSExtension::class],
|
|
|
|
SiteConfig::class => [ContentReviewDefaultSettings::class],
|
|
|
|
];
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
public function testReviewedThrowsExceptionWithNoRecordID()
|
|
|
|
{
|
2018-01-08 04:47:31 +01:00
|
|
|
$this->expectException(HTTPResponse_Exception::class);
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var CMSPageEditController|ContentReviewCMSExtension $controller */
|
|
|
|
$controller = new CMSPageEditController();
|
|
|
|
|
2017-09-06 05:49:23 +02:00
|
|
|
$dummyForm = new Form($controller, "EditForm", new FieldList(), new FieldList());
|
2015-11-02 00:27:42 +01:00
|
|
|
|
2015-11-12 03:56:19 +01:00
|
|
|
$controller->savereview(array(
|
2015-11-02 00:27:42 +01:00
|
|
|
"ID" => null,
|
|
|
|
"Message" => null,
|
|
|
|
), $dummyForm);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testReviewedThrowsExceptionWithWrongRecordID()
|
|
|
|
{
|
2018-01-08 04:47:31 +01:00
|
|
|
$this->expectException(HTTPResponse_Exception::class);
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var CMSPageEditController|ContentReviewCMSExtension $controller */
|
|
|
|
$controller = new CMSPageEditController();
|
|
|
|
|
2017-09-06 05:49:23 +02:00
|
|
|
$dummyForm = new Form($controller, "EditForm", new FieldList(), new FieldList());
|
2015-11-02 00:27:42 +01:00
|
|
|
|
2015-11-12 03:56:19 +01:00
|
|
|
$controller->savereview(array(
|
2015-11-02 00:27:42 +01:00
|
|
|
"ID" => "FAIL",
|
|
|
|
"Message" => null,
|
|
|
|
), $dummyForm);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testReviewedWithAuthor()
|
|
|
|
{
|
|
|
|
/** @var Member $author */
|
2017-09-06 05:49:23 +02:00
|
|
|
$author = $this->objFromFixture(Member::class, "author");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
2017-09-06 06:53:45 +02:00
|
|
|
$this->logInAs($author);
|
2014-02-18 21:51:54 +01:00
|
|
|
|
2015-11-02 00:27:42 +01:00
|
|
|
/** @var Page|SiteTreeContentReview $page */
|
2017-09-06 05:49:23 +02:00
|
|
|
$page = $this->objFromFixture(Page::class, "home");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$data = array(
|
2015-11-12 03:56:19 +01:00
|
|
|
"action_savereview" => 1,
|
2017-09-06 05:49:23 +02:00
|
|
|
"ID" => $page->ID,
|
2015-11-02 00:27:42 +01:00
|
|
|
);
|
|
|
|
|
2015-11-12 03:56:19 +01:00
|
|
|
$this->get('admin/pages/edit/show/' . $page->ID);
|
2017-09-06 06:53:45 +02:00
|
|
|
$response = $this->post($this->getFormAction($page), $data);
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$this->assertEquals("OK", $response->getStatusDescription());
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
}
|
|
|
|
|
2017-09-06 06:53:45 +02:00
|
|
|
/**
|
|
|
|
* Return a CMS page edit form action via using a dummy request and session
|
|
|
|
*
|
|
|
|
* @param Page $page
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getFormAction(Page $page)
|
|
|
|
{
|
|
|
|
$controller = singleton(CMSPageEditController::class);
|
|
|
|
$controller->setRequest(new HTTPRequest('GET', '/'));
|
|
|
|
$controller->getRequest()->setSession($this->session());
|
|
|
|
|
|
|
|
return $controller->getEditForm($page->ID)->FormAction();
|
|
|
|
}
|
2015-11-02 00:27:42 +01:00
|
|
|
}
|