BUGFIX: fixing DMS unit tests

This commit is contained in:
Julian Seidenberg 2012-07-27 13:11:28 +12:00
parent e3c49aa775
commit cb2f61c260
4 changed files with 33 additions and 23 deletions

View File

@ -176,8 +176,6 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
$tags = $this->getTagsObjects($category, $value); $tags = $this->getTagsObjects($category, $value);
if ($tags->Count() > 0) { if ($tags->Count() > 0) {
$tagsToDelete = array();
foreach($tags as $t) { foreach($tags as $t) {
$documentList = $t->Documents(); $documentList = $t->Documents();
@ -187,13 +185,6 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
//delete the entire tag if it has no relations left //delete the entire tag if it has no relations left
if ($documentList->Count() == 0) $t->delete(); if ($documentList->Count() == 0) $t->delete();
} }
//TODO: remove this comment if unit tests work fine
//delete after the loop, so it doesn't conflict with the loop of the $tags list
// foreach($tagsToDelete as $tID) {
// $tag = DataObject::get_by_id("DMSTag",$tID);
// $tag->delete();
// }
} }
} }
@ -202,20 +193,12 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
* @return null * @return null
*/ */
function removeAllTags() { function removeAllTags() {
$tagsToDelete = array();
$allTags = $this->Tags(); $allTags = $this->Tags();
foreach($allTags as $tag) { foreach($allTags as $tag) {
$documentlist = $tag->Documents(); $documentlist = $tag->Documents();
$documentlist->remove($this); $documentlist->remove($this);
if ($tag->Documents()->Count() == 0) $tag->delete(); if ($tag->Documents()->Count() == 0) $tag->delete();
} }
//TODO: remove this comment if unit tests work fine
//delete after the loop, so it doesn't conflict with the loop of the $tags list
// foreach($tagsToDelete as $tID) {
// $tag = DataObject::get_by_id("DMSTag",$tID);
// $tag->delete();
// }
} }
/** /**

View File

@ -3,6 +3,17 @@ class DMSDocumentTest extends SapphireTest {
static $fixture_file = "dms/tests/dmstest.yml"; static $fixture_file = "dms/tests/dmstest.yml";
function tearDownOnce() {
$d = DataObject::get("DMSDocument");
foreach($d as $d1) {
$d1->delete();
}
$t = DataObject::get("DMSTag");
foreach($t as $t1) {
$t1->delete();
}
}
function testPageRelations() { function testPageRelations() {
$s1 = $this->objFromFixture('SiteTree','s1'); $s1 = $this->objFromFixture('SiteTree','s1');
$s2 = $this->objFromFixture('SiteTree','s2'); $s2 = $this->objFromFixture('SiteTree','s2');

View File

@ -3,6 +3,17 @@ class DMSTagTest extends SapphireTest {
//static $fixture_file = "dms/tests/dmstest.yml"; //static $fixture_file = "dms/tests/dmstest.yml";
function tearDownOnce() {
$d = DataObject::get("DMSDocument");
foreach($d as $d1) {
$d1->delete();
}
$t = DataObject::get("DMSTag");
foreach($t as $t1) {
$t1->delete();
}
}
function testAddingTags() { function testAddingTags() {
$doc = new DMSDocument(); $doc = new DMSDocument();
$doc->Filename = "test file"; $doc->Filename = "test file";

View File

@ -19,6 +19,15 @@ class DMSTest extends SapphireTest {
} }
function tearDown() { function tearDown() {
$d = DataObject::get("DMSDocument");
foreach($d as $d1) {
$d1->delete();
}
$t = DataObject::get("DMSTag");
foreach($t as $t1) {
$t1->delete();
}
//delete the test folder after the test runs //delete the test folder after the test runs
$this->delete(BASE_PATH . DIRECTORY_SEPARATOR . DMS::$dmsFolder); $this->delete(BASE_PATH . DIRECTORY_SEPARATOR . DMS::$dmsFolder);
@ -48,11 +57,9 @@ class DMSTest extends SapphireTest {
function testDMSStorage() { function testDMSStorage() {
$this->markTestIncomplete('DMS is WIP');
$dms = DMS::getDMSInstance(); $dms = DMS::getDMSInstance();
$file = BASE_PATH . DIRECTORY_SEPARATOR . self::$testFile; $file = self::$testFile;
$document = $dms->storeDocument($file); $document = $dms->storeDocument($file);
$this->assertNotNull($document, "Document object created"); $this->assertNotNull($document, "Document object created");
@ -62,12 +69,10 @@ class DMSTest extends SapphireTest {
} }
function testDMSFolderSpanning() { function testDMSFolderSpanning() {
$this->markTestIncomplete('DMS is WIP');
DMS::$dmsFolderSize = 5; DMS::$dmsFolderSize = 5;
$dms = DMS::getDMSInstance(); $dms = DMS::getDMSInstance();
$file = BASE_PATH . DIRECTORY_SEPARATOR . self::$testFile; $file = self::$testFile;
$documents = array(); $documents = array();
for($i = 0; $i <= 16; $i++) { for($i = 0; $i <= 16; $i++) {