Skip to content

Commit

Permalink
Add orderable collection tests for next and previous tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseleite committed Jan 31, 2020
1 parent 43f7e60 commit e47b23d
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions tests/Tags/Collection/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,104 @@ function it_can_get_previous_and_next_entries_in_a_dated_asc_collection()
$this->assertEquals(['Carrot', 'Banana', 'Danish'], $this->runTagAndGetTitles('older')); // Alias of prev when date:desc
}

/** @test */
function it_can_get_previous_and_next_entries_in_an_orderable_asc_collection()
{
$this->foods->orderable(true)->save();

$this->makeEntry($this->foods, 'a')->set('title', 'Apple')->save();
$this->makeEntry($this->foods, 'b')->set('title', 'Banana')->save();
$this->makeEntry($this->foods, 'c')->set('title', 'Carrot')->save();
$this->makeEntry($this->foods, 'd')->set('title', 'Danish')->save();
$this->makeEntry($this->foods, 'e')->set('title', 'Egg')->save();
$this->makeEntry($this->foods, 'f')->set('title', 'Fig')->save();
$this->makeEntry($this->foods, 'g')->set('title', 'Grape')->save();
$this->makeEntry($this->foods, 'h')->set('title', 'Hummus')->save();
$this->makeEntry($this->foods, 'i')->set('title', 'Ice Cream')->save();

$this->foods->setEntryPositions([
$this->findEntryByTitle('Carrot')->id(),
$this->findEntryByTitle('Hummus')->id(),
$this->findEntryByTitle('Apple')->id(),
$this->findEntryByTitle('Ice Cream')->id(),
$this->findEntryByTitle('Banana')->id(),
$this->findEntryByTitle('Fig')->id(),
$this->findEntryByTitle('Grape')->id(),
$this->findEntryByTitle('Egg')->id(),
$this->findEntryByTitle('Danish')->id(),
])->save();

$currentId = $this->findEntryByTitle('Banana')->id();

$orderBy = 'order:asc';
// Hummus
// Apple
// Ice Cream
// Banana (current)
// Fig
// Grape
// Egg

$this->setTagParameters(['in' => 'foods', 'current' => $currentId, 'order_by' => $orderBy, 'limit' => 1]);

$this->assertEquals(['Fig'], $this->runTagAndGetTitles('next'));
$this->assertEquals(['Ice Cream'], $this->runTagAndGetTitles('previous'));

$this->setTagParameters(['in' => 'foods', 'current' => $currentId, 'order_by' => $orderBy, 'limit' => 3]);

$this->assertEquals(['Fig', 'Grape', 'Egg'], $this->runTagAndGetTitles('next'));
$this->assertEquals(['Hummus', 'Apple', 'Ice Cream'], $this->runTagAndGetTitles('previous'));
}

/** @test */
function it_can_get_previous_and_next_entries_in_an_orderable_desc_collection()
{
$this->foods->orderable(true)->save();

$this->makeEntry($this->foods, 'a')->set('title', 'Apple')->save();
$this->makeEntry($this->foods, 'b')->set('title', 'Banana')->save();
$this->makeEntry($this->foods, 'c')->set('title', 'Carrot')->save();
$this->makeEntry($this->foods, 'd')->set('title', 'Danish')->save();
$this->makeEntry($this->foods, 'e')->set('title', 'Egg')->save();
$this->makeEntry($this->foods, 'f')->set('title', 'Fig')->save();
$this->makeEntry($this->foods, 'g')->set('title', 'Grape')->save();
$this->makeEntry($this->foods, 'h')->set('title', 'Hummus')->save();
$this->makeEntry($this->foods, 'i')->set('title', 'Ice Cream')->save();

$this->foods->setEntryPositions([
$this->findEntryByTitle('Carrot')->id(),
$this->findEntryByTitle('Hummus')->id(),
$this->findEntryByTitle('Apple')->id(),
$this->findEntryByTitle('Ice Cream')->id(),
$this->findEntryByTitle('Banana')->id(),
$this->findEntryByTitle('Fig')->id(),
$this->findEntryByTitle('Grape')->id(),
$this->findEntryByTitle('Egg')->id(),
$this->findEntryByTitle('Danish')->id(),
])->save();

$currentId = $this->findEntryByTitle('Banana')->id();

$orderBy = 'order:desc';
// Egg
// Grape
// Fig
// Banana (current)
// Ice Cream
// Apple
// Hummus

$this->setTagParameters(['in' => 'foods', 'current' => $currentId, 'order_by' => $orderBy, 'limit' => 1]);

$this->assertEquals(['Ice Cream'], $this->runTagAndGetTitles('next'));
$this->assertEquals(['Fig'], $this->runTagAndGetTitles('previous'));

$this->setTagParameters(['in' => 'foods', 'current' => $currentId, 'order_by' => $orderBy, 'limit' => 3]);

$this->assertEquals(['Ice Cream', 'Apple', 'Hummus'], $this->runTagAndGetTitles('next'));
$this->assertEquals(['Egg', 'Grape', 'Fig'], $this->runTagAndGetTitles('previous'));
}

/** @test */
function it_adds_defaults_for_missing_items_based_on_blueprint()
{
Expand Down

0 comments on commit e47b23d

Please sign in to comment.