setParent($parent), $grandChild = (new SocialIssue())->setParent($child), $grandGrandChild = (new SocialIssue())->setParent($grandChild), $unrelated = new SocialIssue(), ]); $ancestors = SocialIssue::findAncestorSocialIssues($socialIssues); $this->assertCount(3, $ancestors); $this->assertContains($parent, $ancestors); $this->assertContains($child, $ancestors); $this->assertContains($grandChild, $ancestors); } public function testGetAncestors() { $parent = new SocialIssue(); $child = (new SocialIssue())->setParent($parent); $grandChild = (new SocialIssue())->setParent($child); $grandGrandChild = (new SocialIssue())->setParent($grandChild); $unrelated = new SocialIssue(); $this->assertContains($parent, $grandGrandChild->getAncestors(true)); $this->assertContains($child, $grandGrandChild->getAncestors(true)); $this->assertContains($grandChild, $grandGrandChild->getAncestors(true)); $this->assertContains($grandGrandChild, $grandGrandChild->getAncestors(true)); $this->assertNotContains($grandGrandChild, $grandGrandChild->getAncestors(false)); $this->assertCount(0, $unrelated->getAncestors(false)); } public function testIsDescendantOf() { $parent = new SocialIssue(); $child = (new SocialIssue())->setParent($parent); $grandChild = (new SocialIssue())->setParent($child); $grandGrandChild = (new SocialIssue())->setParent($grandChild); $unrelated = new SocialIssue(); $this->assertTrue($grandGrandChild->isDescendantOf($parent)); $this->assertTrue($grandGrandChild->isDescendantOf($grandChild)); $this->assertTrue($grandGrandChild->isDescendantOf($child)); $this->assertFalse($grandGrandChild->isDescendantOf($unrelated)); $this->assertTrue($grandChild->isDescendantOf($parent)); $this->assertTrue($grandChild->isDescendantOf($child)); $this->assertFalse($grandChild->isDescendantOf($unrelated)); $this->assertFalse($grandChild->isDescendantOf($grandChild)); $this->assertFalse($unrelated->isDescendantOf($parent)); $this->assertFalse($child->isDescendantOf($grandChild)); } }