2012-07-25 08:56:43 +02:00
|
|
|
<?php
|
|
|
|
class DMSTagTest extends SapphireTest {
|
|
|
|
|
2012-07-27 03:11:28 +02:00
|
|
|
function tearDownOnce() {
|
2012-11-01 12:34:29 +01:00
|
|
|
self::$is_running_test = true;
|
|
|
|
|
2012-07-27 03:11:28 +02:00
|
|
|
$d = DataObject::get("DMSDocument");
|
|
|
|
foreach($d as $d1) {
|
|
|
|
$d1->delete();
|
|
|
|
}
|
|
|
|
$t = DataObject::get("DMSTag");
|
|
|
|
foreach($t as $t1) {
|
|
|
|
$t1->delete();
|
|
|
|
}
|
2012-11-01 12:34:29 +01:00
|
|
|
|
|
|
|
self::$is_running_test = $this->originalIsRunningTest;
|
2012-07-27 03:11:28 +02:00
|
|
|
}
|
|
|
|
|
2012-07-25 08:56:43 +02:00
|
|
|
function testAddingTags() {
|
2012-07-27 04:21:24 +02:00
|
|
|
$doc = new DMSDocument();
|
2012-07-25 08:56:43 +02:00
|
|
|
$doc->Filename = "test file";
|
|
|
|
$doc->Folder = "0";
|
|
|
|
$doc->write();
|
|
|
|
|
|
|
|
$doc->addTag("fruit","banana");
|
|
|
|
$doc->addTag("fruit","orange");
|
|
|
|
$doc->addTag("fruit","apple");
|
|
|
|
$doc->addTag("company","apple");
|
|
|
|
$doc->addTag("company","SilverStripe");
|
|
|
|
|
2012-07-30 02:33:01 +02:00
|
|
|
$fruits = $doc->getTagsList("fruit");
|
2012-07-25 08:56:43 +02:00
|
|
|
$this->assertNotNull($fruits,"Something returned for fruit tags");
|
|
|
|
$this->assertEquals(count($fruits),3,"3 fruit tags returned");
|
2012-07-25 08:59:01 +02:00
|
|
|
$this->assertTrue(in_array("banana",$fruits),"correct fruit tags returned");
|
2012-07-27 01:26:30 +02:00
|
|
|
|
|
|
|
//sneakily create another document and link one of the tags to that, too
|
2012-07-27 04:21:24 +02:00
|
|
|
$doc2 = new DMSDocument();
|
2012-07-27 01:26:30 +02:00
|
|
|
$doc2->Filename = "sneaky file";
|
|
|
|
$doc2->Folder = "0";
|
|
|
|
$doc2->write();
|
|
|
|
$doc2->addTag("fruit","banana");
|
|
|
|
|
2012-07-30 02:33:01 +02:00
|
|
|
$fruits = $doc2->getTagsList("fruit");
|
2012-07-27 01:26:30 +02:00
|
|
|
$this->assertNotNull($fruits,"Something returned for fruit tags");
|
|
|
|
$this->assertEquals(count($fruits),1,"Only 1 fruit tags returned");
|
|
|
|
|
|
|
|
//tidy up by deleting all tags from doc 1 (But the banana fruit tag should remain)
|
|
|
|
$doc->removeAllTags();
|
|
|
|
|
|
|
|
//banana fruit remains
|
2012-07-30 02:33:01 +02:00
|
|
|
$fruits = $doc2->getTagsList("fruit");
|
2012-07-27 01:26:30 +02:00
|
|
|
$this->assertNotNull($fruits,"Something returned for fruit tags");
|
|
|
|
$this->assertEquals(count($fruits),1,"Only 1 fruit tags returned");
|
|
|
|
|
|
|
|
$tags = DataObject::get("DMSTag");
|
|
|
|
$this->assertEquals($tags->Count(),1,"A single DMS tag objects remain after deletion of all tags on doc1");
|
|
|
|
|
|
|
|
//delete all tags off doc2 to complete the tidy up
|
|
|
|
$doc2->removeAllTags();
|
|
|
|
|
|
|
|
$tags = DataObject::get("DMSTag");
|
|
|
|
$this->assertEquals($tags->Count(),0,"No DMS tag objects remain after deletion");
|
2012-07-25 08:56:43 +02:00
|
|
|
}
|
2012-07-27 01:26:30 +02:00
|
|
|
|
|
|
|
function testRemovingTags() {
|
2012-07-27 04:21:24 +02:00
|
|
|
$doc = new DMSDocument();
|
2012-07-27 01:26:30 +02:00
|
|
|
$doc->Filename = "test file";
|
|
|
|
$doc->Folder = "0";
|
|
|
|
$doc->write();
|
|
|
|
|
|
|
|
$doc->addTag("fruit","banana");
|
|
|
|
$doc->addTag("fruit","orange");
|
|
|
|
$doc->addTag("fruit","apple");
|
|
|
|
$doc->addTag("company","apple");
|
|
|
|
$doc->addTag("company","SilverStripe");
|
|
|
|
|
2012-07-30 02:33:01 +02:00
|
|
|
$companies = $doc->getTagsList("company");
|
2012-07-27 01:26:30 +02:00
|
|
|
$this->assertNotNull($companies,"Companies returned before deletion");
|
|
|
|
$this->assertEquals(count($companies),2,"Two companies returned before deletion");
|
|
|
|
|
|
|
|
//delete an entire category
|
|
|
|
$doc->removeTag("company");
|
|
|
|
|
2012-07-30 02:33:01 +02:00
|
|
|
$companies = $doc->getTagsList("company");
|
2012-07-27 01:26:30 +02:00
|
|
|
$this->assertNull($companies,"All companies deleted");
|
|
|
|
|
2012-07-30 02:33:01 +02:00
|
|
|
$fruit = $doc->getTagsList("fruit");
|
2012-07-27 01:26:30 +02:00
|
|
|
$this->assertEquals(count($fruit),3,"Three fruits returned before deletion");
|
|
|
|
|
|
|
|
//delete a single tag
|
|
|
|
$doc->removeTag("fruit","apple");
|
|
|
|
|
2012-07-30 02:33:01 +02:00
|
|
|
$fruit = $doc->getTagsList("fruit");
|
2012-07-27 01:26:30 +02:00
|
|
|
$this->assertEquals(count($fruit),2,"Two fruits returned after deleting one");
|
|
|
|
|
|
|
|
//delete a single tag
|
|
|
|
$doc->removeTag("fruit","orange");
|
|
|
|
|
2012-07-30 02:33:01 +02:00
|
|
|
$fruit = $doc->getTagsList("fruit");
|
2012-07-27 01:26:30 +02:00
|
|
|
$this->assertEquals(count($fruit),1,"One fruits returned after deleting two");
|
|
|
|
|
|
|
|
//nothing happens when deleting tag that doesn't exist
|
|
|
|
$doc->removeTag("fruit","jellybean");
|
|
|
|
|
2012-07-30 02:33:01 +02:00
|
|
|
$fruit = $doc->getTagsList("fruit");
|
2012-07-27 01:26:30 +02:00
|
|
|
$this->assertEquals(count($fruit),1,"One fruits returned after attempting to delete non-existent fruit");
|
|
|
|
|
|
|
|
//delete the last fruit
|
|
|
|
$doc->removeTag("fruit","banana");
|
|
|
|
|
2012-07-30 02:33:01 +02:00
|
|
|
$fruit = $doc->getTagsList("fruit");
|
2012-07-27 01:26:30 +02:00
|
|
|
$this->assertNull($fruit,"All fruits deleted");
|
|
|
|
|
|
|
|
$tags = DataObject::get("DMSTag");
|
|
|
|
$this->assertEquals($tags->Count(),0,"No DMS tag objects remain after deletion");
|
|
|
|
}
|
|
|
|
|
2012-07-25 08:56:43 +02:00
|
|
|
}
|