1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class DMSDocumentCartExtensionTest extends SapphireTest |
|
|
|
|
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()); |
|
|
|
|
16
|
|
|
|
17
|
|
|
$document->MaximumCartQuantity = 0; |
18
|
|
|
$this->assertFalse($document->getHasQuantityLimit()); |
|
|
|
|
19
|
|
|
|
20
|
|
|
$document->MaximumCartQuantity = 1; |
21
|
|
|
$this->assertTrue($document->getHasQuantityLimit()); |
|
|
|
|
22
|
|
|
$this->assertSame(1, $document->getMaximumQuantity()); |
|
|
|
|
23
|
|
|
|
24
|
|
|
$document->MaximumCartQuantity = 10; |
25
|
|
|
$this->assertSame(10, $document->getMaximumQuantity()); |
|
|
|
|
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() |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$fields = DMSDocument::create()->getCMSFields(); |
34
|
|
|
|
35
|
|
|
$allowedInCart = $fields->fieldByName('AllowedInCart'); |
36
|
|
|
$this->assertInstanceOf('CheckboxField', $allowedInCart); |
|
|
|
|
37
|
|
|
$this->assertTrue((bool) $allowedInCart->hasClass('dms-allowed-in-cart')); |
|
|
|
|
38
|
|
|
|
39
|
|
|
$allowedInCart = $fields->fieldByName('MaximumCartQuantity'); |
40
|
|
|
$this->assertInstanceOf('TextField', $allowedInCart); |
|
|
|
|
41
|
|
|
$this->assertTrue((bool) $allowedInCart->hasClass('dms-maximum-cart-quantity')); |
|
|
|
|
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()); |
|
|
|
|
51
|
|
|
$this->assertFalse(DMSDocument::create()->getValidationResult()); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Test that print request count is shown in the document's summary |
56
|
|
|
*/ |
57
|
|
View Code Duplication |
public function testPrintRequestCountIsShownInDocumentSummary() |
|
|
|
|
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); |
|
|
|
|
65
|
|
|
|
66
|
|
|
$printRequestField = $summary->FieldList() |
67
|
|
|
->fieldByName('FilePreview.FilePreviewData.FilePreviewDataFields.PrintRequestCount'); |
68
|
|
|
|
69
|
|
|
$this->assertNotNull($printRequestField, 'Print request count field exists in DMSDocument fields'); |
|
|
|
|
70
|
|
|
$this->assertEquals(3, $printRequestField->Value()); |
|
|
|
|
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
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.