/** * Test directory scanning for images to VSMGImage object creation */ static function testGetImagePaths() { $all_images = VSMGFileHelper::getImagePaths("../test/images", FALSE); assert(count($all_images) == 15); $all_images = VSMGFileHelper::getImagePaths("../test/images", TRUE); assert(count($all_images) == 17); }
static function testGenerateGalleryHTML() { $all_images = VSMGFileHelper::getImagePaths("../test/images", TRUE); $gallery = new VSMGGallery($all_images, TestVSMGImageHelper::$username, TestVSMGImageHelper::$password, TestVSMGImageHelper::$database); $gallery_html = $gallery->getThumbnailsHTML(); return "<html>\n {$gallery_html}</html>\n"; }
/** * A function to (optionally) recursive through a root directory, * retrieving image paths * * @param $folder * The root folder to start the scanning * @param $enable_chidren * Boolean value to enable scanning through child folders, default to false * * @return * An array of image paths * * @todo * Use more robust php recursive directory search options */ static function getImagePaths($folder, $enable_chidren = FALSE) { $image_array = array(); $iterator = new RecursiveDirectoryIterator($folder); $image_array = array_merge($image_array, VSMGFileHelper::getDirectoryImages($folder)); if ($enable_chidren) { foreach ($iterator as $file) { if (is_dir($file) && !$iterator->isDot()) { // echo "VSMGFileHelper::getImagePaths DIR: $file\n"; $image_array = array_merge($image_array, VSMGFileHelper::getDirectoryImages($file)); } } } return $image_array; }
<?php require_once 'TestVSMGFileHelper.php'; require_once 'TestVSMGImageHelper.php'; TestVSMGFileHelper::run(); TestVSMGImageHelper::run(); $username = '******'; $password = '******'; $database = 'modx'; // Setup a quick html file $all_images = VSMGFileHelper::getImagePaths("../test/images", TRUE); $gallery = new VSMGGallery($all_images, $username, $password, $database); $gallery_html = $gallery->getThumbnailsHTML(); $ind_file = "index-test.html"; $fh = fopen($ind_file, 'w') or die("Erro opening file"); $html = "<html>\n" . ' <link rel="stylesheet" href="../css/vsmg.css" type="text/css"/>' . $gallery_html . "</html>\n"; fwrite($fh, $html); fclose($fh);