1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Tests DMS shortcode linking functionality. |
4
|
|
|
* |
5
|
|
|
* @package dms |
6
|
|
|
* @subpackage tests |
7
|
|
|
*/ |
8
|
|
|
class DMSShortcodeHandlerTest extends SapphireTest |
9
|
|
|
{ |
10
|
|
|
protected static $fixture_file = 'dmstest.yml'; |
11
|
|
|
|
12
|
|
|
public function testShortcodeOperation() |
13
|
|
|
{ |
14
|
|
|
Config::inst()->update('DMS', 'folder_name', 'assets/_unit-test-123'); |
15
|
|
|
|
16
|
|
|
$file = 'dms/tests/DMS-test-lorum-file.pdf'; |
17
|
|
|
$document = DMS::inst()->storeDocument($file); |
18
|
|
|
|
19
|
|
|
$result = ShortcodeParser::get('default')->parse(sprintf( |
20
|
|
|
'<p><a href="[dms_document_link id=\'%d\']">Document</a></p>', |
21
|
|
|
$document->ID |
22
|
|
|
)); |
23
|
|
|
|
24
|
|
|
$value = Injector::inst()->create('HTMLValue', $result); |
25
|
|
|
$link = $value->query('//a')->item(0); |
26
|
|
|
|
27
|
|
|
$this->assertStringEndsWith( |
|
|
|
|
28
|
|
|
'/dmsdocument/' . $document->ID . '-dms-test-lorum-file-pdf', |
29
|
|
|
$link->getAttribute('href') |
30
|
|
|
); |
31
|
|
|
$this->assertEquals($document->getExtension(), $link->getAttribute('data-ext')); |
|
|
|
|
32
|
|
|
$this->assertEquals($document->getFileSizeFormatted(), $link->getAttribute('data-size')); |
|
|
|
|
33
|
|
|
|
34
|
|
|
DMSFilesystemTestHelper::delete('assets/_unit-test-123'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* When the document is valid, the correct arguments are provided and some content is given, the content should |
39
|
|
|
* be parsed and added into an anchor to the document |
40
|
|
|
*/ |
41
|
|
|
public function testShortcodeWithContentReturnsParsedContentInLink() |
42
|
|
|
{ |
43
|
|
|
$document = $this->objFromFixture('DMSDocument', 'd1'); |
44
|
|
|
$arguments = array('id' => $document->ID); |
45
|
|
|
$result = DMSShortcodeHandler::handle($arguments, 'Some content', ShortcodeParser::get('default'), ''); |
46
|
|
|
|
47
|
|
|
$this->assertSame( |
|
|
|
|
48
|
|
|
'<a href="/dmsdocument/' . $document->ID . '-test-file-file-doesnt-exist-1">Some content</a>', |
49
|
|
|
$result |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* An error page link should be returned if the arguments are not valid, empty or the document is not available etc. |
55
|
|
|
* |
56
|
|
|
* This only applies when an error page with a 404 error code exists. |
57
|
|
|
*/ |
58
|
|
|
public function testReturnErrorPageWhenIdIsEmpty() |
59
|
|
|
{ |
60
|
|
|
ErrorPage::create(array('URLSegment' => 'testing', 'ErrorCode' => '404'))->write(); |
61
|
|
|
$result = DMSShortcodeHandler::handle(array(), '', ShortcodeParser::get('default'), ''); |
62
|
|
|
$this->assertContains('testing', $result); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* When invalid or no data is available to return from the arguments and no error page exists to use for a link, |
67
|
|
|
* return a blank string |
68
|
|
|
*/ |
69
|
|
|
public function testReturnEmptyStringWhenNoErrorPageExistsAndIdIsEmpty() |
70
|
|
|
{ |
71
|
|
|
$this->assertSame('', DMSShortcodeHandler::handle(array(), '', ShortcodeParser::get('default'), '')); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
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.