2013-10-09 11:54:08 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Tests DMS shortcode linking functionality.
|
2014-01-10 03:19:12 +01:00
|
|
|
*
|
|
|
|
* @package dms
|
|
|
|
* @subpackage tests
|
2013-10-09 11:54:08 +02:00
|
|
|
*/
|
2015-12-17 19:48:37 +01:00
|
|
|
class DMSShortcodeTest extends SapphireTest
|
|
|
|
{
|
|
|
|
public function testShortcodeOperation()
|
|
|
|
{
|
2017-05-17 06:24:25 +02:00
|
|
|
Config::inst()->update('DMS', 'folder_name', 'assets/_unit-test-123');
|
|
|
|
|
2015-12-17 19:48:37 +01:00
|
|
|
$file = 'dms/tests/DMS-test-lorum-file.pdf';
|
|
|
|
$document = DMS::inst()->storeDocument($file);
|
2013-10-09 11:54:08 +02:00
|
|
|
|
2015-12-17 19:48:37 +01:00
|
|
|
$result = ShortcodeParser::get('default')->parse(sprintf(
|
2017-05-01 05:54:48 +02:00
|
|
|
'<p><a href="[dms_document_link id=\'%d\']">Document</a></p>',
|
|
|
|
$document->ID
|
2015-12-17 19:48:37 +01:00
|
|
|
));
|
2013-10-09 11:54:08 +02:00
|
|
|
|
2015-12-17 19:48:37 +01:00
|
|
|
$value = Injector::inst()->create('HTMLValue', $result);
|
|
|
|
$link = $value->query('//a')->item(0);
|
2013-10-09 11:54:08 +02:00
|
|
|
|
2015-12-17 19:48:37 +01:00
|
|
|
$this->assertStringEndsWith("/dmsdocument/$document->ID", $link->getAttribute('href'));
|
|
|
|
$this->assertEquals($document->getExtension(), $link->getAttribute('data-ext'));
|
|
|
|
$this->assertEquals($document->getFileSizeFormatted(), $link->getAttribute('data-size'));
|
2017-05-17 06:24:25 +02:00
|
|
|
|
|
|
|
DMSFilesystemTestHelper::delete('assets/_unit-test-123');
|
2015-12-17 19:48:37 +01:00
|
|
|
}
|
2013-10-09 11:54:08 +02:00
|
|
|
}
|