Completed
Pull Request — master (#110)
by Franco
02:03
created

DMSDocumentTest::testCanView()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 42
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 42
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 24
nc 2
nop 0
1
<?php
2
class DMSDocumentTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
3
{
4
    protected static $fixture_file = 'dmstest.yml';
5
6 View Code Duplication
    public function tearDownOnce()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
7
    {
8
        self::$is_running_test = true;
9
10
        $d = DataObject::get('DMSDocument');
11
        foreach ($d as $d1) {
12
            $d1->delete();
13
        }
14
        $t = DataObject::get('DMSTag');
15
        foreach ($t as $t1) {
16
            $t1->delete();
17
        }
18
19
        self::$is_running_test = $this->originalIsRunningTest;
20
    }
21
22
    public function testPageRelations()
23
    {
24
        $s1 = $this->objFromFixture('SiteTree', 's1');
25
        $s2 = $this->objFromFixture('SiteTree', 's2');
26
        $s3 = $this->objFromFixture('SiteTree', 's3');
27
        $s4 = $this->objFromFixture('SiteTree', 's4');
28
        $s5 = $this->objFromFixture('SiteTree', 's5');
29
        $s6 = $this->objFromFixture('SiteTree', 's6');
30
31
        $d1 = $this->objFromFixture('DMSDocument', 'd1');
32
33
        $pages = $d1->Pages();
34
        $pagesArray = $pages->toArray();
35
        $this->assertEquals($pagesArray[0]->ID, $s1->ID, 'Page 1 associated correctly');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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
        $this->assertEquals($pagesArray[1]->ID, $s2->ID, 'Page 2 associated correctly');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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...
37
        $this->assertEquals($pagesArray[2]->ID, $s3->ID, 'Page 3 associated correctly');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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
        $this->assertEquals($pagesArray[3]->ID, $s4->ID, 'Page 4 associated correctly');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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...
39
        $this->assertEquals($pagesArray[4]->ID, $s5->ID, 'Page 5 associated correctly');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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
        $this->assertEquals($pagesArray[5]->ID, $s6->ID, 'Page 6 associated correctly');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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...
41
    }
42
43
    public function testAddPageRelation()
44
    {
45
        $s1 = $this->objFromFixture('SiteTree', 's1');
46
        $s2 = $this->objFromFixture('SiteTree', 's2');
47
        $s3 = $this->objFromFixture('SiteTree', 's3');
48
49
        $doc = new DMSDocument();
50
        $doc->Filename = 'test file';
51
        $doc->Folder = '0';
52
        $doc->write();
53
54
        $doc->addPage($s1);
0 ignored issues
show
Documentation introduced by
$s1 is of type object<DataObject>|null, but the function expects a object<SiteTree>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
55
        $doc->addPage($s2);
0 ignored issues
show
Documentation introduced by
$s2 is of type object<DataObject>|null, but the function expects a object<SiteTree>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
56
        $doc->addPage($s3);
0 ignored issues
show
Documentation introduced by
$s3 is of type object<DataObject>|null, but the function expects a object<SiteTree>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
58
        $pages = $doc->Pages();
59
        $pagesArray = $pages->toArray();
60
        $this->assertEquals($pagesArray[0]->ID, $s1->ID, 'Page 1 associated correctly');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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...
61
        $this->assertEquals($pagesArray[1]->ID, $s2->ID, 'Page 2 associated correctly');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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...
62
        $this->assertEquals($pagesArray[2]->ID, $s3->ID, 'Page 3 associated correctly');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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
        $doc->removePage($s1);
0 ignored issues
show
Compatibility introduced by
$s1 of type object<DataObject> is not a sub-type of object<SiteTree>. It seems like you assume a child class of the class DataObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
65
        $pages = $doc->Pages();
66
        $pagesArray = $pages->toArray();    // Page 1 is missing
67
        $this->assertEquals($pagesArray[0]->ID, $s2->ID, 'Page 2 still associated correctly');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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...
68
        $this->assertEquals($pagesArray[1]->ID, $s3->ID, 'Page 3 still associated correctly');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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...
69
70
        $documents = $s2->Documents();
71
        $documentsArray = $documents->toArray();
72
        $this->assertDOSContains(
73
            array(
74
                array('Filename' => $doc->Filename)
75
            ),
76
            $documentsArray,
77
            'Document associated with page'
0 ignored issues
show
Unused Code introduced by
The call to DMSDocumentTest::assertDOSContains() has too many arguments starting with 'Document associated with page'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
78
        );
79
80
        $doc->removeAllPages();
81
        $pages = $doc->Pages();
82
        $this->assertEquals($pages->Count(), 0, 'All pages removed');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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...
83
84
        $documents = $s2->Documents();
85
        $documentsArray = $documents->toArray();
86
        $this->assertNotContains($doc, $documentsArray, 'Document no longer associated with page');
87
    }
88
89
    public function testDeletingPageWithAssociatedDocuments()
90
    {
91
        $s1 = $this->objFromFixture('SiteTree', 's1');
92
        $s2 = $this->objFromFixture('SiteTree', 's2');
93
        $s2->publish('Stage', 'Live');
94
        $s2ID = $s2->ID;
95
96
        $doc = new DMSDocument();
97
        $doc->Filename = 'delete test file';
98
        $doc->Folder = '0';
99
        $doc->write();
100
101
        $doc->addPage($s1);
0 ignored issues
show
Documentation introduced by
$s1 is of type object<DataObject>|null, but the function expects a object<SiteTree>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
102
        $doc->addPage($s2);
0 ignored issues
show
Compatibility introduced by
$s2 of type object<DataObject> is not a sub-type of object<SiteTree>. It seems like you assume a child class of the class DataObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
103
104
        $s1->delete();
105
106
        $documents = DataObject::get("DMSDocument", "\"Filename\" = 'delete test file'", false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a string|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
107
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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
            $documents->Count(),
109
            '1',
110
            "Deleting one of the associated page doesn't affect the single document we created"
111
        );
112
113
        $s2->delete();
114
        $documents = DataObject::get("DMSDocument", "\"Filename\" = 'delete test file'");
115
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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
            $documents->Count(),
117
            '1',
118
            "Deleting a page from draft stage doesn't delete the associated docs,"
119
            . "even if it's the last page they're associated with"
120
        );
121
122
        $s2 = Versioned::get_one_by_stage('SiteTree', 'Live', sprintf('"SiteTree"."ID" = %d', $s2ID));
123
        $s2->doDeleteFromLive();
0 ignored issues
show
Bug introduced by
The method doDeleteFromLive() does not exist on DataObject. Did you maybe mean delete()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
124
        $documents = DataObject::get("DMSDocument", "\"Filename\" = 'delete test file'");
125
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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
            $documents->Count(),
127
            '0',
128
            'However, deleting the live version of the last page that a document is '
129
            . 'associated with causes that document to be deleted as well'
130
        );
131
    }
132
133
    public function testUnpublishPageWithAssociatedDocuments()
134
    {
135
        $s2 = $this->objFromFixture('SiteTree', 's2');
136
        $s2->publish('Stage', 'Live');
137
        $s2ID = $s2->ID;
138
139
        $doc = new DMSDocument();
140
        $doc->Filename = 'delete test file';
141
        $doc->Folder = '0';
142
        $doc->write();
143
144
        $doc->addPage($s2);
0 ignored issues
show
Compatibility introduced by
$s2 of type object<DataObject> is not a sub-type of object<SiteTree>. It seems like you assume a child class of the class DataObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
145
146
        $s2->doDeleteFromLive();
0 ignored issues
show
Bug introduced by
The method doDeleteFromLive() does not exist on DataObject. Did you maybe mean delete()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
147
        $documents = DataObject::get("DMSDocument", "\"Filename\" = 'delete test file'");
148
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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...
149
            $documents->Count(),
150
            '1',
151
            "Deleting a page from live stage doesn't delete the associated docs,"
152
            . "even if it's the last page they're associated with"
153
        );
154
155
        $s2 = Versioned::get_one_by_stage('SiteTree', 'Stage', sprintf('"SiteTree"."ID" = %d', $s2ID));
156
        $s2->delete();
157
        $documents = DataObject::get("DMSDocument", "\"Filename\" = 'delete test file'");
158
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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...
159
            $documents->Count(),
160
            '0',
161
            'However, deleting the draft version of the last page that a document is '
162
            . 'associated with causes that document to be deleted as well'
163
        );
164
    }
165
166
    public function testDefaultDownloadBehabiourCMSFields()
167
    {
168
        $document = singleton('DMSDocument');
169
        Config::inst()->update('DMSDocument', 'default_download_behaviour', 'open');
170
        $cmsFields = $document->getCMSFields();
171
        $this->assertEquals('open', $cmsFields->dataFieldByName('DownloadBehavior')->Value());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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...
172
173
174
        Config::inst()->update('DMSDocument', 'default_download_behaviour', 'download');
175
        $cmsFields = $document->getCMSFields();
176
        $this->assertEquals('download', $cmsFields->dataFieldByName('DownloadBehavior')->Value());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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
179
    /**
180
     * Ensure that related documents can be retrieved for a given DMS document
181
     */
182
    public function testRelatedDocuments()
183
    {
184
        $document = $this->objFromFixture('DMSDocument', 'document_with_relations');
185
        $this->assertGreaterThan(0, $document->RelatedDocuments()->count());
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<DMSDocumentTest>.

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...
186
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentTest>.

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...
187
            array('test-file-file-doesnt-exist-1', 'test-file-file-doesnt-exist-2'),
188
            $document->getRelatedDocuments()->column('Filename')
189
        );
190
    }
191
192
    /**
193
     * Test the extensibility of getRelatedDocuments
194
     */
195
    public function testGetRelatedDocumentsIsExtensible()
196
    {
197
        DMSDocument::add_extension('StubRelatedDocumentExtension');
198
199
        $emptyDocument = new DMSDocument;
200
        $relatedDocuments = $emptyDocument->getRelatedDocuments();
201
202
        $this->assertCount(1, $relatedDocuments);
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<DMSDocumentTest>.

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...
203
        $this->assertSame('Extended', $relatedDocuments->first()->Filename);
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<DMSDocumentTest>.

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...
204
    }
205
206
    /**
207
     * Ensure that the DMS Document CMS actions contains a grid field for managing related documents
208
     */
209
    public function testDocumentHasCmsFieldForManagingRelatedDocuments()
210
    {
211
        $document = $this->objFromFixture('DMSDocument', 'document_with_relations');
212
213
        $documentFields = $document->getCMSFields();
214
        /** @var FieldGroup $actions */
215
        $actions = $documentFields->fieldByName('ActionsPanel');
216
217
        $gridField = null;
218
        foreach ($actions->getChildren() as $child) {
219
            /** @var FieldGroup $child */
220
            if ($gridField = $child->fieldByName('RelatedDocuments')) {
221
                break;
222
            }
223
        }
224
        $this->assertInstanceOf('GridField', $gridField);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<DMSDocumentTest>.

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
        /** @var GridFieldConfig $gridFieldConfig */
227
        $gridFieldConfig = $gridField->getConfig();
228
229
        $this->assertNotNull(
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<DMSDocumentTest>.

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...
230
            'GridFieldAddExistingAutocompleter',
231
            $addExisting = $gridFieldConfig->getComponentByType('GridFieldAddExistingAutocompleter'),
232
            'Related documents GridField has an "add existing" autocompleter'
233
        );
234
235
        $this->assertNull(
0 ignored issues
show
Bug introduced by
The method assertNull() does not seem to exist on object<DMSDocumentTest>.

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...
236
            $gridFieldConfig->getComponentByType('GridFieldAddNewButton'),
237
            'Related documents GridField does not have an "add new" button'
238
        );
239
    }
240
241
    /*
242
     * Tests whether the permissions fields are added
243
     */
244
    public function testAddPermissionsFields()
245
    {
246
        $document = $this->objFromFixture('DMSDocument', 'd1');
247
        $fields = $document->getCMSFields();
248
249
        $this->assertNotNull($fields->fieldByName('CanViewType'));
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<DMSDocumentTest>.

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...
250
        $this->assertNotNull($fields->fieldByName('ViewerGroups'));
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<DMSDocumentTest>.

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
253
    /**
254
     * Test view permissions
255
     */
256
    public function testCanView()
257
    {
258
        /** @var DMSDocument $document */
259
        $document = $this->objFromFixture('DMSDocument', 'd1');
260
        $document->CanViewType = 'LoggedInUsers';
261
        $document->write();
262
263
        //Make sure user is logged out
264
        if ($member = Member::currentUser()) {
265
            $member->logOut();
266
        }
267
268
        //Logged out user test
269
        $this->assertFalse($document->canView());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DMSDocumentTest>.

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...
270
271
        //Logged in user test
272
        $adminID = $this->logInWithPermission();
273
        $admin = Member::get()->byID($adminID);
274
        $this->assertTrue($document->canView($admin));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentTest>.

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...
275
        /** @var Member $member */
276
        $admin->logout();
277
278
        //Check anyone
279
        $document->CanViewType = 'Anyone';
280
        $document->write();
281
        $this->assertTrue($document->canView());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentTest>.

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...
282
283
        //Check OnlyTheseUsers
284
        $group = $this->objFromFixture('Group', 'content-author');
285
        $document->CanViewType = 'OnlyTheseUsers';
286
        $document->ViewerGroups()->add($group);
0 ignored issues
show
Documentation Bug introduced by
The method ViewerGroups does not exist on object<DMSDocument>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
287
        $document->write();
288
289
        $reportAdminID = $this->logInWithPermission('cable-guy');
290
        /** @var Member $reportAdmin */
291
        $reportAdmin = Member::get()->byID($reportAdminID);
292
        $this->assertFalse($document->canView($reportAdmin));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DMSDocumentTest>.

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...
293
        //Add reportAdmin to group
294
        $reportAdmin->addToGroupByCode('content-author');
295
        $this->assertTrue($document->canView($reportAdmin));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentTest>.

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...
296
        $reportAdmin->logout();
297
    }
298
299
    /**
300
     * Tests edit permissions
301
     */
302
    public function testCanEdit()
303
    {
304
        /** @var DMSDocument $document */
305
306
        $document = $this->objFromFixture('DMSDocument', 'd1');
307
        $document->CanEditType = 'LoggedInUsers';
308
        $document->write();
309
310
        //Make sure user is logged out
311
        if ($member = Member::currentUser()) {
312
            $member->logOut();
313
        }
314
315
        //Logged out user test
316
        $this->assertFalse($document->canEdit());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DMSDocumentTest>.

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...
317
318
        //Logged in user test
319
        $adminID = $this->logInWithPermission();
320
        $admin = Member::get()->byID($adminID);
321
        $this->assertTrue($document->canEdit($adminID));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentTest>.

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...
322
        /** @var Member $member */
323
        $admin->logout();
324
325
        //Check OnlyTheseUsers
326
        $group = $this->objFromFixture('Group', 'content-author');
327
        $document->CanEditType = 'OnlyTheseUsers';
328
        $document->EditorGroups()->add($group);
0 ignored issues
show
Documentation Bug introduced by
The method EditorGroups does not exist on object<DMSDocument>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
329
        $document->write();
330
331
        $reportAdminID = $this->logInWithPermission('cable-guy');
332
        /** @var Member $reportAdmin */
333
        $reportAdmin = Member::get()->byID($reportAdminID);
334
        $this->assertFalse($document->canEdit($reportAdmin));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DMSDocumentTest>.

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...
335
        //Add reportAdmin to group
336
        $reportAdmin->addToGroupByCode('content-author');
337
        $this->assertTrue($document->canEdit($reportAdmin));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentTest>.

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...
338
        $reportAdmin->logout();
339
    }
340
}
341