DMSDocumentControllerTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 7
dl 0
loc 66
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A tearDown() 0 5 1
A testDownloadBehaviourOpen() 0 20 1
A behaviourProvider() 0 7 1
1
<?php
2
3
/**
4
 * Class DMSDocumentControllerTest
5
 */
6
class DMSDocumentControllerTest extends SapphireTest
7
{
8
    protected static $fixture_file = 'dmstest.yml';
9
10
    /**
11
     * @var DMSDocument_Controller
12
     */
13
    protected $controller;
14
15
    public function setUp()
16
    {
17
        parent::setUp();
18
19
        Config::inst()->update('DMS', 'folder_name', 'assets/_unit-test-123');
20
        $this->logInWithPermission('ADMIN');
21
22
        $this->controller = $this->getMockBuilder('DMSDocument_Controller')
0 ignored issues
show
Bug introduced by
The method getMockBuilder() does not seem to exist on object<DMSDocumentControllerTest>.

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...
23
            ->setMethods(array('sendFile'))
24
            ->getMock();
25
    }
26
27
    public function tearDown()
28
    {
29
        DMSFilesystemTestHelper::delete('assets/_unit-test-123');
30
        parent::tearDown();
31
    }
32
33
    /**
34
     * Test that the download behaviour is either "open" or "download"
35
     *
36
     * @param string $behaviour
37
     * @param string $expectedDisposition
38
     * @dataProvider behaviourProvider
39
     */
40
    public function testDownloadBehaviourOpen($behaviour, $expectedDisposition)
41
    {
42
        $self = $this;
43
        $this->controller->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<DMSDocumentControllerTest>.

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...
Documentation Bug introduced by
The method expects does not exist on object<DMSDocument_Controller>? 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...
44
            ->method('sendFile')
45
            ->will(
46
                $this->returnCallback(function ($path, $mime, $name, $disposition) use ($self, $expectedDisposition) {
0 ignored issues
show
Bug introduced by
The method returnCallback() does not seem to exist on object<DMSDocumentControllerTest>.

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...
47
                    $self->assertEquals($expectedDisposition, $disposition);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentControllerTest>.

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...
48
                })
49
            );
50
51
        $openDoc = DMS::inst()->storeDocument('dms/tests/DMS-test-lorum-file.pdf');
52
        $openDoc->DownloadBehavior = $behaviour;
53
        $openDoc->clearEmbargo(false);
54
        $openDoc->write();
55
56
        $request = new SS_HTTPRequest('GET', $openDoc->Link());
57
        $request->match('dmsdocument/$ID');
58
        $this->controller->index($request);
59
    }
60
61
    /**
62
     * @return array[]
63
     */
64
    public function behaviourProvider()
65
    {
66
        return array(
67
            array('open', 'inline'),
68
            array('download', 'attachment')
69
        );
70
    }
71
}
72