mirror of
https://github.com/silverstripe/silverstripe-contentreview
synced 2024-10-22 17:05:47 +02:00
Improving the code coverage
This commit is contained in:
parent
7a843e222f
commit
f806987ba7
@ -29,12 +29,14 @@ class ContentReviewCMSPageEditController extends LeftAndMainExtension {
|
|||||||
}
|
}
|
||||||
$SQL_id = Convert::raw2sql($data['ID']);
|
$SQL_id = Convert::raw2sql($data['ID']);
|
||||||
$record = SiteTree::get()->byID($SQL_id);
|
$record = SiteTree::get()->byID($SQL_id);
|
||||||
if($record && !$record->canEdit()) {
|
|
||||||
return Security::permissionFailure($this);
|
|
||||||
}
|
|
||||||
if(!$record || !$record->ID) {
|
if(!$record || !$record->ID) {
|
||||||
throw new SS_HTTPResponse_Exception("Bad record ID #$SQL_id", 404);
|
throw new SS_HTTPResponse_Exception("Bad record ID #$SQL_id", 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!$record->canEdit()) {
|
||||||
|
return Security::permissionFailure($this->owner);
|
||||||
|
}
|
||||||
|
|
||||||
$fields = new FieldList();
|
$fields = new FieldList();
|
||||||
$fields->push(HiddenField::create('ID', 'ID', $SQL_id));
|
$fields->push(HiddenField::create('ID', 'ID', $SQL_id));
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
/**
|
/**
|
||||||
* Description of GroupContentReview
|
* Description of GroupContentReview
|
||||||
*
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
class ContentReviewOwner extends DataExtension {
|
class ContentReviewOwner extends DataExtension {
|
||||||
|
|
||||||
|
70
tests/ContentReviewCMSPageEditControllerTest.php
Normal file
70
tests/ContentReviewCMSPageEditControllerTest.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class ContentReviewCMSPageEditControllerTest extends FunctionalTest {
|
||||||
|
|
||||||
|
public static $fixture_file = 'contentreview/tests/ContentReviewTest.yml';
|
||||||
|
|
||||||
|
public function testReviewedThrowsExceptionWithNoRecordID() {
|
||||||
|
$this->setExpectedException('SS_HTTPResponse_Exception', 'No record ID', 404);
|
||||||
|
$controller = new CMSPageEditController();
|
||||||
|
$dummyForm = new CMSForm($controller, 'EditForm', new FieldList(), new FieldList());
|
||||||
|
$controller->reviewed(array('ID'=>null, 'Message' => null), $dummyForm);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReviewedThrowsExceptionWithWrongRecordID() {
|
||||||
|
$this->setExpectedException('SS_HTTPResponse_Exception', 'Bad record ID #FAIL', 404);
|
||||||
|
$controller = new CMSPageEditController();
|
||||||
|
$dummyForm = new CMSForm($controller, 'EditForm', new FieldList(), new FieldList());
|
||||||
|
$controller->reviewed(array('ID'=>'FAIL', 'Message' => null), $dummyForm);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReviewedThrowsExceptionWithWrongAccess() {
|
||||||
|
$visitor = $this->objFromFixture('Member', 'visitor');
|
||||||
|
$this->loginAs($visitor);
|
||||||
|
$page = $this->objFromFixture('Page', 'home');
|
||||||
|
$data = array(
|
||||||
|
'action_reviewed' => 1
|
||||||
|
);
|
||||||
|
$response = $this->post('admin/pages/edit/EditForm', $data);
|
||||||
|
$this->assertEquals(403, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReviewedWithAuthor() {
|
||||||
|
$author = $this->objFromFixture('Member', 'author');
|
||||||
|
$this->loginAs($author);
|
||||||
|
$page = $this->objFromFixture('Page', 'home');
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
'action_reviewed' => 1,
|
||||||
|
'ID' => $page->ID
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $this->post('admin/pages/edit/EditForm', $data);
|
||||||
|
$this->assertEquals('OK', $response->getStatusDescription());
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSaveReview() {
|
||||||
|
$author = $this->objFromFixture('Member', 'author');
|
||||||
|
$this->loginAs($author);
|
||||||
|
$page = $this->objFromFixture('Page', 'home');
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
'action_save_review' => 1,
|
||||||
|
'ID' => $page->ID,
|
||||||
|
'ReviewNotes' => 'This is the best page ever'
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $this->post('admin/pages/edit/EditForm', $data);
|
||||||
|
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -31,6 +31,10 @@ Member:
|
|||||||
FirstName: Test
|
FirstName: Test
|
||||||
Surname: Editor
|
Surname: Editor
|
||||||
Groups: =>Group.editorgroup
|
Groups: =>Group.editorgroup
|
||||||
|
visitor:
|
||||||
|
FirstName: Kari
|
||||||
|
Surname: Visitor
|
||||||
|
Email: visitor@example.com
|
||||||
|
|
||||||
Page:
|
Page:
|
||||||
home:
|
home:
|
||||||
|
Loading…
Reference in New Issue
Block a user