Completed
Push — master ( eebc60...bc130b )
by Franco
04:09 queued 02:13
created

testDownloadBehaviourOpen()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 20
nc 1
nop 2
1
<?php
2
3
/**
4
 * Class DMSDocumentControllerTest
5
 */
6
class DMSDocumentControllerTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by
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...
7
{
8
    protected static $fixture_file = "dmstest.yml";
9
10
    /**
11
     * Test that the download behaviour is either "open" or "download"
12
     *
13
     * @param string $behaviour
14
     * @param string $expectedDisposition
15
     * @dataProvider behaviourProvider
16
     */
17
    public function testDownloadBehaviourOpen($behaviour, $expectedDisposition)
18
    {
19
        DMS::$dmsFolder = DMS_DIR;    //sneakily setting the DMS folder to the folder where the test file lives
20
21
        $this->logInWithPermission('ADMIN');
22
23
        /** @var DMSDocument_Controller $controller */
24
        $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...
25
            ->setMethods(array('sendFile'))->getMock();
26
27
        $self = $this;
28
        $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...
29
            ->method('sendFile')
30
            ->will(
31
                $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...
32
                    $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...
33
                })
34
            );
35
36
        $openDoc = new DMSDocument();
37
        $openDoc->Filename = "DMS-test-lorum-file.pdf";
0 ignored issues
show
Documentation introduced by
The property Filename does not exist on object<DMSDocument>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
38
        $openDoc->Folder = "tests";
0 ignored issues
show
Documentation introduced by
The property Folder does not exist on object<DMSDocument>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
39
        $openDoc->DownloadBehavior = $behaviour;
0 ignored issues
show
Documentation introduced by
The property DownloadBehavior does not exist on object<DMSDocument>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
40
        $openDoc->clearEmbargo(false);
41
        $openDoc->write();
42
        $request = new SS_HTTPRequest('GET', 'index/' . $openDoc->ID);
43
        $request->match('index/$ID');
44
        $controller->index($request);
45
    }
46
47
    /**
48
     * @return array[]
49
     */
50
    public function behaviourProvider()
51
    {
52
        return array(
53
            array('open', 'inline'),
54
            array('download', 'attachment')
55
        );
56
    }
57
}
58