Example #1
0
<?php

require_once dirname(__FILE__) . '/helper/dmMediaUnitTestHelper.php';
$helper = new dmMediaUnitTestHelper();
$helper->boot();
$t = new lime_test(58);
$mediaTable = dmDb::table('DmMedia');
$folderTable = dmDb::table('DmMediaFolder');
$t->diag('Media tests');
$folderTable->checkRoot();
$root = $folderTable->getTree()->fetchRoot();
$t->diag('syncing root');
$root->sync();
$helper->checkTreeIntegrity($t);
$helper->testFolderCorrelations($t);
$t->isa_ok($root, 'DmMediaFolder', 'root is a media folder');
$t->is($root->fullPath, dmOs::normalize(sfConfig::get('sf_upload_dir')), 'root full path is ' . $root->fullPath);
$t->diag('add a folder in root');
$folder = new DmMediaFolder();
$folder->relPath = 'test_' . dmString::random(8);
$folder->getNode()->insertAsLastChildOf($root);
$helper->checkTreeIntegrity($t);
$t->ok($folder->exists(), 'folder ' . $folder->name . ' has been created');
$t->is($folder->getNode()->getParent(), $root, 'folder\'s parent is root');
$t->is($folder->fullPath, dmOs::join(sfConfig::get('sf_upload_dir'), $folder->name), 'folder\'s full path is ' . $folder->fullPath);
$t->ok(is_dir($folder->fullPath), 'folder exists in filesystem');
$t->diag('add a file in folder');
$fileName = dmString::random(8) . '_' . basename(__FILE__);
$filePath = dmOs::join($folder->fullPath, $fileName);
copy(__FILE__, $filePath);
$media = $mediaTable->create(array('file' => basename($filePath), 'author' => 'Thibault D.', 'legend' => 'dmMedia test cases', 'dm_media_folder_id' => $folder->id))->saveGet();
<?php

require_once dirname(__FILE__) . '/helper/dmMediaUnitTestHelper.php';
$helper = new dmMediaUnitTestHelper();
$helper->boot('admin');
$t = new lime_test(19);
$mediaTable = dmDb::table('DmMedia');
$folderTable = dmDb::table('DmMediaFolder');
$t->diag('Media tests');
$folderTable->checkRoot();
$root = $folderTable->getTree()->fetchRoot();
$t->diag('syncing root');
$root->sync();
$helper->checkTreeIntegrity($t);
$helper->testFolderCorrelations($t);
$parent = $folderTable->createQuery('f')->select('f.*, RANDOM() as rand')->orderBy('rand')->fetchOne();
require_once dmOs::join(sfConfig::get('dm_admin_dir'), 'modules/dmMediaLibrary/lib/DmAdminNewMediaFolderForm.php');
$form = new DmAdminNewMediaFolderForm();
$form->setDefault('parent_id', $parent->id);
$values = array('parent_id' => $parent->id);
$t->comment('Submit empty form');
$form->bind($values);
$t->is($form->isValid(), false, 'The form is not valid');
$t->comment('Submit bad dir name');
$values['name'] = '/';
$form->bind($values);
$t->is($form->isValid(), false, 'The form is not valid');
$t->comment('Submit good dir name');
$values['name'] = $name = dmString::random();
$form->bind($values);
$t->is($form->isValid(), true, 'The form is valid');
Example #3
0
<?php

require_once dirname(__FILE__) . '/helper/dmMediaUnitTestHelper.php';
$helper = new dmMediaUnitTestHelper();
$helper->boot();
$t = new lime_test(122);
$table = dmDb::table('DmMediaFolder');
$root = $table->checkRoot();
$t->diag('syncing root');
$root->sync();
$helper->checkTreeIntegrity($t);
$helper->testFolderCorrelations($t);
$grandParent = $table->createQuery('f')->select('f.*, RANDOM() as rand')->orderBy('rand')->fetchOne();
$parent = $table->create(array('rel_path' => $grandParent->relPath . '/parent'));
$parent->Node->insertAsFirstChildOf($grandParent);
$t->is($parent->exists(), true, 'Folder parent created');
$t->is((string) $parent->Node->getParent(), (string) $grandParent, 'Folder parent inserted in grand-parent');
$f1 = $table->create(array('rel_path' => $parent->relPath . '/f1'));
$f1->Node->insertAsFirstChildOf($parent);
$t->is($f1->exists(), true, 'Folder f1 created');
$t->is((string) $f1->Node->getParent(), (string) $parent, 'Folder f1 inserted in parent');
$f2 = $table->create(array('rel_path' => $parent->relPath . '/f2'));
$f2->Node->insertAsFirstChildOf($parent);
$t->is($f2->exists(), true, 'Folder f2 created');
$t->is((string) $f2->Node->getParent(), (string) $parent, 'Folder f2 inserted in parent');
$f3 = $table->create(array('rel_path' => $f2->relPath . '/f3'));
$f3->Node->insertAsFirstChildOf($f2);
$t->is($f3->exists(), true, 'Folder f3 created');
$t->is((string) $f3->Node->getParent(), (string) $f2, 'Folder f3 inserted in f2');
$helper->checkTreeIntegrity($t);
$helper->testFolderCorrelations($t);