silverstripe-contentreview/tests/ContentReviewCMSPageEditControllerTest.php

104 lines
3.3 KiB
PHP
Raw Normal View History

2014-02-18 21:51:54 +01:00
<?php
2015-11-02 00:27:42 +01:00
/**
* @mixin PHPUnit_Framework_TestCase
*/
class ContentReviewCMSPageEditControllerTest extends ContentReviewBaseTest
{
/**
* @var string
*/
public static $fixture_file = "contentreview/tests/ContentReviewTest.yml";
/**
* @var array
*/
protected $requiredExtensions = array(
"SiteTree" => array("SiteTreeContentReview"),
"Group" => array("ContentReviewOwner"),
"Member" => array("ContentReviewOwner"),
"CMSPageEditController" => array("ContentReviewCMSExtension"),
"SiteConfig" => array("ContentReviewDefaultSettings"),
);
public function testReviewedThrowsExceptionWithNoRecordID()
{
$this->setExpectedException("SS_HTTPResponse_Exception");
/** @var CMSPageEditController|ContentReviewCMSExtension $controller */
$controller = new CMSPageEditController();
$dummyForm = new CMSForm($controller, "EditForm", new FieldList(), new FieldList());
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()
{
$this->setExpectedException("SS_HTTPResponse_Exception");
/** @var CMSPageEditController|ContentReviewCMSExtension $controller */
$controller = new CMSPageEditController();
$dummyForm = new CMSForm($controller, "EditForm", new FieldList(), new FieldList());
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 */
$author = $this->objFromFixture("Member", "author");
$this->loginAs($author);
2014-02-18 21:51:54 +01:00
2015-11-02 00:27:42 +01:00
/** @var Page|SiteTreeContentReview $page */
$page = $this->objFromFixture("Page", "home");
$data = array(
2015-11-12 03:56:19 +01:00
"action_savereview" => 1,
2015-11-02 00:27:42 +01:00
"ID" => $page->ID,
);
2015-11-12 03:56:19 +01:00
$this->get('admin/pages/edit/show/' . $page->ID);
$response = $this->post(singleton('CMSPageEditController')->getEditForm($page->ID)->FormAction(), $data);
2015-11-02 00:27:42 +01:00
$this->assertEquals("OK", $response->getStatusDescription());
$this->assertEquals(200, $response->getStatusCode());
}
public function testSaveReview()
{
/** @var Member $author */
$author = $this->objFromFixture("Member", "author");
$this->loginAs($author);
/** @var Page|SiteTreeContentReview $page */
$page = $this->objFromFixture("Page", "home");
$data = array(
2015-11-12 03:56:19 +01:00
"action_savereview" => 1,
2015-11-02 00:27:42 +01:00
"ID" => $page->ID,
"ReviewNotes" => "This is the best page ever",
);
2015-11-12 03:56:19 +01:00
$this->get('admin/pages/edit/show/' . $page->ID);
$response = $this->post(singleton('CMSPageEditController')->getEditForm($page->ID)->FormAction(), $data);
2015-11-02 00:27:42 +01:00
$this->assertEquals("OK", $response->getStatusDescription());
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals(1, $page->ReviewLogs()->count());
$reviewLog = $page->ReviewLogs()->first();
$this->assertEquals($data["ReviewNotes"], $reviewLog->Note);
}
}