Skip to content
This repository has been archived by the owner on Jan 10, 2021. It is now read-only.

Commit

Permalink
TESTS, implementing unit testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Glasl committed Mar 7, 2017
1 parent 91f518f commit 483b2f9
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
4 changes: 2 additions & 2 deletions code/extensions/TaggingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ public function onBeforeWrite() {
foreach($types as $relationship => $type) {
foreach($this->owner->$relationship() as $tag) {

// Update both the fusion tags and tagging.
// Update both the fusion tags and tagging (using the relationship causes caching issues).

$fusion = $tag->FusionTag();
$fusion = FusionTag::get()->byID($tag->FusionTagID);
$this->owner->FusionTags()->add($fusion);
$tagging[] = $fusion->Title;
}
Expand Down
73 changes: 73 additions & 0 deletions tests/FusionUnitTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,79 @@ public function testTags() {
$fusion = FusionTag::get()->byID($ID);
$this->assertTrue(is_object($fusion));
$this->assertEquals($fusion->TagTypes, null);

// The database needs to be emptied to prevent further testing conflict.

self::empty_temp_db();
}

/**
* The test to ensure the page tagging is functioning correctly.
*/

public function testTagging() {

// Instantiate a page to use.

$page = SiteTree::create();

// Determine whether consolidated tags are found in the existing relationships.

$types = array();
$existing = singleton('FusionService')->getFusionTagTypes();
foreach($existing as $type => $field) {
$types[$type] = $type;
}
$types = array_intersect($page->many_many(), $types);
if(empty($types)) {

// Instantiate a tag to use, adding it against the page.

$tag = FusionTag::create();
$field = 'Title';
$tag->$field = 'new';
$tag->write();
$page->FusionTags()->add($tag->ID);
}
else {

// There are consolidated tags found.

foreach($types as $relationship => $type) {

// Instantiate a tag to use, adding it against the page.

$tag = $type::create();
$field = $existing[$type];
$tag->$field = 'new';
$tag->write();
$page->$relationship()->add($tag->ID);

// The consolidated tags are automatically parsed, so this only needs to exist against one.

break;
}
}
$page->writeToStage('Stage');
$page->writeToStage('Live');

// Determine whether the page tagging reflects this.

$this->assertContains($tag->$field, $page->Tagging);

// Update the tag.

$tag->$field = 'changed';
$tag->write();

// Determine whether the page tagging reflects this.

$page = SiteTree::get()->byID($page->ID);
$this->assertContains($tag->$field, $page->Tagging);

// The database needs to be emptied to prevent further testing conflict.

self::empty_temp_db();
}

}
Expand Down

0 comments on commit 483b2f9

Please sign in to comment.