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

testDocumentHasNoCMSFieldsForManagingRelatedDocumentsIfCantEdit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
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
        // Test remove with array
139
        $document->removeActionPanelTask('example')->removeActionPanelTask('embargo');
140
        // Test remove with string
141
        $document->removeActionPanelTask('find-usage');
142
        $result = $document->getActionTaskHtml();
143
144
        $this->assertNotContains('Example', $result);
145
        $this->assertNotContains('embargo', $result);
146
        $this->assertNotContains('find-usage', $result);
147
    }
148
149
    /*
150
     * Tests whether the permissions fields are added
151
     */
152
    public function testGetPermissionsActionPanel()
153
    {
154
        $result = $this->objFromFixture('DMSDocument', 'd1')->getPermissionsActionPanel();
155
156
        $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...
157
        $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...
158
        $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...
159
    }
160
161
    /**
162
     * Test view permissions
163
     */
164
    public function testCanView()
165
    {
166
        /** @var DMSDocument $document */
167
        $document = $this->objFromFixture('DMSDocument', 'doc-logged-in-users');
168
        $this->logoutMember();
169
        // Logged out user test
170
        $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...
171
172
        // Logged in user test
173
        $adminID = $this->logInWithPermission();
174
        $admin = Member::get()->byID($adminID);
175
        $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...
176
        /** @var Member $member */
177
        $admin->logout();
178
179
        // Check anyone
180
        $document = $this->objFromFixture('DMSDocument', 'doc-anyone');
181
        $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...
182
183
        // Check OnlyTheseUsers
184
        $document = $this->objFromFixture('DMSDocument', 'doc-only-these-users');
185
        $reportAdminID = $this->logInWithPermission('cable-guy');
186
        /** @var Member $reportAdmin */
187
        $reportAdmin = Member::get()->byID($reportAdminID);
188
        $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...
189
        // Add reportAdmin to group
190
        $reportAdmin->addToGroupByCode('content-author');
191
        $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...
192
        $reportAdmin->logout();
193
    }
194
195
    /**
196
     * Tests edit permissions
197
     */
198
    public function testCanEdit()
199
    {
200
        $this->logoutMember();
201
202
        /** @var DMSDocument $document1 */
203
        $document1 = $this->objFromFixture('DMSDocument', 'doc-logged-in-users');
204
205
        // Logged out user test
206
        $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...
207
208
        //Logged in user test
209
        $contentAuthor = $this->objFromFixture('Member', 'editor');
210
        $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...
211
212
        // Check OnlyTheseUsers
213
        /** @var DMSDocument $document2 */
214
        $document2 = $this->objFromFixture('DMSDocument', 'doc-only-these-users');
215
        /** @var Member $cableGuy */
216
        $cableGuy = $this->objFromFixture('Member', 'non-editor');
217
        $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...
218
219
        $cableGuy->addToGroupByCode('content-author');
220
        $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...
221
    }
222
223
    /**
224
     * Tests delete permissions
225
     */
226 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...
227
    {
228
        $this->logoutMember();
229
        $document1 = $this->objFromFixture('DMSDocument', 'doc-logged-in-users');
230
231
        // Logged out user test
232
        $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...
233
234
        // Test editors can delete
235
        $contentAuthor = $this->objFromFixture('Member', 'editor');
236
        $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 235 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...
237
    }
238
239
    /**
240
     * Tests create permission
241
     */
242 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...
243
    {
244
        $this->logoutMember();
245
        $document1 = $this->objFromFixture('DMSDocument', 'doc-logged-in-users');
246
        $this->logInWithPermission('CMS_ACCESS_DMSDocumentAdmin');
247
        // Test CMS access can create
248
        $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...
249
250
        $this->logoutMember();
251
252
        // Test editors can create
253
        $contentAuthor = $this->objFromFixture('Member', 'editor');
254
        $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 253 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...
255
    }
256
257
    /**
258
     * Logs out any active member
259
     */
260
    protected function logoutMember()
261
    {
262
        if ($member = Member::currentUser()) {
263
            $member->logOut();
264
        }
265
    }
266
267
    /**
268
     * Test permission denied reasons for documents
269
     */
270
    public function testGetPermissionDeniedReason()
271
    {
272
        /** @var DMSDocument $document1 */
273
        $doc1 = $this->objFromFixture('DMSDocument', 'doc-logged-in-users');
274
        $this->assertContains('Please log in to view this document', $doc1->getPermissionDeniedReason());
275
276
        /** @var DMSDocument $doc2 */
277
        $doc2 = $this->objFromFixture('DMSDocument', 'doc-only-these-users');
278
        $this->assertContains('You are not authorised to view this document', $doc2->getPermissionDeniedReason());
279
280
        /** @var DMSDocument $doc3 */
281
        $doc3 = $this->objFromFixture('DMSDocument', 'doc-anyone');
282
        $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...
283
    }
284
285
    /**
286
     * Ensure that all pages that a document belongs to (via many document sets) can be retrieved in one list
287
     */
288
    public function testGetRelatedPages()
289
    {
290
        $document = $this->objFromFixture('DMSDocument', 'd1');
291
        $result = $document->getRelatedPages();
292
        $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...
293
        $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...
294
    }
295
296
    /**
297
     * Test that the title is returned if it is set, otherwise the filename without ID
298
     */
299
    public function testGetTitleOrFilenameWithoutId()
300
    {
301
        $d1 = $this->objFromFixture('DMSDocument', 'd1');
302
        $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...
303
304
        $d2 = $this->objFromFixture('DMSDocument', 'd2');
305
        $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...
306
    }
307
308
    /**
309
     * Ensure that the folder a document's file is stored in can be retrieved, and that delete() will also delete
310
     * the file and the record
311
     */
312
    public function testGetStorageFolderThenDelete()
313
    {
314
        Config::inst()->update('DMS', 'folder_name', 'assets/_unit-tests');
315
316
        $document = DMS::inst()->storeDocument('dms/tests/DMS-test-lorum-file.pdf');
317
        $filename = $document->getStorageFolder() . '/' . $document->getFilename();
318
319
        $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...
320
        $document->delete();
321
        $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...
322
        $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...
323
324
        DMSFilesystemTestHelper::delete('assets/_unit-tests');
325
    }
326
327
    /**
328
     * Test that the link contains an ID and URL slug
329
     */
330
    public function testGetLink()
331
    {
332
        Config::inst()->update('DMS', 'folder_name', 'assets/_unit-tests');
333
334
        $document = DMS::inst()->storeDocument('dms/tests/DMS-test-lorum-file.pdf');
335
336
        $expected = '/dmsdocument/' . $document->ID . '-dms-test-lorum-file-pdf';
337
        $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...
338
        $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...
339
    }
340
341
    /**
342
     * Ensure that the description can be returned in HTML format
343
     */
344
    public function testGetDescriptionWithLineBreak()
345
    {
346
        $document = DMSDocument::create();
347
        $document->Description = "Line 1\nLine 2\nLine 3";
348
        $document->write();
349
350
        $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...
351
    }
352
}
353