DMSDocumentAddControllerTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
class DMSDocumentAddControllerTest extends FunctionalTest
4
{
5
    protected static $fixture_file = 'dms/tests/dmstest.yml';
6
7
    /**
8
     * @var DMSDocumentAddController
9
     */
10
    protected $controller;
11
12
    public function setUp()
13
    {
14
        parent::setUp();
15
        $this->logInWithPermission();
16
        $this->controller = new DMSDocumentAddController;
17
        $this->controller->init();
18
    }
19
20
    /**
21
     * Ensure that if no ID is provided then a SiteTree singleton is returned (which will not have an ID). If one is
22
     * provided then it should be loaded from the database via versioning.
23
     */
24 View Code Duplication
    public function testCurrentPageReturnsSiteTree()
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...
25
    {
26
        $page = $this->objFromFixture('SiteTree', 's1');
27
28
        $this->assertInstanceOf('SiteTree', $this->controller->currentPage());
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<DMSDocumentAddControllerTest>.

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...
29
        $this->assertEmpty($this->controller->currentPage()->ID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<DMSDocumentAddControllerTest>.

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...
30
        $this->controller->setRequest(new SS_HTTPRequest('GET', '/', array('page_id' => $page->ID)));
31
        $this->assertEquals($page->ID, $this->controller->currentPage()->ID, 'Specified page is loaded and returned');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentAddControllerTest>.

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...
32
    }
33
34
    /**
35
     * Ensure that if no "dsid" is given a singleton is returned (which will not have an ID). If one is provided
36
     * it should be loaded from the database
37
     */
38 View Code Duplication
    public function testGetCurrentDocumentSetReturnsDocumentSet()
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...
39
    {
40
        $set = $this->objFromFixture('DMSDocumentSet', 'ds1');
41
42
        $this->assertInstanceOf('DMSDocumentSet', $this->controller->getCurrentDocumentSet());
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<DMSDocumentAddControllerTest>.

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->assertEmpty($this->controller->getCurrentDocumentSet()->ID, 'Singleton does not have an ID');
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<DMSDocumentAddControllerTest>.

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
        $this->controller->setRequest(new SS_HTTPRequest('GET', '/', array('dsid' => $set->ID)));
45
        $this->assertEquals($set->ID, $this->controller->getCurrentDocumentSet()->ID, 'Specified document set is returned');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentAddControllerTest>.

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...
46
    }
47
48
    /**
49
     * Test that extra allowed extensions are merged into the default upload field allowed extensions
50
     */
51
    public function testGetAllowedExtensions()
52
    {
53
        Config::inst()->remove('File', 'allowed_extensions');
54
        Config::inst()->update('File', 'allowed_extensions', array('jpg', 'gif'));
55
        $this->assertSame(array('jpg', 'gif'), $this->controller->getAllowedExtensions());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<DMSDocumentAddControllerTest>.

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...
56
57
        Config::inst()->update('DMSDocumentAddController', 'allowed_extensions', array('php', 'php5'));
58
        $this->assertSame(array('jpg', 'gif', 'php', 'php5'), $this->controller->getAllowedExtensions());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<DMSDocumentAddControllerTest>.

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...
59
    }
60
61
    /**
62
     * Test that the back link will be the document set that a file is uploaded into if relevant, otherwise the model
63
     * admin that it was uploaded from
64
     */
65
    public function testBacklink()
66
    {
67
        // No page ID and no document set ID
68
        $this->assertContains('admin/documents', $this->controller->Backlink());
69
70
        // No page ID, has document set ID
71
        $request = new SS_HTTPRequest('GET', '/', array('dsid' => 123));
72
        $this->controller->setRequest($request);
73
        $this->assertContains('EditForm', $this->controller->Backlink());
74
        $this->assertContains('123', $this->controller->Backlink());
75
76
        // Has page ID and document set ID
77
        $request = new SS_HTTPRequest('GET', '/', array('dsid' => 123, 'page_id' => 234));
78
        $this->controller->setRequest($request);
79
        $this->assertContains('admin/pages', $this->controller->Backlink());
80
        $this->assertContains('123', $this->controller->Backlink());
81
    }
82
83
    /**
84
     * Test that the document autocomplete endpoint returns JSON, matching on ID, title or filename (case insensitive)
85
     */
86
    public function testDocumentAutocomplete()
87
    {
88
        $result = (string) $this->get('admin/pages/adddocument/documentautocomplete?term=EXIST')->getBody();
89
        $this->assertJson($result, 'Autocompleter should return JSON');
0 ignored issues
show
Bug introduced by
The method assertJson() does not seem to exist on object<DMSDocumentAddControllerTest>.

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...
90
        $this->assertContains("File That Doesn't Exist (Title)", $result);
91
        $this->assertContains('test-file-file-doesnt-exist-1', $result);
92
        $this->assertNotContains('doc-logged-in-users', $result);
93
94
        $document = $this->objFromFixture('DMSDocument', 'd2');
95
        $result = (string) $this->get('admin/pages/adddocument/documentautocomplete?term=' . $document->ID)->getBody();
96
        $this->assertContains($document->ID . " - File That Doesn't Exist (Title)", $result);
97
    }
98
}
99