Skip to content

Commit

Permalink
SelectElementTest: Add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Nov 30, 2022
1 parent 0650a6c commit 9fee083
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/FormElement/SelectElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,4 +585,35 @@ public function testOrderOfOptionsAndDisabledOptionsDoesNotMatter()

$this->assertHtml($html, $select);
}

public function testSetOptionsResetsOptions()
{
$select = new SelectElement('select');
$select->setOptions(['foo' => 'Foo', 'bar' => 'Bar']);

$this->assertInstanceOf(SelectOption::class, $select->getOption('foo'));
$this->assertInstanceOf(SelectOption::class, $select->getOption('bar'));

$select->setOptions(['car' => 'Car', 'train' => 'Train']);

$this->assertInstanceOf(SelectOption::class, $select->getOption('car'));
$this->assertInstanceOf(SelectOption::class, $select->getOption('train'));

$this->expectExceptionMessage('There is no such option "foo"');
$select->getOption('foo');
}

public function testGetOptionReturnsPreviouslySetOption()
{
$select = new SelectElement('select');
$select->setOptions(['' => 'Empty String', 'foo' => 'Foo', 'bar' => 'Bar']);

$this->assertNull($select->getOption('')->getValue());
$this->assertSame('foo', $select->getOption('foo')->getValue());

$select->setOptions(['' => 'Please Choose', 'car' => 'Car', 'train' => 'Train']);

$this->assertNull($select->getOption('')->getValue());
$this->assertSame('car', $select->getOption('car')->getValue());
}
}

0 comments on commit 9fee083

Please sign in to comment.