1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\ContentReview\Tests; |
4
|
|
|
|
5
|
|
|
use Page; |
6
|
|
|
use SilverStripe\CMS\Controllers\CMSPageEditController; |
7
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
8
|
|
|
use SilverStripe\ContentReview\Extensions\SiteTreeContentReview; |
9
|
|
|
use SilverStripe\ContentReview\Extensions\ContentReviewOwner; |
10
|
|
|
use SilverStripe\ContentReview\Extensions\ContentReviewCMSExtension; |
11
|
|
|
use SilverStripe\ContentReview\Extensions\ContentReviewDefaultSettings; |
12
|
|
|
use SilverStripe\Control\HTTPRequest; |
13
|
|
|
use SilverStripe\Control\HTTPResponse_Exception; |
14
|
|
|
use SilverStripe\Forms\FieldList; |
15
|
|
|
use SilverStripe\Forms\Form; |
16
|
|
|
use SilverStripe\Security\Group; |
17
|
|
|
use SilverStripe\Security\Member; |
18
|
|
|
use SilverStripe\SiteConfig\SiteConfig; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @mixin PHPUnit_Framework_TestCase |
22
|
|
|
*/ |
23
|
|
|
class ContentReviewCMSPageEditControllerTest extends ContentReviewBaseTest |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected static $fixture_file = 'ContentReviewTest.yml'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
protected static $required_extensions = [ |
34
|
|
|
SiteTree::class => [SiteTreeContentReview::class], |
35
|
|
|
Group::class => [ContentReviewOwner::class], |
36
|
|
|
Member::class => [ContentReviewOwner::class], |
37
|
|
|
CMSPageEditController::class => [ContentReviewCMSExtension::class], |
38
|
|
|
SiteConfig::class => [ContentReviewDefaultSettings::class], |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
View Code Duplication |
public function testReviewedThrowsExceptionWithNoRecordID() |
42
|
|
|
{ |
43
|
|
|
$this->setExpectedException(HTTPResponse_Exception::class); |
|
|
|
|
44
|
|
|
|
45
|
|
|
/** @var CMSPageEditController|ContentReviewCMSExtension $controller */ |
46
|
|
|
$controller = new CMSPageEditController(); |
47
|
|
|
|
48
|
|
|
$dummyForm = new Form($controller, "EditForm", new FieldList(), new FieldList()); |
49
|
|
|
|
50
|
|
|
$controller->savereview(array( |
51
|
|
|
"ID" => null, |
52
|
|
|
"Message" => null, |
53
|
|
|
), $dummyForm); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
View Code Duplication |
public function testReviewedThrowsExceptionWithWrongRecordID() |
57
|
|
|
{ |
58
|
|
|
$this->setExpectedException(HTTPResponse_Exception::class); |
|
|
|
|
59
|
|
|
|
60
|
|
|
/** @var CMSPageEditController|ContentReviewCMSExtension $controller */ |
61
|
|
|
$controller = new CMSPageEditController(); |
62
|
|
|
|
63
|
|
|
$dummyForm = new Form($controller, "EditForm", new FieldList(), new FieldList()); |
64
|
|
|
|
65
|
|
|
$controller->savereview(array( |
66
|
|
|
"ID" => "FAIL", |
67
|
|
|
"Message" => null, |
68
|
|
|
), $dummyForm); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testReviewedWithAuthor() |
72
|
|
|
{ |
73
|
|
|
/** @var Member $author */ |
74
|
|
|
$author = $this->objFromFixture(Member::class, "author"); |
75
|
|
|
|
76
|
|
|
$this->logInAs($author); |
77
|
|
|
|
78
|
|
|
/** @var Page|SiteTreeContentReview $page */ |
79
|
|
|
$page = $this->objFromFixture(Page::class, "home"); |
80
|
|
|
|
81
|
|
|
$data = array( |
82
|
|
|
"action_savereview" => 1, |
83
|
|
|
"ID" => $page->ID, |
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
$this->get('admin/pages/edit/show/' . $page->ID); |
87
|
|
|
$response = $this->post($this->getFormAction($page), $data); |
|
|
|
|
88
|
|
|
|
89
|
|
|
$this->assertEquals("OK", $response->getStatusDescription()); |
90
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Return a CMS page edit form action via using a dummy request and session |
95
|
|
|
* |
96
|
|
|
* @param Page $page |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
protected function getFormAction(Page $page) |
100
|
|
|
{ |
101
|
|
|
$controller = singleton(CMSPageEditController::class); |
102
|
|
|
$controller->setRequest(new HTTPRequest('GET', '/')); |
103
|
|
|
$controller->getRequest()->setSession($this->session()); |
104
|
|
|
|
105
|
|
|
return $controller->getEditForm($page->ID)->FormAction(); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.