Update TalkExtension and tests
This commit is contained in:
parent
6b022a02d0
commit
7f48563806
|
@ -85,13 +85,7 @@ class TalksExtension extends AbstractExtension
|
|||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'talks';
|
||||
}
|
||||
|
||||
private function getLastDate($talk): string
|
||||
{
|
||||
return $this->getEvents(collect([$talk]))
|
||||
->pluck('date')->max();
|
||||
return 'app.talks';
|
||||
}
|
||||
|
||||
public function getEvents(Collection $talks): Collection
|
||||
|
@ -100,4 +94,24 @@ class TalksExtension extends AbstractExtension
|
|||
return $talk['events'];
|
||||
});
|
||||
}
|
||||
|
||||
public function filterUpcoming(Collection $talks)
|
||||
{
|
||||
return $talks->filter(function ($talk) {
|
||||
return $this->getLastDate($talk) >= $this->today;
|
||||
})->values();
|
||||
}
|
||||
|
||||
public function filterPast(Collection $talks)
|
||||
{
|
||||
return $talks->filter(function ($talk) {
|
||||
return $this->getLastDate($talk) < $this->today;
|
||||
})->values();
|
||||
}
|
||||
|
||||
private function getLastDate($talk): string
|
||||
{
|
||||
return $this->getEvents(collect([$talk]))
|
||||
->pluck('date')->max();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,10 +91,11 @@ class TalksExtensionTest extends TestCase
|
|||
],
|
||||
];
|
||||
|
||||
$result = $this->extension->getPast([$pastTalk, $futureTalk]);
|
||||
$talks = $this->extension->getAll([$pastTalk, $futureTalk]);
|
||||
$filtered = $this->extension->filterPast($talks);
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertSame($pastTalk, $result->first());
|
||||
$this->assertCount(1, $filtered);
|
||||
$this->assertSame($pastTalk, $filtered->first());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
@ -121,10 +122,11 @@ class TalksExtensionTest extends TestCase
|
|||
],
|
||||
];
|
||||
|
||||
$result = $this->extension->getUpcoming([$pastTalk, $todayTalk, $futureTalk]);
|
||||
$talks = $this->extension->getAll([$pastTalk, $todayTalk, $futureTalk]);
|
||||
$filtered = $this->extension->filterUpcoming($talks);
|
||||
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertSame([$todayTalk, $futureTalk], $result->toArray());
|
||||
$this->assertCount(2, $filtered);
|
||||
$this->assertSame([$todayTalk, $futureTalk], $filtered->toArray());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
@ -138,8 +140,10 @@ class TalksExtensionTest extends TestCase
|
|||
],
|
||||
];
|
||||
|
||||
$this->assertCount(1, $this->extension->getUpcoming([$talk]));
|
||||
$this->assertEmpty($this->extension->getPast([$talk]));
|
||||
$talks = $this->extension->getAll([$talk]);
|
||||
|
||||
$this->assertCount(1, $this->extension->filterUpcoming($talks));
|
||||
$this->assertEmpty($this->extension->filterPast($talks));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
|
Loading…
Reference in a new issue