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

tests/cms/DMSDocumentAddControllerTest.php (9 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
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()
25
    {
26
        $page = $this->objFromFixture('SiteTree', 's1');
27
28
        $this->assertInstanceOf('SiteTree', $this->controller->currentPage());
0 ignored issues
show
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
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('ID' => $page->ID)));
31
        $this->assertEquals($page->ID, $this->controller->currentPage()->ID, 'Specified page is loaded and returned');
0 ignored issues
show
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()
39
    {
40
        $set = $this->objFromFixture('DMSDocumentSet', 'ds1');
41
42
        $this->assertInstanceOf('DMSDocumentSet', $this->controller->getCurrentDocumentSet());
0 ignored issues
show
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
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
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
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
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, '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
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