Completed
Push — master ( 4a6357...521c8c )
by Franco
10s
created

tests/ContentReviewCMSPageEditControllerTest.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

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.

Loading history...
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);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

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.

Loading history...
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
    public function testSaveReview()
94
    {
95
        /** @var Member $author */
96
        $author = $this->objFromFixture(Member::class, "author");
97
98
        $this->logInAs($author);
99
100
        /** @var Page|SiteTreeContentReview $page */
101
        $page = $this->objFromFixture(Page::class, "home");
102
103
        $data = array(
104
            "action_savereview" => 1,
105
            "ID"                => $page->ID,
106
            "ReviewNotes"       => "This is the best page ever",
107
        );
108
109
        $this->get('admin/pages/edit/show/' . $page->ID);
110
        $response = $this->post($this->getFormAction($page), $data);
111
112
        $this->assertEquals("OK", $response->getStatusDescription());
113
        $this->assertEquals(200, $response->getStatusCode());
114
        $this->assertEquals(1, $page->ReviewLogs()->count());
115
116
        $reviewLog = $page->ReviewLogs()->first();
117
118
        $this->assertEquals($data["ReviewNotes"], $reviewLog->Note);
119
    }
120
121
    /**
122
     * Return a CMS page edit form action via using a dummy request and session
123
     *
124
     * @param Page $page
125
     * @return string
126
     */
127
    protected function getFormAction(Page $page)
128
    {
129
        $controller = singleton(CMSPageEditController::class);
130
        $controller->setRequest(new HTTPRequest('GET', '/'));
131
        $controller->getRequest()->setSession($this->session());
132
133
        return $controller->getEditForm($page->ID)->FormAction();
134
    }
135
}
136