Fixed bug where the metadata was not loading correctly in StoredFile.

Added more descriptive titles to Playlist UnitTests.

Added a test to get that the media file clip length is set/get correctly.
This commit is contained in:
paul.baranowski 2010-11-15 17:02:18 -05:00
parent 228aca224e
commit 31fd85a29f
3 changed files with 46 additions and 26 deletions

View File

@ -433,7 +433,7 @@ class StoredFile {
$this->gunid = StoredFile::generateGunid(); $this->gunid = StoredFile::generateGunid();
} }
else { else {
$this->md = $this->loadMetadata(); $this->loadMetadata();
$this->exists = is_file($this->filepath) && is_readable($this->filepath); $this->exists = is_file($this->filepath) && is_readable($this->filepath);
} }
} }
@ -492,6 +492,7 @@ class StoredFile {
." WHERE gunid='$escapedValue'"; ." WHERE gunid='$escapedValue'";
//var_dump($sql); //var_dump($sql);
$this->md = $CC_DBC->getRow($sql); $this->md = $CC_DBC->getRow($sql);
//var_dump($this->md);
if (PEAR::isError($this->md)) { if (PEAR::isError($this->md)) {
$error = $this->md; $error = $this->md;
$this->md = null; $this->md = null;
@ -508,7 +509,9 @@ class StoredFile {
$compatibilityData[$xmlName] = $value; $compatibilityData[$xmlName] = $value;
} }
} }
//var_dump($compatibilityData);
$this->md = array_merge($this->md, $compatibilityData); $this->md = array_merge($this->md, $compatibilityData);
//var_dump($this->md);
//$_SESSION["debug"] = $this->md; //$_SESSION["debug"] = $this->md;
} }

View File

@ -42,22 +42,22 @@ class PlaylistTests extends PHPUnit_TestCase {
function setup() { function setup() {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$this->greenbox = new GreenBox(); $this->greenbox = new GreenBox();
// Add a file // Add a file
$values = array("filepath" => dirname(__FILE__)."/test10001.mp3"); $values = array("filepath" => dirname(__FILE__)."/test10001.mp3");
$this->storedFile = StoredFile::Insert($values, false); $this->storedFile = StoredFile::Insert($values, false);
// Add a file // Add a file
$values = array("filepath" => dirname(__FILE__)."/test10002.mp3"); $values = array("filepath" => dirname(__FILE__)."/test10002.mp3");
$this->storedFile2 = StoredFile::Insert($values, false); $this->storedFile2 = StoredFile::Insert($values, false);
} }
function testGBCreatePlaylist() { function testGBCreatePlaylist() {
$pl = new Playlist(); $pl = new Playlist();
$pl_id = $pl->create("create"); $pl_id = $pl->create("Playlist UnitTest: create ".date("g:i a"));
if (!is_int($pl_id)) { if (!is_int($pl_id)) {
$this->fail("problems creating playlist."); $this->fail("problems creating playlist.");
return; return;
@ -66,7 +66,7 @@ class PlaylistTests extends PHPUnit_TestCase {
function testGBLock() { function testGBLock() {
$pl = new Playlist(); $pl = new Playlist();
$pl_id = $pl->create("lock test"); $pl_id = $pl->create("Playlist Metadata: lock ".date("g:i a"));
$sessid = Alib::Login('root', 'q'); $sessid = Alib::Login('root', 'q');
@ -80,7 +80,7 @@ class PlaylistTests extends PHPUnit_TestCase {
function testGBUnLock() { function testGBUnLock() {
$pl = new Playlist(); $pl = new Playlist();
$pl_id = $pl->create("unlock test"); $pl_id = $pl->create("Playlist UnitTest: unlock ".date("g:i a"));
$sessid = Alib::Login('root', 'q'); $sessid = Alib::Login('root', 'q');
@ -92,12 +92,12 @@ class PlaylistTests extends PHPUnit_TestCase {
return; return;
} }
} }
function testGBSetPLMetaData() { function testGBSetPLMetaData() {
$pl = new Playlist(); $pl = new Playlist();
$pl_id = $pl->create("set meta data test"); $pl_id = $pl->create("Playlist UnitTest: Set Metadata ".date("g:i a"));
$res = $this->greenbox->setPLMetadataValue($pl_id, "dc:title", "A Title"); $res = $this->greenbox->setPLMetadataValue($pl_id, "dc:title", "Playlist Unit Test: Updated Title ".date("g:i a"));
if($res !== TRUE) { if($res !== TRUE) {
$this->fail("problems setting playlist metadata."); $this->fail("problems setting playlist metadata.");
@ -107,7 +107,7 @@ class PlaylistTests extends PHPUnit_TestCase {
function testGBGetPLMetaData() { function testGBGetPLMetaData() {
$pl = new Playlist(); $pl = new Playlist();
$name = "Testing"; $name = "Playlist UnitTest: GetMetadata ".date("g:i a");
$pl_id = $pl->create($name); $pl_id = $pl->create($name);
$res = $this->greenbox->getPLMetadataValue($pl_id, "dc:title"); $res = $this->greenbox->getPLMetadataValue($pl_id, "dc:title");
@ -121,12 +121,13 @@ class PlaylistTests extends PHPUnit_TestCase {
function testAddAudioClip() { function testAddAudioClip() {
$pl = new Playlist(); $pl = new Playlist();
$pl_id = $pl->create("Playlist Unit Test ". uniqid()); $pl_id = $pl->create("Playlist Unit Test ". date("g:i a"));
$res = $this->greenbox->addAudioClipToPlaylist($pl_id, $this->storedFile->getId()); $res = $this->greenbox->addAudioClipToPlaylist($pl_id, $this->storedFile->getId());
if($res !== TRUE) { if($res !== TRUE) {
$this->fail("problems adding audioclip to playlist."); $this->fail("problems adding audioclip to playlist.");
return; return;
} }
$res = $this->greenbox->addAudioClipToPlaylist($pl_id, $this->storedFile2->getId()); $res = $this->greenbox->addAudioClipToPlaylist($pl_id, $this->storedFile2->getId());
if($res !== TRUE) { if($res !== TRUE) {
$this->fail("problems adding audioclip 2 to playlist."); $this->fail("problems adding audioclip 2 to playlist.");
@ -136,7 +137,7 @@ class PlaylistTests extends PHPUnit_TestCase {
function testMoveAudioClip() { function testMoveAudioClip() {
$pl = new Playlist(); $pl = new Playlist();
$pl_id = $pl->create("Move"); $pl_id = $pl->create("Playlist Unit Test: Move ". date("g:i a"));
$this->greenbox->addAudioClipToPlaylist($pl_id, $this->storedFile->getId()); $this->greenbox->addAudioClipToPlaylist($pl_id, $this->storedFile->getId());
$this->greenbox->addAudioClipToPlaylist($pl_id, $this->storedFile2->getId()); $this->greenbox->addAudioClipToPlaylist($pl_id, $this->storedFile2->getId());
@ -151,7 +152,7 @@ class PlaylistTests extends PHPUnit_TestCase {
function testDeleteAudioClip() { function testDeleteAudioClip() {
$pl = new Playlist(); $pl = new Playlist();
$pl_id = $pl->create("Delete"); $pl_id = $pl->create("Playlist UnitTest: Delete ".date("g:i a"));
$this->greenbox->addAudioClipToPlaylist($pl_id, $this->storedFile->getId()); $this->greenbox->addAudioClipToPlaylist($pl_id, $this->storedFile->getId());
$res = $this->greenbox->delAudioClipFromPlaylist($pl_id, 0); $res = $this->greenbox->delAudioClipFromPlaylist($pl_id, 0);
@ -161,19 +162,19 @@ class PlaylistTests extends PHPUnit_TestCase {
return; return;
} }
} }
function testFadeInfo() { function testFadeInfo() {
$pl = new Playlist(); $pl = new Playlist();
$pl_id = $pl->create("Fade Info"); $pl_id = $pl->create("Playlist Unit Test: Fade Info " . date("g:i a"));
$this->greenbox->addAudioClipToPlaylist($pl_id, $this->storedFile2->getId()); $this->greenbox->addAudioClipToPlaylist($pl_id, $this->storedFile2->getId());
$res = $this->greenbox->changeFadeInfo($pl_id, 0, '00:00:01.14', null); $res = $this->greenbox->changeFadeInfo($pl_id, 0, '00:00:01.14', null);
if(!is_array($res) && count($res) !== 2) { if(!is_array($res) && count($res) !== 2) {
$this->fail("problems setting fade in playlist."); $this->fail("problems setting fade in playlist.");
return; return;
} }
} }
} }

View File

@ -1,7 +1,5 @@
<?php <?php
require_once(dirname(__FILE__).'/../StoredFile.php'); require_once(dirname(__FILE__).'/../StoredFile.php');
//require_once(dirname(__FILE__).'/../BasicStor.php');
//require_once(dirname(__FILE__).'/../GreenBox.php');
$dsn = $CC_CONFIG['dsn']; $dsn = $CC_CONFIG['dsn'];
$CC_DBC = DB::connect($dsn, TRUE); $CC_DBC = DB::connect($dsn, TRUE);
@ -43,14 +41,16 @@ class StoredFileTest extends PHPUnit_TestCase {
$STORAGE_SERVER_PATH = dirname(__FILE__)."/../../"; $STORAGE_SERVER_PATH = dirname(__FILE__)."/../../";
$filePath = dirname(__FILE__)."/ex1.mp3"; $filePath = dirname(__FILE__)."/ex1.mp3";
// Delete any old data from previous tests
$md5 = md5_file($filePath); $md5 = md5_file($filePath);
$duplicate = StoredFile::RecallByMd5($md5); $duplicate = StoredFile::RecallByMd5($md5);
if ($duplicate) { if ($duplicate) {
$duplicate->delete(); $duplicate->delete();
} }
$values = array("filepath" => $filePath); // Test inserting a file by linking
// Insert and link to file, dont copy it $values = array("filepath" => $filePath,
"dc:description" => "Unit test ".time());
$storedFile = StoredFile::Insert($values, false); $storedFile = StoredFile::Insert($values, false);
if (PEAR::isError($storedFile)) { if (PEAR::isError($storedFile)) {
$this->fail("Failed to create StoredFile: ".$storedFile->getMessage()); $this->fail("Failed to create StoredFile: ".$storedFile->getMessage());
@ -63,6 +63,7 @@ class StoredFileTest extends PHPUnit_TestCase {
return; return;
} }
// Test loading metadata
$f = new StoredFile(); $f = new StoredFile();
$f->__setGunid($storedFile->getGunid()); $f->__setGunid($storedFile->getGunid());
$f->loadMetadata(); $f->loadMetadata();
@ -71,7 +72,22 @@ class StoredFileTest extends PHPUnit_TestCase {
return; return;
} }
//var_dump($md); //var_dump($md);
// Check if the length field has been set.
$f2 = StoredFile::RecallByGunid($storedFile->getGunid());
$m2 = $f2->getMetadata();
if (!isset($m2["length"]) || $m2["length"] == "00:00:00.000000") {
$this->fail("Length not reporting correctly in metadata.");
return;
}
} }
function testFoo() {
// Add a file
$values = array("filepath" => dirname(__FILE__)."/test10001.mp3");
$this->storedFile = StoredFile::Insert($values, false);
}
} }
?> ?>