Completed
Push — master ( 563dd9...22367a )
by Robbie
08:19
created

testPrintRequestCountIsShownInDocumentSummary()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
class DMSDocumentCartExtensionTest 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...
4
{
5
    protected static $fixture_file = 'DMSDocumentCartExtensionTest.yml';
6
7
    protected $requiredExtensions = array(
8
        'DMSDocument' => array('DMSDocumentCartExtension')
9
    );
10
11
    public function testMaximumCartQuantity()
12
    {
13
        $document = DMSDocument::create(array('AllowedInCart' => true, 'MaximumCartQuantity' => ''));
14
15
        $this->assertFalse($document->getHasQuantityLimit());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DMSDocumentCartExtensionTest>.

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...
16
17
        $document->MaximumCartQuantity = 0;
18
        $this->assertFalse($document->getHasQuantityLimit());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DMSDocumentCartExtensionTest>.

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...
19
20
        $document->MaximumCartQuantity = 1;
21
        $this->assertTrue($document->getHasQuantityLimit());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartExtensionTest>.

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...
22
        $this->assertSame(1, $document->getMaximumQuantity());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<DMSDocumentCartExtensionTest>.

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
24
        $document->MaximumCartQuantity = 10;
25
        $this->assertSame(10, $document->getMaximumQuantity());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<DMSDocumentCartExtensionTest>.

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...
26
    }
27
28
    /**
29
     * The CSS classes are required for the CMS Javascript to work, assert that they are correct
30
     */
31 View Code Duplication
    public function testCmsFieldsHaveRequiredCssClasses()
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...
32
    {
33
        $fields = DMSDocument::create()->getCMSFields();
34
35
        $allowedInCart = $fields->fieldByName('AllowedInCart');
36
        $this->assertInstanceOf('CheckboxField', $allowedInCart);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<DMSDocumentCartExtensionTest>.

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->assertTrue((bool) $allowedInCart->hasClass('dms-allowed-in-cart'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartExtensionTest>.

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
39
        $allowedInCart = $fields->fieldByName('MaximumCartQuantity');
40
        $this->assertInstanceOf('TextField', $allowedInCart);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<DMSDocumentCartExtensionTest>.

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
        $this->assertTrue((bool) $allowedInCart->hasClass('dms-maximum-cart-quantity'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartExtensionTest>.

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...
42
    }
43
44
    /**
45
     * Ensure that validation messages can be retrieved once, cleared, then not again
46
     */
47
    public function testGetValidationResult()
48
    {
49
        Session::set('dms-cart-validation-message', 'testing');
50
        $this->assertSame('testing', DMSDocument::create()->getValidationResult());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<DMSDocumentCartExtensionTest>.

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...
51
        $this->assertFalse(DMSDocument::create()->getValidationResult());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DMSDocumentCartExtensionTest>.

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...
52
    }
53
54
    /**
55
     * Test that print request count is shown in the document's summary
56
     */
57 View Code Duplication
    public function testPrintRequestCountIsShownInDocumentSummary()
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...
58
    {
59
        $document = $this->objFromFixture('DMSDocument', 'requested_for_print');
60
        $fields = $document->getCMSFields();
61
62
        // Results of DMSDocument::getFieldsForFile is the first in the list
63
        $summary = $fields->first();
64
        $this->assertInstanceOf('FieldGroup', $summary);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<DMSDocumentCartExtensionTest>.

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...
65
66
        $printRequestField = $summary->FieldList()
67
            ->fieldByName('FilePreview.FilePreviewData.FilePreviewDataFields.PrintRequestCount');
68
69
        $this->assertNotNull($printRequestField, 'Print request count field exists in DMSDocument fields');
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<DMSDocumentCartExtensionTest>.

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...
70
        $this->assertEquals(3, $printRequestField->Value());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentCartExtensionTest>.

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...
71
    }
72
73
    /**
74
     * @expectedException DMSDocumentCartException
75
     * @expectedExceptionMessage peanut is not accepted for this method.
76
     */
77
    public function testGetActionLinkThrowsExceptionOnInvalidAction()
78
    {
79
        DMSDocument::singleton()->getActionLink('Peanut');
80
    }
81
}
82