Completed
Push — master ( 2e2112...bbe9e3 )
by Franco
01:17 queued 01:13
created

DMSDocumentTest::testRelatedDocuments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
class DMSDocumentTest 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...
3
{
4
    protected static $fixture_file = 'dmstest.yml';
5
6 View Code Duplication
    public function tearDownOnce()
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...
7
    {
8
        self::$is_running_test = true;
9
10
        $d = DataObject::get('DMSDocument');
11
        foreach ($d as $d1) {
12
            $d1->delete();
13
        }
14
        $t = DataObject::get('DMSTag');
15
        foreach ($t as $t1) {
16
            $t1->delete();
17
        }
18
19
        self::$is_running_test = $this->originalIsRunningTest;
20
    }
21
22
    public function testPageRelations()
23
    {
24
        $s1 = $this->objFromFixture('SiteTree', 's1');
25
        $s2 = $this->objFromFixture('SiteTree', 's2');
26
        $s3 = $this->objFromFixture('SiteTree', 's3');
27
        $s4 = $this->objFromFixture('SiteTree', 's4');
28
        $s5 = $this->objFromFixture('SiteTree', 's5');
29
        $s6 = $this->objFromFixture('SiteTree', 's6');
30
31
        $d1 = $this->objFromFixture('DMSDocument', 'd1');
32
33
        $pages = $d1->Pages();
34
        $pagesArray = $pages->toArray();
35
        $this->assertEquals($pagesArray[0]->ID, $s1->ID, 'Page 1 associated correctly');
0 ignored issues
show
Bug introduced by
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...
36
        $this->assertEquals($pagesArray[1]->ID, $s2->ID, 'Page 2 associated correctly');
0 ignored issues
show
Bug introduced by
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...
37
        $this->assertEquals($pagesArray[2]->ID, $s3->ID, 'Page 3 associated correctly');
0 ignored issues
show
Bug introduced by
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...
38
        $this->assertEquals($pagesArray[3]->ID, $s4->ID, 'Page 4 associated correctly');
0 ignored issues
show
Bug introduced by
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...
39
        $this->assertEquals($pagesArray[4]->ID, $s5->ID, 'Page 5 associated correctly');
0 ignored issues
show
Bug introduced by
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...
40
        $this->assertEquals($pagesArray[5]->ID, $s6->ID, 'Page 6 associated correctly');
0 ignored issues
show
Bug introduced by
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...
41
    }
42
43
    public function testAddPageRelation()
44
    {
45
        $s1 = $this->objFromFixture('SiteTree', 's1');
46
        $s2 = $this->objFromFixture('SiteTree', 's2');
47
        $s3 = $this->objFromFixture('SiteTree', 's3');
48
49
        $doc = new DMSDocument();
50
        $doc->Filename = 'test file';
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...
51
        $doc->Folder = '0';
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...
52
        $doc->write();
53
54
        $doc->addPage($s1);
0 ignored issues
show
Documentation introduced by
$s1 is of type object<DataObject>|null, but the function expects a object<SiteTree>.

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...
55
        $doc->addPage($s2);
0 ignored issues
show
Documentation introduced by
$s2 is of type object<DataObject>|null, but the function expects a object<SiteTree>.

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...
56
        $doc->addPage($s3);
0 ignored issues
show
Documentation introduced by
$s3 is of type object<DataObject>|null, but the function expects a object<SiteTree>.

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...
57
58
        $pages = $doc->Pages();
59
        $pagesArray = $pages->toArray();
60
        $this->assertEquals($pagesArray[0]->ID, $s1->ID, 'Page 1 associated correctly');
0 ignored issues
show
Bug introduced by
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...
61
        $this->assertEquals($pagesArray[1]->ID, $s2->ID, 'Page 2 associated correctly');
0 ignored issues
show
Bug introduced by
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...
62
        $this->assertEquals($pagesArray[2]->ID, $s3->ID, 'Page 3 associated correctly');
0 ignored issues
show
Bug introduced by
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...
63
64
        $doc->removePage($s1);
0 ignored issues
show
Compatibility introduced by
$s1 of type object<DataObject> is not a sub-type of object<SiteTree>. It seems like you assume a child class of the class DataObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
65
        $pages = $doc->Pages();
66
        $pagesArray = $pages->toArray();    // Page 1 is missing
67
        $this->assertEquals($pagesArray[0]->ID, $s2->ID, 'Page 2 still associated correctly');
0 ignored issues
show
Bug introduced by
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...
68
        $this->assertEquals($pagesArray[1]->ID, $s3->ID, 'Page 3 still associated correctly');
0 ignored issues
show
Bug introduced by
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...
69
70
        $documents = $s2->Documents();
71
        $documentsArray = $documents->toArray();
72
        $this->assertDOSContains(
73
            array(
74
                array('Filename' => $doc->Filename)
0 ignored issues
show
Documentation introduced by
The property Filename does not exist on object<DMSDocument>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
75
            ),
76
            $documentsArray,
77
            'Document associated with page'
0 ignored issues
show
Unused Code introduced by
The call to DMSDocumentTest::assertDOSContains() has too many arguments starting with 'Document associated with page'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
78
        );
79
80
        $doc->removeAllPages();
81
        $pages = $doc->Pages();
82
        $this->assertEquals($pages->Count(), 0, 'All pages removed');
0 ignored issues
show
Bug introduced by
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...
83
84
        $documents = $s2->Documents();
85
        $documentsArray = $documents->toArray();
86
        $this->assertNotContains($doc, $documentsArray, 'Document no longer associated with page');
87
    }
88
89
    public function testDeletingPageWithAssociatedDocuments()
90
    {
91
        $s1 = $this->objFromFixture('SiteTree', 's1');
92
        $s2 = $this->objFromFixture('SiteTree', 's2');
93
        $s2->publish('Stage', 'Live');
94
        $s2ID = $s2->ID;
95
96
        $doc = new DMSDocument();
97
        $doc->Filename = 'delete test file';
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...
98
        $doc->Folder = '0';
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...
99
        $doc->write();
100
101
        $doc->addPage($s1);
0 ignored issues
show
Documentation introduced by
$s1 is of type object<DataObject>|null, but the function expects a object<SiteTree>.

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...
102
        $doc->addPage($s2);
0 ignored issues
show
Compatibility introduced by
$s2 of type object<DataObject> is not a sub-type of object<SiteTree>. It seems like you assume a child class of the class DataObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
103
104
        $s1->delete();
105
106
        $documents = DataObject::get("DMSDocument", "\"Filename\" = 'delete test file'", false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a string|array.

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...
107
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
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...
108
            $documents->Count(),
109
            '1',
110
            "Deleting one of the associated page doesn't affect the single document we created"
111
        );
112
113
        $s2->delete();
114
        $documents = DataObject::get("DMSDocument", "\"Filename\" = 'delete test file'");
115
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
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...
116
            $documents->Count(),
117
            '1',
118
            "Deleting a page from draft stage doesn't delete the associated docs,"
119
            . "even if it's the last page they're associated with"
120
        );
121
122
        $s2 = Versioned::get_one_by_stage('SiteTree', 'Live', sprintf('"SiteTree"."ID" = %d', $s2ID));
123
        $s2->doDeleteFromLive();
0 ignored issues
show
Bug introduced by
The method doDeleteFromLive() does not exist on DataObject. Did you maybe mean delete()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
124
        $documents = DataObject::get("DMSDocument", "\"Filename\" = 'delete test file'");
125
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
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...
126
            $documents->Count(),
127
            '0',
128
            'However, deleting the live version of the last page that a document is '
129
            . 'associated with causes that document to be deleted as well'
130
        );
131
    }
132
133
    public function testUnpublishPageWithAssociatedDocuments()
134
    {
135
        $s2 = $this->objFromFixture('SiteTree', 's2');
136
        $s2->publish('Stage', 'Live');
137
        $s2ID = $s2->ID;
138
139
        $doc = new DMSDocument();
140
        $doc->Filename = 'delete test file';
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...
141
        $doc->Folder = '0';
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...
142
        $doc->write();
143
144
        $doc->addPage($s2);
0 ignored issues
show
Compatibility introduced by
$s2 of type object<DataObject> is not a sub-type of object<SiteTree>. It seems like you assume a child class of the class DataObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
145
146
        $s2->doDeleteFromLive();
0 ignored issues
show
Bug introduced by
The method doDeleteFromLive() does not exist on DataObject. Did you maybe mean delete()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
147
        $documents = DataObject::get("DMSDocument", "\"Filename\" = 'delete test file'");
148
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
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...
149
            $documents->Count(),
150
            '1',
151
            "Deleting a page from live stage doesn't delete the associated docs,"
152
            . "even if it's the last page they're associated with"
153
        );
154
155
        $s2 = Versioned::get_one_by_stage('SiteTree', 'Stage', sprintf('"SiteTree"."ID" = %d', $s2ID));
156
        $s2->delete();
157
        $documents = DataObject::get("DMSDocument", "\"Filename\" = 'delete test file'");
158
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
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...
159
            $documents->Count(),
160
            '0',
161
            'However, deleting the draft version of the last page that a document is '
162
            . 'associated with causes that document to be deleted as well'
163
        );
164
    }
165
166
    public function testDefaultDownloadBehabiourCMSFields()
167
    {
168
        $document = singleton('DMSDocument');
169
        Config::inst()->update('DMSDocument', 'default_download_behaviour', 'open');
170
        $cmsFields = $document->getCMSFields();
171
        $this->assertEquals('open', $cmsFields->dataFieldByName('DownloadBehavior')->Value());
0 ignored issues
show
Bug introduced by
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...
172
173
174
        Config::inst()->update('DMSDocument', 'default_download_behaviour', 'download');
175
        $cmsFields = $document->getCMSFields();
176
        $this->assertEquals('download', $cmsFields->dataFieldByName('DownloadBehavior')->Value());
0 ignored issues
show
Bug introduced by
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...
177
    }
178
179
    /**
180
     * Ensure that related documents can be retrieved for a given DMS document
181
     */
182
    public function testRelatedDocuments()
183
    {
184
        $document = $this->objFromFixture('DMSDocument', 'document_with_relations');
185
        $this->assertGreaterThan(0, $document->RelatedDocuments()->count());
0 ignored issues
show
Bug introduced by
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...
186
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
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...
187
            array('test-file-file-doesnt-exist-1', 'test-file-file-doesnt-exist-2'),
188
            $document->getRelatedDocuments()->column('Filename')
189
        );
190
    }
191
192
    /**
193
     * Test the extensibility of getRelatedDocuments
194
     */
195
    public function testGetRelatedDocumentsIsExtensible()
196
    {
197
        DMSDocument::add_extension('StubRelatedDocumentExtension');
198
199
        $emptyDocument = new DMSDocument;
200
        $relatedDocuments = $emptyDocument->getRelatedDocuments();
201
202
        $this->assertCount(1, $relatedDocuments);
0 ignored issues
show
Bug introduced by
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...
203
        $this->assertSame('Extended', $relatedDocuments->first()->Filename);
0 ignored issues
show
Bug introduced by
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...
204
    }
205
206
    /**
207
     * Ensure that the DMS Document CMS actions contains a grid field for managing related documents
208
     */
209
    public function testDocumentHasCmsFieldForManagingRelatedDocuments()
210
    {
211
        $document = $this->objFromFixture('DMSDocument', 'document_with_relations');
212
213
        $documentFields = $document->getCMSFields();
214
        /** @var FieldGroup $actions */
215
        $actions = $documentFields->fieldByName('ActionsPanel');
216
217
        $gridField = null;
218
        foreach ($actions->getChildren() as $child) {
219
            /** @var FieldGroup $child */
220
            if ($gridField = $child->fieldByName('RelatedDocuments')) {
221
                break;
222
            }
223
        }
224
        $this->assertInstanceOf('GridField', $gridField);
0 ignored issues
show
Bug introduced by
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...
225
226
        /** @var GridFieldConfig $gridFieldConfig */
227
        $gridFieldConfig = $gridField->getConfig();
228
229
        $this->assertNotNull(
0 ignored issues
show
Bug introduced by
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...
230
            'GridFieldAddExistingAutocompleter',
231
            $addExisting = $gridFieldConfig->getComponentByType('GridFieldAddExistingAutocompleter'),
232
            'Related documents GridField has an "add existing" autocompleter'
233
        );
234
235
        $this->assertNull(
0 ignored issues
show
Bug introduced by
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...
236
            $gridFieldConfig->getComponentByType('GridFieldAddNewButton'),
237
            'Related documents GridField does not have an "add new" button'
238
        );
239
    }
240
}
241