2012-07-16 18:21:48 +12:00
< ? php
class DMSTest extends SapphireTest {
2012-07-17 13:52:46 +12:00
static $testFile = 'dms/tests/DMS-test-lorum-file.pdf' ;
2012-07-16 18:21:48 +12:00
//store values to reset back to after this test runs
static $dmsFolderOld ;
static $dmsFolderSizeOld ;
function setUp () {
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)
$this -> delete ( BASE_PATH . DIRECTORY_SEPARATOR . DMS :: $dmsFolder );
}
function tearDown () {
//delete the test folder after the test runs
$this -> delete ( BASE_PATH . DIRECTORY_SEPARATOR . DMS :: $dmsFolder );
//set the old DMS folder back again
DMS :: $dmsFolder = self :: $dmsFolderOld ;
DMS :: $dmsFolderSize = self :: $dmsFolderSizeOld ;
}
public function delete ( $path ) {
2012-07-17 13:52:46 +12: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 18:21:48 +12:00
}
function testDMSStorage () {
2012-07-23 13:50:10 +12:00
$this -> markTestIncomplete ( 'DMS is WIP' );
2012-07-16 18:21:48 +12:00
$dms = DMS :: getDMSInstance ();
$file = BASE_PATH . DIRECTORY_SEPARATOR . self :: $testFile ;
$document = $dms -> storeDocument ( $file );
$this -> assertNotNull ( $document , " Document object created " );
2012-07-17 13:52:46 +12:00
$this -> assertTrue ( file_exists ( DMS :: $dmsPath . DIRECTORY_SEPARATOR . $document -> Folder . DIRECTORY_SEPARATOR . $document -> Filename ), " Document file copied into DMS folder " );
2012-07-16 18:21:48 +12:00
//$title = $document->getTag('title');
}
function testDMSFolderSpanning () {
2012-07-23 13:50:10 +12:00
$this -> markTestIncomplete ( 'DMS is WIP' );
2012-07-16 18:21:48 +12:00
DMS :: $dmsFolderSize = 5 ;
$dms = DMS :: getDMSInstance ();
$file = BASE_PATH . DIRECTORY_SEPARATOR . self :: $testFile ;
2012-07-17 13:52:46 +12:00
$documents = array ();
2012-07-16 18:21:48 +12:00
for ( $i = 0 ; $i <= 16 ; $i ++ ) {
$document = $dms -> storeDocument ( $file );
$this -> assertNotNull ( $document , " Document object created on run number: $i " );
2012-07-17 13:52:46 +12: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 18:21:48 +12:00
}
//test we created 4 folder to contain the 17 files
2012-07-17 13:52:46 +12:00
foreach ( $folders as $f ) {
$this -> assertTrue ( is_dir ( DMS :: $dmsPath . DIRECTORY_SEPARATOR . $f ), " Document folder ' $f ' exists " );
}
2012-07-16 18:21:48 +12:00
}
}