Skip to content

Commit

Permalink
Add test for non-versioned owner objects
Browse files Browse the repository at this point in the history
  • Loading branch information
michalkleiner committed Jun 21, 2021
1 parent 1be37f0 commit 89a2ba0
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions tests/TaxonomyTermTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,87 @@ public function testOwnerObjectOwnsTaxonomyTerm()
}


/**
* Test a non-versioned model correctly adds and removes versioned tags in both draft and live stages
*/
public function testNonVersionedOwnerObject()
{
$origStage = Versioned::get_stage();

// Start in draft mode
Versioned::set_stage(Versioned::DRAFT);

// Remove extension
OwnerObject::remove_extension(Versioned::class);

$object6 = $this->objFromFixture(OwnerObject::class, 'object6');
$this->assertFalse($object6->hasExtension(Versioned::class));

$this->assertEquals(
0,
$object6->Tags()->count(),
'The object for testing non-versioned owner has 0 terms assigned'
);

$rootTerm1 = $this->objFromFixture(TaxonomyTerm::class, 'rootTerm1');
$rootTerm2 = $this->objFromFixture(TaxonomyTerm::class, 'rootTerm2');

$object6->Tags()->add($rootTerm1);
$object6->Tags()->add($rootTerm2);

$this->assertEquals(
2,
$object6->Tags()->count(),
'The object for testing non-versioned owner has 2 terms assigned in draft'
);

// Set live mode where non-versioned objects should always be visible
Versioned::set_stage(Versioned::LIVE);

$this->assertEquals(
2,
$object6->Tags()->count(),
'The object for testing non-versioned owner has 2 terms assigned in live'
);

// Remove one of the terms in live mode
$object6->Tags()->remove($rootTerm1);

// Set draft mode where the term deleted in live should be also gone
Versioned::set_stage(Versioned::DRAFT);

$this->assertEquals(
1,
$object6->Tags()->count(),
'The object for testing non-versioned owner has 1 term assigned in draft after first term removed in live'
);
$this->assertEquals(
$rootTerm2->ID,
$object6->Tags()->first()->ID,
'The object for testing non-versioned owner has only term 2 assigned in draft after term 1 removed in live'
);

// Set live mode where non-versioned objects should always be visible
Versioned::set_stage(Versioned::LIVE);

$this->assertEquals(
1,
$object6->Tags()->count(),
'The object for testing non-versioned owner still has 1 term assigned in live'
);
$this->assertEquals(
$rootTerm2->ID,
$object6->Tags()->first()->ID,
'The object for testing non-versioned owner still has only term 2 assigned in live'
);

// Restore the orig archived stage
if ($origStage) {
Versioned::set_stage($origStage);
}
}


/**
* Test when a RequiredTypes loop exists, e.g
* 1. TypeZ requires TypeY,
Expand Down

0 comments on commit 89a2ba0

Please sign in to comment.