forked from contao/contao
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
114 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace Contao\CoreBundle\Tests\Event; | ||
|
||
use Contao\CoreBundle\Event\FilterPageTypeEvent; | ||
use Contao\DataContainer; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class FilterPageTypeEventTest extends TestCase | ||
{ | ||
public function testReturnsDataContainer(): void | ||
{ | ||
$dc = $this->createMock(DataContainer::class); | ||
|
||
$event = new FilterPageTypeEvent([], $dc); | ||
|
||
$this->assertSame($dc, $event->getDataContainer()); | ||
} | ||
|
||
public function testReturnsOptionsWithNumericKeys(): void | ||
{ | ||
$dc = $this->createMock(DataContainer::class); | ||
|
||
$event = new FilterPageTypeEvent(['foo' => 'bar'], $dc); | ||
|
||
$this->assertSame(['bar'], $event->getOptions()); | ||
} | ||
|
||
public function testCanAddOption(): void | ||
{ | ||
$dc = $this->createMock(DataContainer::class); | ||
|
||
$event = new FilterPageTypeEvent([], $dc); | ||
|
||
$this->assertSame([], $event->getOptions()); | ||
|
||
$event->addOption('foo'); | ||
|
||
$this->assertSame(['foo'], $event->getOptions()); | ||
} | ||
|
||
public function testDoesNotAddDuplicateOptions(): void | ||
{ | ||
$dc = $this->createMock(DataContainer::class); | ||
|
||
$event = new FilterPageTypeEvent(['foo'], $dc); | ||
|
||
$this->assertSame(['foo'], $event->getOptions()); | ||
|
||
$event->addOption('foo'); | ||
|
||
$this->assertSame(['foo'], $event->getOptions()); | ||
} | ||
|
||
public function testCanSetOptions(): void | ||
{ | ||
$dc = $this->createMock(DataContainer::class); | ||
|
||
$event = new FilterPageTypeEvent(['foo'], $dc); | ||
|
||
$this->assertSame(['foo'], $event->getOptions()); | ||
|
||
$event->setOptions(['foo' => 'bar']); | ||
|
||
$this->assertSame(['bar'], $event->getOptions()); | ||
} | ||
|
||
public function testCanRemoveOption(): void | ||
{ | ||
$dc = $this->createMock(DataContainer::class); | ||
|
||
$event = new FilterPageTypeEvent(['foo'], $dc); | ||
|
||
$this->assertSame(['foo'], $event->getOptions()); | ||
|
||
$event->removeOption('foo'); | ||
|
||
$this->assertSame([], $event->getOptions()); | ||
} | ||
|
||
public function testIgnoresMissingWhenRemovingOptions(): void | ||
{ | ||
$dc = $this->createMock(DataContainer::class); | ||
|
||
$event = new FilterPageTypeEvent(['foo'], $dc); | ||
|
||
$this->assertSame(['foo'], $event->getOptions()); | ||
|
||
$event->removeOption('bar'); | ||
|
||
$this->assertSame(['foo'], $event->getOptions()); | ||
} | ||
} |