From 6229e98e923b357834fbd3c155deb96e3dd1c300 Mon Sep 17 00:00:00 2001 From: Nic Date: Thu, 15 Jun 2023 09:11:23 -0500 Subject: [PATCH] BUGFIX properly return preset categories on locator (#241) * BUGFIX properly return preset categories on locator * UPDATE tests to reflect corrected result --- src/Page/Locator.php | 10 ++++++---- tests/Page/LocatorTest.php | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Page/Locator.php b/src/Page/Locator.php index 1fc2546..bc2caba 100644 --- a/src/Page/Locator.php +++ b/src/Page/Locator.php @@ -189,7 +189,9 @@ public static function locator_categories_by_locator($id = 0): ArrayList|ManyMan /** @var Locator $locator */ if ($locator = static::get()->byID($id)) { - return $locator->getUsedCategories(); + if ($locator->Categories()->exists()) { + return $locator->Categories(); + } } return ArrayList::create(); @@ -249,12 +251,12 @@ public function getShowRadius() /** * @return mixed + * + * @deprecated call the Categories() relation on the locator instead */ public function getUsedCategories() { - return $this->Categories()->filter([ - 'LocationSet.ID:GreaterThan' => 0, - ]); + return $this->Categories(); } /** diff --git a/tests/Page/LocatorTest.php b/tests/Page/LocatorTest.php index 16ec6a6..a4641d9 100644 --- a/tests/Page/LocatorTest.php +++ b/tests/Page/LocatorTest.php @@ -69,7 +69,7 @@ public function testGetAllCategories() public function testGetPageCategories() { $locator = $this->objFromFixture(Locator::class, 'locator1'); - $this->assertEquals($locator->getPageCategories()->count(), 1); + $this->assertEquals($locator->getPageCategories()->count(), 2); } /** @@ -88,7 +88,7 @@ public function testLocatorCategoriesByLocator() { $locator = $this->objFromFixture(Locator::class, 'locator1'); - $this->assertEquals(Locator::locator_categories_by_locator($locator->ID)->count(), 1); + $this->assertEquals(Locator::locator_categories_by_locator($locator->ID)->count(), 2); $newLocator = Locator::create(); $newLocator->Title = 'Locator 2'; @@ -153,7 +153,7 @@ public function testGetUsedCategories() $locator = $this->objFromFixture(Locator::class, 'locator1'); $categories = $locator->getUsedCategories()->toArray(); - $this->assertEquals(1, count($categories)); + $this->assertEquals(2, count($categories)); } /**