StoredFileTests.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. require_once(dirname(__FILE__).'/../StoredFile.php');
  3. class StoredFileTest extends PHPUnit_TestCase {
  4. function __construct($name) {
  5. parent::__construct($name);
  6. }
  7. function setup() {
  8. }
  9. function testGetAudioMetadata() {
  10. $filePath = dirname(__FILE__)."/ex1.mp3";
  11. $metadata = Metadata::LoadFromFile($filePath);
  12. if (($metadata["dc:description"] != "Tmu sem tam videla ...")
  13. || ($metadata["audio"]["dataformat"] != "mp3")
  14. || ($metadata["dc:type"] != "Speech")) {
  15. $str = " [dc:description] = " . $metadata["dc:description"] ."\n"
  16. . " [audio][dataformat] = " . $metadata["audio"]["dataformat"]."\n"
  17. . " [dc:type] = ".$metadata["dc:type"]."\n";
  18. $this->fail("Metadata has unexpected values:\n".$str);
  19. }
  20. //var_dump($metadata);
  21. //$this->assertTrue(FALSE);
  22. }
  23. function testDeleteAndPutFile() {
  24. $STORAGE_SERVER_PATH = dirname(__FILE__)."/../../";
  25. $filePath = dirname(__FILE__)."/ex1.mp3";
  26. // Delete any old data from previous tests
  27. $md5 = md5_file($filePath);
  28. $duplicate = Application_Model_StoredFile::RecallByMd5($md5);
  29. if ($duplicate) {
  30. $duplicate->delete();
  31. }
  32. // Test inserting a file by linking
  33. $values = array("filepath" => $filePath,
  34. "dc:description" => "Unit test ".time());
  35. $storedFile = Application_Model_StoredFile::Insert($values, false);
  36. //var_dump($storedFile);
  37. $id = $storedFile->getId();
  38. if (!is_numeric($id)) {
  39. $this->fail("StoredFile not created correctly. id = ".$id);
  40. return;
  41. }
  42. // Test loading metadata
  43. $f = new Application_Model_StoredFile();
  44. $f->__setGunid($storedFile->getGunid());
  45. $f->loadMetadata();
  46. if (!is_array($md = $f->getMetadata())) {
  47. $this->fail("Unable to load metadata.");
  48. return;
  49. }
  50. //var_dump($md);
  51. // Check if the length field has been set.
  52. $f2 = Application_Model_StoredFile::RecallByGunid($storedFile->getGunid());
  53. $m2 = $f2->getMetadata();
  54. if (!isset($m2["length"]) || $m2["length"] == "00:00:00.000000") {
  55. $this->fail("Length not reporting correctly in metadata.");
  56. return;
  57. }
  58. }
  59. }