Skip to content

Commit

Permalink
Simplify the findPages() method
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Sep 11, 2019
1 parent b889f36 commit 54e99d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion core-bundle/src/Routing/RouteProvider.php
Expand Up @@ -463,7 +463,7 @@ private function sortRoutes(array &$routes, array $languages = null): void
}

/**
* Finds the page models keeping the candidates order
* Finds the page models keeping the candidates order.
*
* @return Model[]
*/
Expand Down
29 changes: 12 additions & 17 deletions core-bundle/tests/Routing/RouteProviderTest.php
Expand Up @@ -192,21 +192,16 @@ public function testReturnsAnEmptyCollectionIfTheLanguageIsNotGiven(): void
*/
public function testFindsPagesByAliasCandidates(string $path, string $urlSuffix, bool $prependLocale, bool $folderUrl, array $aliases, array $ids = []): void
{
$conditions = [];

if (!empty($ids)) {
$conditions[] = 'tl_page.id IN ('.implode(',', $ids).')';
}

if (!empty($aliases)) {
$conditions[] = 'tl_page.alias IN ('.implode(',', $aliases).')';
}
$pageAdapter = $this->mockAdapter(['findByPk', 'findByAlias']);
$pageAdapter
->expects(empty($ids) ? $this->never() : $this->once())
->method('findByPk')
->willReturn(null)
;

$pageAdapter = $this->mockAdapter(['findBy']);
$pageAdapter
->expects($this->once())
->method('findBy')
->with([implode(' OR ', $conditions)], [])
->expects($this->exactly(\count($aliases)))
->method('findByAlias')
->willReturn(null)
;

Expand Down Expand Up @@ -317,10 +312,10 @@ public function getAliasCandidates(): \Generator
*/
public function testSortsTheRoutes(array $pages, array $languages): void
{
$pageAdapter = $this->mockAdapter(['findBy']);
$pageAdapter = $this->mockAdapter(['findByAlias']);
$pageAdapter
->expects($this->once())
->method('findBy')
->method('findByAlias')
->willReturn(new Collection(array_values($pages), 'tl_page'))
;

Expand Down Expand Up @@ -469,10 +464,10 @@ public function testAddsRoutesForAPage(string $alias, string $language, string $
{
$page = $this->createPage($language, $alias, true, $domain, $scheme);

$pageAdapter = $this->mockAdapter(['findBy']);
$pageAdapter = $this->mockAdapter(['findByAlias']);
$pageAdapter
->expects($this->once())
->method('findBy')
->method('findByAlias')
->willReturn(new Collection([$page], 'tl_page'))
;

Expand Down

0 comments on commit 54e99d0

Please sign in to comment.