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

tests/ContentReviewSettingsTest.php (38 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
/**
4
 * This class tests that settings are inherited correctly based on the inherited,
5
 * custom or disabled settings.
6
 *
7
 * @mixin PHPUnit_Framework_TestCase
8
 */
9
class ContentReviewSettingsTest extends SapphireTest
10
{
11
    /**
12
     * @var string
13
     */
14
    public static $fixture_file = "contentreview/tests/ContentReviewSettingsTest.yml";
15
16
    /**
17
     * @var array
18
     */
19
    protected $requiredExtensions = array(
20
        "SiteTree"              => array("SiteTreeContentReview"),
21
        "Group"                 => array("ContentReviewOwner"),
22
        "Member"                => array("ContentReviewOwner"),
23
        "CMSPageEditController" => array("ContentReviewCMSExtension"),
24
        "SiteConfig"            => array("ContentReviewDefaultSettings"),
25
    );
26
27
    public function testAdvanceReviewDate10Days()
28
    {
29
        /** @var Page|SiteTreeContentReview $page */
30
        $page = new Page();
31
32
        $page->ContentReviewType = "Custom";
33
        $page->ReviewPeriodDays = 10;
34
35
        $this->assertTrue($page->advanceReviewDate());
0 ignored issues
show
The method assertTrue() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
36
37
        $page->write();
0 ignored issues
show
The method write() does not seem to exist on object<SiteTreeContentReview>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
39
        $this->assertEquals(date("Y-m-d", strtotime("now + 10 days")), $page->NextReviewDate);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
    }
41
42
    public function testAdvanceReviewDateNull()
43
    {
44
        /** @var Page|SiteTreeContentReview $page */
45
        $page = new Page();
46
47
        $page->ContentReviewType = "Custom";
48
        $page->ReviewPeriodDays = 0;
49
50
        $this->assertFalse($page->advanceReviewDate());
0 ignored issues
show
The method assertFalse() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
52
        $page->write();
0 ignored issues
show
The method write() does not seem to exist on object<SiteTreeContentReview>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
54
        $this->assertEquals(null, $page->NextReviewDate);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
    }
56
57 View Code Duplication
    public function testAdvanceReviewFromCustomSettings()
58
    {
59
        /** @var Page|SiteTreeContentReview $page */
60
        $page = $this->objFromFixture("Page", "custom");
61
62
        $this->assertTrue($page->advanceReviewDate());
0 ignored issues
show
The method assertTrue() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
64
        $page->write();
0 ignored issues
show
The method write() does not seem to exist on object<SiteTreeContentReview>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
66
        $this->assertEquals(date("Y-m-d", strtotime("now + " . $page->ReviewPeriodDays . " days")), $page->NextReviewDate);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
    }
68
69
    public function testAdvanceReviewFromInheritedSettings()
70
    {
71
        // When a parent page is advanced, the next review date of the child is not automatically advanced
72
        $parentPage = $this->objFromFixture("Page", "page-1");
73
        $this->assertTrue($parentPage->advanceReviewDate());
74
        $parentPage->write();
75
        
76
        $page = $this->objFromFixture("Page", "page-1-1");
77
        $this->assertEquals(date("Y-m-d", strtotime("now + 5 days")), $parentPage->NextReviewDate);
78
        $this->assertEquals('2011-04-12', $page->NextReviewDate);
79
80
        // When a sub page is advanced, the next review date is advanced by the number of days in the parent
81
        $this->assertTrue($page->advanceReviewDate());
0 ignored issues
show
The method assertTrue() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
82
        $page->write();
83
        $this->assertEquals(date("Y-m-d", strtotime("now + 5 days")), $page->NextReviewDate);
84
    }
85
86 View Code Duplication
    public function testAdvanceReviewFromInheritedSiteConfigSettings()
87
    {
88
        /** @var Page|SiteTreeContentReview $page */
89
        $page = $this->objFromFixture("Page", "inherit");
90
91
        /** @var SiteConfig|ContentReviewDefaultSettings $siteConfig */
92
        $siteConfig = $this->objFromFixture("SiteConfig", "default");
93
94
        $this->assertTrue($page->advanceReviewDate());
0 ignored issues
show
The method assertTrue() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
95
96
        $page->write();
0 ignored issues
show
The method write() does not seem to exist on object<SiteTreeContentReview>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
97
98
        $this->assertEquals(date("Y-m-d", strtotime("now + " . $siteConfig->ReviewPeriodDays . " days")), $page->NextReviewDate);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
99
    }
100
101 View Code Duplication
    public function testGetSettingsObjectFromCustom()
102
    {
103
        /** @var Page|SiteTreeContentReview $page */
104
        $page = $this->objFromFixture("Page", "custom");
105
106
        $this->assertEquals("Custom", $page->ContentReviewType);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
107
        $this->assertEquals($page, $page->getOptions());
0 ignored issues
show
The method assertEquals() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
108
    }
109
110
    public function testGetSettingsObjectFromDisabled()
111
    {
112
        /** @var Page|SiteTreeContentReview $page */
113
        $page = $this->objFromFixture("Page", "disabled");
114
115
        $this->assertEquals("Disabled", $page->ContentReviewType);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
116
        $this->assertFalse($page->getOptions());
0 ignored issues
show
The method assertFalse() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
117
    }
118
119
    public function testGetOptionObjectFromInheritedDisabled()
120
    {
121
        /** @var Page|SiteTreeContentReview $page */
122
        $page = $this->objFromFixture("Page", "page-2-1-1");
123
124
        $this->assertEquals("Inherit", $page->ContentReviewType);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
125
        $this->assertFalse($page->getOptions());
0 ignored issues
show
The method assertFalse() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
126
    }
127
128 View Code Duplication
    public function testGetOptionObjectFromDeeplyInheritedPage()
129
    {
130
        /** @var Page|SiteTreeContentReview $page */
131
        $page = $this->objFromFixture("Page", "page-3-1-1-1");
132
133
        $this->assertEquals("Inherit", $page->ContentReviewType);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
134
        $this->assertInstanceOf("SiteConfig", $page->getOptions());
0 ignored issues
show
The method assertInstanceOf() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
135
    }
136
137
    public function testGetSettingsObjectFromInheritPage()
138
    {
139
        /** @var Page|SiteTreeContentReview $page */
140
        $page = $this->objFromFixture("Page", "page-1-1");
141
142
        /** @var Page|SiteTreeContentReview $parentPage */
143
        $parentPage = $this->objFromFixture("Page", "page-1");
144
145
        $this->assertEquals("Inherit", $page->ContentReviewType);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
146
        $this->assertEquals(get_class($parentPage), get_class($page->getOptions()));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
147
        $this->assertEquals($parentPage->ID, $page->getOptions()->ID);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
148
    }
149
150
    public function testGetSettingsObjectFromInheritedRootPage()
151
    {
152
        /** @var Page|SiteTreeContentReview $page */
153
        $page = $this->objFromFixture("Page", "inherit");
154
155
        $this->assertEquals("Inherit", $page->ContentReviewType);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
156
        $this->assertEquals($this->objFromFixture("SiteConfig", "default"), $page->getOptions());
0 ignored issues
show
The method assertEquals() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
157
    }
158
159
    public function testGetNextReviewDateFromCustomSettings()
160
    {
161
        /** @var Page|SiteTreeContentReview $page */
162
        $page = $this->objFromFixture('Page', 'custom');
163
164
        $date = $page->getReviewDate();
165
166
        $this->assertEquals('2010-02-01', $date->format('Y-m-d'));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
167
    }
168
169
    public function testGetNextReviewDateFromSiteConfigInheritedSetting()
170
    {
171
        /** @var Page|SiteTreeContentReview $page */
172
        $page = $this->objFromFixture("Page", "inherit");
173
174
        $nextReviewDate = $page->getReviewDate();
175
176
        $this->assertInstanceOf("Date", $nextReviewDate);
0 ignored issues
show
The method assertInstanceOf() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
177
178
        /** @var SiteConfig|ContentReviewDefaultSettings $siteConfig */
179
        $siteConfig = $this->objFromFixture("SiteConfig", "default");
180
181
        $expected = $this->addDaysToDate(SS_Datetime::now(), $siteConfig->ReviewPeriodDays);
182
183
        $this->assertEquals($expected, $nextReviewDate->format("Y-m-d"));
0 ignored issues
show
The method assertEquals() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
184
    }
185
186
    public function testGetNextReviewDateFromPageInheritedSetting()
187
    {
188
        // Although page-1-1 inherits from page-1, it has an independent review date
189
        $page = $this->objFromFixture("Page", "page-1-1");
190
        $nextReviewDate = $page->getReviewDate();
191
        $this->assertInstanceOf("Date", $nextReviewDate);
0 ignored issues
show
The method assertInstanceOf() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
192
        $this->assertEquals('2011-04-12', $nextReviewDate->format("Y-m-d"));
193
    }
194
195
    public function testUpdateNextReviewDateFromCustomToDisabled()
196
    {
197
        /** @var Page|SiteTreeContentReview $page */
198
        $page = $this->objFromFixture("Page", "custom");
199
200
        // before write()
201
        $this->assertEquals("2010-02-01", $page->NextReviewDate);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
202
203
        $page->ContentReviewType = "Disabled";
204
        $page->write();
0 ignored issues
show
The method write() does not seem to exist on object<SiteTreeContentReview>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
205
206
        DataObject::flush_and_destroy_cache();
207
        unset($page);
208
209
        /** @var Page|SiteTreeContentReview $page */
210
        $page = $this->objFromFixture("Page", "custom");
211
212
        $this->assertNull($page->NextReviewDate);
0 ignored issues
show
The method assertNull() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
213
    }
214
215
    public function testUpdateNextReviewDateFromDisabledToCustom()
216
    {
217
        /** @var Page|SiteTreeContentReview $page */
218
        $page = $this->objFromFixture("Page", "disabled");
219
220
        $this->assertNull($page->NextReviewDate);
0 ignored issues
show
The method assertNull() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
221
222
        $page->ContentReviewType = "Custom";
223
        $page->ReviewPeriodDays = "7";
224
        $page->write();
0 ignored issues
show
The method write() does not seem to exist on object<SiteTreeContentReview>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
225
226
        DataObject::flush_and_destroy_cache();
227
        unset($page);
228
229
        /** @var Page|SiteTreeContentReview $page */
230
        $page = $this->objFromFixture("Page", "disabled");
231
232
        $expected = date("Y-m-d", strtotime("+ " . $page->ReviewPeriodDays . " days"));
233
234
        $this->assertEquals($expected, $page->NextReviewDate);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
235
    }
236
237
    public function testParentChangedOptionsAndChildShouldToo()
238
    {
239
        /** @var Page|SiteTreeContentReview $parentPage */
240
        $parentPage = $this->objFromFixture("Page", "page-1");
241
242
        /** @var Page|SiteTreeContentReview $childPage */
243
        $childPage = $this->objFromFixture("Page", "page-1-1");
244
245
        // Parent and child pages have different review dates
246
        $this->assertNotEquals($parentPage->NextReviewDate, $childPage->NextReviewDate);
247
248
        // But if we change the parent page ReviewPeriodDays to 10, the childs stays the same
249
        $parentPage->ReviewPeriodDays = 10;
250
        $parentPage->write();
0 ignored issues
show
The method write() does not seem to exist on object<SiteTreeContentReview>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
251
252
        // Flush all the caches!
253
        DataObject::flush_and_destroy_cache();
254
255
        /** @var Page|SiteTreeContentReview $page */
256
        $parentPage = $this->objFromFixture("Page", "page-1");
257
258
        /** @var Page|SiteTreeContentReview $page */
259
        $childPage = $this->objFromFixture("Page", "page-1-1");
260
261
        // The parent page's date advances, but not the child's
262
        $this->assertEquals('2011-04-12', $childPage->NextReviewDate);
263
        $this->assertEquals($this->addDaysToDate(date("Y-m-d"), 10), $parentPage->NextReviewDate);
264
265
        // Reviewing the child page should, however, advance its review by 10 days
266
        $childPage->advanceReviewDate();
267
        $childPage->write();
268
        $this->assertEquals($this->addDaysToDate(date("Y-m-d"), 10), $childPage->NextReviewDate);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<ContentReviewSettingsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
269
    }
270
271
    /**
272
     * @param string|SS_DateTime|DateTime $date
273
     * @param int                         $days
274
     * @param string                      $format
275
     *
276
     * @return bool|string
277
     */
278
    private function addDaysToDate($date, $days, $format = "Y-m-d")
279
    {
280
        if (is_object($date)) {
281
            $sec = strtotime("+ " . $days . " days", $date->format("U"));
282
        } else {
283
            $sec = strtotime("+ " . $days . " days", strtotime($date));
284
        }
285
286
        return date($format, $sec);
287
    }
288
}
289