Skip to content

Commit

Permalink
BUGFIX properly return preset categories on locator (#241)
Browse files Browse the repository at this point in the history
* BUGFIX properly return preset categories on locator

* UPDATE tests to reflect corrected result
  • Loading branch information
muskie9 authored Jun 15, 2023
1 parent f6a9735 commit 6229e98
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/Page/Locator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Page/LocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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';
Expand Down Expand Up @@ -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));
}

/**
Expand Down

0 comments on commit 6229e98

Please sign in to comment.