Source of file DMSShortcodeHandlerTest.php
Size: 2,720 Bytes - Last Modified: 2021-12-23T10:29:25+00:00
/var/www/docs.ssmods.com/process/src/tests/DMSShortcodeHandlerTest.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 | <?php /** * Tests DMS shortcode linking functionality. * * @package dms * @subpackage tests */ class DMSShortcodeHandlerTest extends SapphireTest { protected static $fixture_file = 'dmstest.yml'; public function testShortcodeOperation() { Config::inst()->update('DMS', 'folder_name', 'assets/_unit-test-123'); $file = 'dms/tests/DMS-test-lorum-file.pdf'; $document = DMS::inst()->storeDocument($file); $result = ShortcodeParser::get('default')->parse(sprintf( '<p><a href="[dms_document_link id=\'%d\']">Document</a></p>', $document->ID )); $value = Injector::inst()->create('HTMLValue', $result); $link = $value->query('//a')->item(0); $this->assertStringEndsWith( '/dmsdocument/' . $document->ID . '-dms-test-lorum-file-pdf', $link->getAttribute('href') ); $this->assertEquals($document->getExtension(), $link->getAttribute('data-ext')); $this->assertEquals($document->getFileSizeFormatted(), $link->getAttribute('data-size')); DMSFilesystemTestHelper::delete('assets/_unit-test-123'); } /** * When the document is valid, the correct arguments are provided and some content is given, the content should * be parsed and added into an anchor to the document */ public function testShortcodeWithContentReturnsParsedContentInLink() { $document = $this->objFromFixture('DMSDocument', 'd1'); $arguments = array('id' => $document->ID); $result = DMSShortcodeHandler::handle($arguments, 'Some content', ShortcodeParser::get('default'), ''); $this->assertSame( '<a href="/dmsdocument/' . $document->ID . '-test-file-file-doesnt-exist-1">Some content</a>', $result ); } /** * An error page link should be returned if the arguments are not valid, empty or the document is not available etc. * * This only applies when an error page with a 404 error code exists. */ public function testReturnErrorPageWhenIdIsEmpty() { ErrorPage::create(array('URLSegment' => 'testing', 'ErrorCode' => '404'))->write(); $result = DMSShortcodeHandler::handle(array(), '', ShortcodeParser::get('default'), ''); $this->assertContains('testing', $result); } /** * When invalid or no data is available to return from the arguments and no error page exists to use for a link, * return a blank string */ public function testReturnEmptyStringWhenNoErrorPageExistsAndIdIsEmpty() { $this->assertSame('', DMSShortcodeHandler::handle(array(), '', ShortcodeParser::get('default'), '')); } } |