2012-07-16 08:21:48 +02:00
< ? php
2012-07-27 07:38:20 +02:00
class DMSTest extends FunctionalTest {
2012-07-16 08:21:48 +02:00
2012-07-17 03:52:46 +02:00
static $testFile = 'dms/tests/DMS-test-lorum-file.pdf' ;
2012-07-27 04:02:46 +02:00
static $testFile2 = 'dms/tests/DMS-test-document-2.pdf' ;
2012-07-16 08:21:48 +02:00
//store values to reset back to after this test runs
static $dmsFolderOld ;
static $dmsFolderSizeOld ;
function setUp () {
2012-07-27 07:38:20 +02:00
parent :: setUp ();
2012-07-16 08:21:48 +02:00
self :: $dmsFolderOld = DMS :: $dmsFolder ;
self :: $dmsFolderSizeOld = DMS :: $dmsFolderSize ;
//use a test DMS folder, so we don't overwrite the live one
DMS :: $dmsFolder = 'dms-assets-test-1234' ;
//clear out the test folder (in case a broken test doesn't delete it)
2012-07-30 02:57:27 +02:00
$this -> delete ( BASE_PATH . DIRECTORY_SEPARATOR . 'dms-assets-test-1234' );
2012-07-16 08:21:48 +02:00
}
function tearDown () {
2012-07-27 07:38:20 +02:00
parent :: tearDown ();
2012-07-27 03:11:28 +02:00
$d = DataObject :: get ( " DMSDocument " );
foreach ( $d as $d1 ) {
$d1 -> delete ();
}
$t = DataObject :: get ( " DMSTag " );
foreach ( $t as $t1 ) {
$t1 -> delete ();
}
2012-07-16 08:21:48 +02:00
//delete the test folder after the test runs
2012-07-30 02:57:27 +02:00
$this -> delete ( BASE_PATH . DIRECTORY_SEPARATOR . 'dms-assets-test-1234' );
2012-07-16 08:21:48 +02:00
//set the old DMS folder back again
DMS :: $dmsFolder = self :: $dmsFolderOld ;
DMS :: $dmsFolderSize = self :: $dmsFolderSizeOld ;
}
public function delete ( $path ) {
2012-07-17 03:52:46 +02:00
if ( file_exists ( $path ) || is_dir ( $path )) {
$it = new RecursiveIteratorIterator (
new RecursiveDirectoryIterator ( $path ),
RecursiveIteratorIterator :: CHILD_FIRST
);
foreach ( $it as $file ) {
if ( in_array ( $file -> getBasename (), array ( '.' , '..' ))) {
continue ;
} elseif ( $file -> isDir ()) {
rmdir ( $file -> getPathname ());
} elseif ( $file -> isFile () || $file -> isLink ()) {
unlink ( $file -> getPathname ());
}
}
rmdir ( $path );
}
2012-07-16 08:21:48 +02:00
}
function testDMSStorage () {
$dms = DMS :: getDMSInstance ();
2012-07-27 03:11:28 +02:00
$file = self :: $testFile ;
2012-07-16 08:21:48 +02:00
$document = $dms -> storeDocument ( $file );
$this -> assertNotNull ( $document , " Document object created " );
2012-07-27 07:38:20 +02:00
$this -> assertTrue ( file_exists ( DMS :: get_DMS_path () . DIRECTORY_SEPARATOR . $document -> Folder . DIRECTORY_SEPARATOR . $document -> Filename ), " Document file copied into DMS folder " );
2012-07-16 08:21:48 +02:00
//$title = $document->getTag('title');
}
function testDMSFolderSpanning () {
DMS :: $dmsFolderSize = 5 ;
$dms = DMS :: getDMSInstance ();
2012-07-27 03:11:28 +02:00
$file = self :: $testFile ;
2012-07-16 08:21:48 +02:00
2012-07-17 03:52:46 +02:00
$documents = array ();
2012-07-16 08:21:48 +02:00
for ( $i = 0 ; $i <= 16 ; $i ++ ) {
$document = $dms -> storeDocument ( $file );
$this -> assertNotNull ( $document , " Document object created on run number: $i " );
2012-07-17 03:52:46 +02:00
$this -> assertTrue ( file_exists ( $document -> getFullPath ()));
$documents [] = $document ;
}
//test document objects have their folders set
$folders = array ();
for ( $i = 0 ; $i <= 16 ; $i ++ ) {
$folderName = $documents [ $i ] -> Folder ;
$this -> assertTrue ( strpos ( $documents [ $i ] -> getFullPath (), DIRECTORY_SEPARATOR . $folderName . DIRECTORY_SEPARATOR ) !== false , " Correct folder name for the documents. Document path contains reference to folder name ' $folderName ' " );
$folders [] = $folderName ;
2012-07-16 08:21:48 +02:00
}
//test we created 4 folder to contain the 17 files
2012-07-17 03:52:46 +02:00
foreach ( $folders as $f ) {
2012-07-27 07:38:20 +02:00
$this -> assertTrue ( is_dir ( DMS :: get_DMS_path () . DIRECTORY_SEPARATOR . $f ), " Document folder ' $f ' exists " );
2012-07-17 03:52:46 +02:00
}
2012-07-16 08:21:48 +02:00
}
2012-07-27 04:02:46 +02:00
function testReplaceDocument () {
$dms = DMS :: getDMSInstance ();
//store the first document
$document = $dms -> storeDocument ( self :: $testFile );
$document -> Title = " My custom title " ;
$document -> Description = " My custom description " ;
$document -> write ();
//then overwrite with a second document
$document = $document -> replaceDocument ( self :: $testFile2 );
$this -> assertNotNull ( $document , " Document object created " );
2012-07-27 07:38:20 +02:00
$this -> assertTrue ( file_exists ( DMS :: get_DMS_path () . DIRECTORY_SEPARATOR . $document -> Folder . DIRECTORY_SEPARATOR . $document -> Filename ), " Document file copied into DMS folder " );
2012-07-27 04:21:24 +02:00
$this -> assertContains ( " DMS-test-document-2 " , $document -> Filename , " Original document filename is contain in the new filename " );
$this -> assertEquals ( " My custom title " , $document -> Title , " Custom title not modified " );
$this -> assertEquals ( " My custom description " , $document -> Description , " Custom description not modified " );
2012-07-27 04:02:46 +02:00
}
2012-07-27 07:38:20 +02:00
function testDownloadDocument () {
// $dms = DMS::getDMSInstance();
//
// //store the first document
// $document = $dms->storeDocument(self::$testFile);
2012-08-01 02:27:30 +02:00
// $link = $document->getDownloadLink();
2012-07-27 07:38:20 +02:00
//
// Debug::Show($link);
// $d=new DMSDocument_Controller();
// $response = $d->index(new SS_HTTPRequest('GET',$link,array("ID"=>$document->ID)));
// //$response = $this->get($link);
// Debug::show($response);
}
2012-07-16 08:21:48 +02:00
}