Completed
Pull Request — master (#168)
by Franco
02:38
created

DMSDocumentTest::logoutMember()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
class DMSDocumentTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by helpfulrobot
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
    public function testDefaultDownloadBehabiourCMSFields()
7
    {
8
        $document = singleton('DMSDocument');
9
        Config::inst()->update('DMSDocument', 'default_download_behaviour', 'open');
10
        $cmsFields = $document->getCMSFields();
11
        $this->assertEquals('open', $cmsFields->dataFieldByName('DownloadBehavior')->Value());
0 ignored issues
show
Bug introduced by Daniel Hensby
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...
12
13
14
        Config::inst()->update('DMSDocument', 'default_download_behaviour', 'download');
15
        $cmsFields = $document->getCMSFields();
16
        $this->assertEquals('download', $cmsFields->dataFieldByName('DownloadBehavior')->Value());
0 ignored issues
show
Bug introduced by Daniel Hensby
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...
17
    }
18
19
    /**
20
     * Ensure that related documents can be retrieved for a given DMS document
21
     */
22
    public function testRelatedDocuments()
23
    {
24
        $document = $this->objFromFixture('DMSDocument', 'document_with_relations');
25
        $this->assertGreaterThan(0, $document->RelatedDocuments()->count());
0 ignored issues
show
Bug introduced by Robbie Averill
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...
26
        $this->assertEquals(
0 ignored issues
show
Bug introduced by Robbie Averill
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...
27
            array('test-file-file-doesnt-exist-1', 'test-file-file-doesnt-exist-2'),
28
            $document->getRelatedDocuments()->column('Filename')
29
        );
30
    }
31
32
    /**
33
     * Test the extensibility of getRelatedDocuments
34
     */
35 View Code Duplication
    public function testGetRelatedDocumentsIsExtensible()
0 ignored issues
show
Duplication introduced by Robbie Averill
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...
36
    {
37
        DMSDocument::add_extension('StubRelatedDocumentExtension');
38
39
        $emptyDocument = new DMSDocument;
40
        $relatedDocuments = $emptyDocument->getRelatedDocuments();
41
42
        $this->assertCount(1, $relatedDocuments);
0 ignored issues
show
Bug introduced by Robbie Averill
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...
43
        $this->assertSame('Extended', $relatedDocuments->first()->Filename);
0 ignored issues
show
Bug introduced by Robbie Averill
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...
44
    }
45
46
    /**
47
     * Ensure that the DMS Document CMS actions contains a grid field for managing related documents
48
     */
49
    public function testDocumentHasCmsFieldForManagingRelatedDocuments()
50
    {
51
        $document = $this->objFromFixture('DMSDocument', 'document_with_relations');
52
        $gridField = $this->getGridFieldFromDocument($document);
0 ignored issues
show
Documentation introduced by Robbie Averill
$document is of type object<DataObject>|null, but the function expects a object<DMSDocument>.

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...
53
        $this->assertInstanceOf('GridField', $gridField);
0 ignored issues
show
Bug introduced by Robbie Averill
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...
54
55
        $gridFieldConfig = $gridField->getConfig();
56
57
        $this->assertNotNull(
0 ignored issues
show
Bug introduced by Robbie Averill
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...
58
            'GridFieldAddExistingAutocompleter',
59
            $addExisting = $gridFieldConfig->getComponentByType('GridFieldAddExistingAutocompleter'),
60
            'Related documents GridField has an "add existing" autocompleter'
61
        );
62
63
        $this->assertNull(
0 ignored issues
show
Bug introduced by Robbie Averill
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...
64
            $gridFieldConfig->getComponentByType('GridFieldAddNewButton'),
65
            'Related documents GridField does not have an "add new" button'
66
        );
67
    }
68
69
    /**
70
     * Ensures that the DMS Document CMS Related and Versions fields are removed if user can't edit
71
     */
72
    public function testDocumentHasNoCMSFieldsForManagingRelatedDocumentsIfCantEdit()
73
    {
74
        $this->logInWithPermission('another-user');
75
        $document = $this->objFromFixture('DMSDocument', 'doc-only-these-users');
76
        $gridField = $this->getGridFieldFromDocument($document);
0 ignored issues
show
Documentation introduced by Robbie Averill
$document is of type object<DataObject>|null, but the function expects a object<DMSDocument>.

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...
77
        $this->assertNull($gridField);
0 ignored issues
show
Bug introduced by Franco Springveldt
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...
78
    }
79
80
    /**
81
     * Ensure that the related documents list does not include the current document itself
82
     */
83
    public function testGetRelatedDocumentsForAutocompleter()
84
    {
85
        $document = $this->objFromFixture('DMSDocument', 'd1');
86
        $gridField = $this->getGridFieldFromDocument($document);
0 ignored issues
show
Documentation introduced by Robbie Averill
$document is of type object<DataObject>|null, but the function expects a object<DMSDocument>.

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...
87
        $this->assertInstanceOf('GridField', $gridField);
0 ignored issues
show
Bug introduced by Franco Springveldt
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...
88
89
        $config = $gridField->getConfig();
90
91
        $autocompleter = $config->getComponentByType('GridFieldAddExistingAutocompleter');
92
        $autocompleter->setResultsFormat('$Filename');
93
94
        $jsonResult = $autocompleter->doSearch(
95
            $gridField,
96
            new SS_HTTPRequest('GET', '/', array('gridfield_relationsearch' => 'test'))
97
        );
98
99
        $this->assertNotContains('test-file-file-doesnt-exist-1', $jsonResult);
100
        $this->assertContains('test-file-file-doesnt-exist-2', $jsonResult);
101
        $this->assertEquals(array('Title:PartialMatch', 'Filename:PartialMatch'), $autocompleter->getSearchFields());
0 ignored issues
show
Bug introduced by Robbie Averill
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...
102
    }
103
104
    /**
105
     * @return GridField
106
     */
107
    protected function getGridFieldFromDocument(DMSDocument $document)
108
    {
109
        $documentFields = $document->getCMSFields();
110
        /** @var FieldGroup $actions */
111
        $actions = $documentFields->fieldByName('ActionsPanel');
112
113
        $gridField = null;
114
        foreach ($actions->getChildren() as $child) {
115
            /** @var FieldGroup $child */
116
            if ($gridField = $child->fieldByName('RelatedDocuments')) {
117
                break;
118
            }
119
        }
120
        return $gridField;
121
    }
122
123
    /**
124
     * Ensure that HTML is returned containing list items with action panel steps
125
     */
126
    public function testGetActionTaskHtml()
127
    {
128
        $document = $this->objFromFixture('DMSDocument', 'd1');
129
        $document->addActionPanelTask('example', 'Example');
130
131
        $result = $document->getActionTaskHtml();
132
133
        $this->assertContains('<label class="left">Actions</label>', $result);
134
        $this->assertContains('<li class="ss-ui-button dmsdocument-action" data-panel="', $result);
135
        $this->assertContains('permission', $result);
136
        $this->assertContains('Example', $result);
137
138
        $actions = array('example', 'embargo','find-usage');
139
        foreach ($actions as $action) {
140
            // Test remove with string
141
            $document->removeActionPanelTask($action);
142
        }
143
        $result = $document->getActionTaskHtml();
144
145
        $this->assertNotContains('Example', $result);
146
        $this->assertNotContains('embargo', $result);
147
        $this->assertNotContains('find-usage', $result);
148
    }
149
150
    /*
151
     * Tests whether the permissions fields are added
152
     */
153
    public function testGetPermissionsActionPanel()
154
    {
155
        $result = $this->objFromFixture('DMSDocument', 'd1')->getPermissionsActionPanel();
156
157
        $this->assertInstanceOf('CompositeField', $result);
0 ignored issues
show
Bug introduced by Robbie Averill
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...
158
        $this->assertNotNull($result->getChildren()->fieldByName('CanViewType'));
0 ignored issues
show
Bug introduced by Robbie Averill
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...
159
        $this->assertNotNull($result->getChildren()->fieldByName('ViewerGroups'));
0 ignored issues
show
Bug introduced by Robbie Averill
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...
160
    }
161
162
    /**
163
     * Test view permissions
164
     */
165
    public function testCanView()
166
    {
167
        /** @var DMSDocument $document */
168
        $document = $this->objFromFixture('DMSDocument', 'doc-logged-in-users');
169
        $this->logoutMember();
170
        // Logged out user test
171
        $this->assertFalse($document->canView());
0 ignored issues
show
Bug introduced by Franco Springveldt
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...
172
173
        // Logged in user test
174
        $adminID = $this->logInWithPermission();
175
        $admin = Member::get()->byID($adminID);
176
        $this->assertTrue($document->canView($admin));
0 ignored issues
show
Bug introduced by Franco Springveldt
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...
177
        /** @var Member $member */
178
        $admin->logout();
179
180
        // Check anyone
181
        $document = $this->objFromFixture('DMSDocument', 'doc-anyone');
182
        $this->assertTrue($document->canView());
0 ignored issues
show
Bug introduced by Franco Springveldt
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...
183
184
        // Check OnlyTheseUsers
185
        $document = $this->objFromFixture('DMSDocument', 'doc-only-these-users');
186
        $reportAdminID = $this->logInWithPermission('cable-guy');
187
        /** @var Member $reportAdmin */
188
        $reportAdmin = Member::get()->byID($reportAdminID);
189
        $this->assertFalse($document->canView($reportAdmin));
0 ignored issues
show
Bug introduced by Franco Springveldt
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...
190
        // Add reportAdmin to group
191
        $reportAdmin->addToGroupByCode('content-author');
192
        $this->assertTrue($document->canView($reportAdmin));
0 ignored issues
show
Bug introduced by Franco Springveldt
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...
193
        $reportAdmin->logout();
194
    }
195
196
    /**
197
     * Tests edit permissions
198
     */
199
    public function testCanEdit()
200
    {
201
        $this->logoutMember();
202
203
        /** @var DMSDocument $document1 */
204
        $document1 = $this->objFromFixture('DMSDocument', 'doc-logged-in-users');
205
206
        // Logged out user test
207
        $this->assertFalse($document1->canEdit());
0 ignored issues
show
Bug introduced by Franco Springveldt
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...
208
209
        //Logged in user test
210
        $contentAuthor = $this->objFromFixture('Member', 'editor');
211
        $this->assertTrue($document1->canEdit($contentAuthor));
0 ignored issues
show
Bug introduced by Franco Springveldt
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...
212
213
        // Check OnlyTheseUsers
214
        /** @var DMSDocument $document2 */
215
        $document2 = $this->objFromFixture('DMSDocument', 'doc-only-these-users');
216
        /** @var Member $cableGuy */
217
        $cableGuy = $this->objFromFixture('Member', 'non-editor');
218
        $this->assertFalse($document2->canEdit($cableGuy));
0 ignored issues
show
Bug introduced by Franco Springveldt
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...
219
220
        $cableGuy->addToGroupByCode('content-author');
221
        $this->assertTrue($document2->canEdit($cableGuy));
0 ignored issues
show
Bug introduced by Franco Springveldt
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...
222
    }
223
224
    /**
225
     * Tests delete permissions
226
     */
227 View Code Duplication
    public function testCanDelete()
0 ignored issues
show
Duplication introduced by Franco Springveldt
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...
228
    {
229
        $this->logoutMember();
230
        $document1 = $this->objFromFixture('DMSDocument', 'doc-logged-in-users');
231
232
        // Logged out user test
233
        $this->assertFalse($document1->canDelete());
0 ignored issues
show
Bug introduced by Franco Springveldt
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...
234
235
        // Test editors can delete
236
        $contentAuthor = $this->objFromFixture('Member', 'editor');
237
        $this->assertTrue($document1->canDelete($contentAuthor));
0 ignored issues
show
Bug introduced by Franco Springveldt
It seems like $contentAuthor defined by $this->objFromFixture('Member', 'editor') on line 236 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by Franco Springveldt
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...
238
    }
239
240
    /**
241
     * Tests create permission
242
     */
243 View Code Duplication
    public function testCanCreate()
0 ignored issues
show
Duplication introduced by Franco Springveldt
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...
244
    {
245
        $this->logoutMember();
246
        $document1 = $this->objFromFixture('DMSDocument', 'doc-logged-in-users');
247
        $this->logInWithPermission('CMS_ACCESS_DMSDocumentAdmin');
248
        // Test CMS access can create
249
        $this->assertTrue($document1->canCreate());
0 ignored issues
show
Bug introduced by Franco Springveldt
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...
250
251
        $this->logoutMember();
252
253
        // Test editors can create
254
        $contentAuthor = $this->objFromFixture('Member', 'editor');
255
        $this->assertTrue($document1->canCreate($contentAuthor));
0 ignored issues
show
Bug introduced by Franco Springveldt
It seems like $contentAuthor defined by $this->objFromFixture('Member', 'editor') on line 254 can also be of type object<DataObject>; however, DataObject::canCreate() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by Franco Springveldt
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...
256
    }
257
258
    /**
259
     * Logs out any active member
260
     */
261
    protected function logoutMember()
262
    {
263
        if ($member = Member::currentUser()) {
264
            $member->logOut();
265
        }
266
    }
267
268
    /**
269
     * Test permission denied reasons for documents
270
     */
271
    public function testGetPermissionDeniedReason()
272
    {
273
        /** @var DMSDocument $document1 */
274
        $doc1 = $this->objFromFixture('DMSDocument', 'doc-logged-in-users');
275
        $this->assertContains('Please log in to view this document', $doc1->getPermissionDeniedReason());
276
277
        /** @var DMSDocument $doc2 */
278
        $doc2 = $this->objFromFixture('DMSDocument', 'doc-only-these-users');
279
        $this->assertContains('You are not authorised to view this document', $doc2->getPermissionDeniedReason());
280
281
        /** @var DMSDocument $doc3 */
282
        $doc3 = $this->objFromFixture('DMSDocument', 'doc-anyone');
283
        $this->assertEquals('', $doc3->getPermissionDeniedReason());
0 ignored issues
show
Bug introduced by Franco Springveldt
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...
284
    }
285
286
    /**
287
     * Ensure that all pages that a document belongs to (via many document sets) can be retrieved in one list
288
     */
289
    public function testGetRelatedPages()
290
    {
291
        $document = $this->objFromFixture('DMSDocument', 'd1');
292
        $result = $document->getRelatedPages();
293
        $this->assertCount(3, $result, 'Document 1 is related to 3 Pages');
0 ignored issues
show
Bug introduced by Robbie Averill
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...
294
        $this->assertSame(array('s1', 's2', 's3'), $result->column('URLSegment'));
0 ignored issues
show
Bug introduced by Robbie Averill
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...
295
    }
296
297
    /**
298
     * Test that the title is returned if it is set, otherwise the filename without ID
299
     */
300
    public function testGetTitleOrFilenameWithoutId()
301
    {
302
        $d1 = $this->objFromFixture('DMSDocument', 'd1');
303
        $this->assertSame('test-file-file-doesnt-exist-1', $d1->getTitle());
0 ignored issues
show
Bug introduced by Sacha Judd
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...
304
305
        $d2 = $this->objFromFixture('DMSDocument', 'd2');
306
        $this->assertSame('File That Doesn\'t Exist (Title)', $d2->getTitle());
0 ignored issues
show
Bug introduced by Sacha Judd
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...
307
    }
308
309
    /**
310
     * Ensure that the folder a document's file is stored in can be retrieved, and that delete() will also delete
311
     * the file and the record
312
     */
313
    public function testGetStorageFolderThenDelete()
314
    {
315
        Config::inst()->update('DMS', 'folder_name', 'assets/_unit-tests');
316
317
        $document = DMS::inst()->storeDocument('dms/tests/DMS-test-lorum-file.pdf');
318
        $filename = $document->getStorageFolder() . '/' . $document->getFilename();
319
320
        $this->assertTrue(file_exists($filename));
0 ignored issues
show
Bug introduced by Robbie Averill
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...
321
        $document->delete();
322
        $this->assertFalse($document->exists());
0 ignored issues
show
Bug introduced by Robbie Averill
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...
323
        $this->assertFalse(file_exists($filename));
0 ignored issues
show
Bug introduced by Robbie Averill
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...
324
325
        DMSFilesystemTestHelper::delete('assets/_unit-tests');
326
    }
327
328
    /**
329
     * Test that the link contains an ID and URL slug
330
     */
331
    public function testGetLink()
332
    {
333
        Config::inst()->update('DMS', 'folder_name', 'assets/_unit-tests');
334
335
        $document = DMS::inst()->storeDocument('dms/tests/DMS-test-lorum-file.pdf');
336
337
        $expected = '/dmsdocument/' . $document->ID . '-dms-test-lorum-file-pdf';
338
        $this->assertSame($expected, $document->Link());
0 ignored issues
show
Bug introduced by Robbie Averill
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...
339
        $this->assertSame($expected, $document->getLink());
0 ignored issues
show
Bug introduced by Robbie Averill
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...
340
    }
341
342
    /**
343
     * Ensure that the description can be returned in HTML format
344
     */
345
    public function testGetDescriptionWithLineBreak()
346
    {
347
        $document = DMSDocument::create();
348
        $document->Description = "Line 1\nLine 2\nLine 3";
349
        $document->write();
350
351
        $this->assertSame("Line 1<br />\nLine 2<br />\nLine 3", $document->getDescriptionWithLineBreak());
0 ignored issues
show
Bug introduced by Robbie Averill
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...
352
    }
353
}
354