diff --git a/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php b/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php new file mode 100644 index 0000000..00dbdf5 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php @@ -0,0 +1,173 @@ +page = $this->prophesize(DocumentElement::class); + $this->session = $this->prophesize(Session::class); + $this->session->getPage()->willReturn($this->page->reveal()); + $this->webAssert = $this->prophesize(WebAssert::class); + } + + /** + * @covers ::assertUniqueText + */ + public function testAssertUniqueText() { + $this->page->getText()->willReturn('foo bar bar'); + $this->assertUniqueText('foo'); + } + + /** + * @covers ::assertUniqueText + */ + public function testAssertUniqueTextFail() { + $this->page->getText()->willReturn('foo bar bar'); + $this->setExpectedException(PHPUnit_Framework_ExpectationFailedException::class); + $this->assertUniqueText('bar'); + } + + /** + * @covers ::assertUniqueText + */ + public function testAssertUniqueTextUnknown() { + $this->page->getText()->willReturn('foo bar bar'); + $this->setExpectedException(PHPUnit_Framework_ExpectationFailedException::class); + $this->assertUniqueText('alice'); + } + + /** + * @covers ::assertUniqueText + */ + public function testAssertUniqueTextMarkup() { + $this->page->getText()->willReturn('foo bar bar'); + $markupObject = $this->prophesize(MarkupInterface::class); + $markupObject->__toString()->willReturn('foo'); + $this->assertUniqueText($markupObject->reveal()); + } + + /** + * @covers ::assertNoUniqueText + */ + public function testAssertNoUniqueText() { + $this->page->getText()->willReturn('foo bar bar'); + $this->assertNoUniqueText('bar'); + } + + /** + * @covers ::assertNoUniqueText + */ + public function testAssertNoUniqueTextFail() { + $this->page->getText()->willReturn('foo bar bar'); + $this->setExpectedException(PHPUnit_Framework_ExpectationFailedException::class); + $this->assertNoUniqueText('foo'); + } + + /** + * @covers ::assertNoUniqueText + */ + public function testAssertNoUniqueTextUnknown() { + $this->page->getText()->willReturn('foo bar bar'); + $this->setExpectedException(PHPUnit_Framework_ExpectationFailedException::class); + $this->assertNoUniqueText('alice'); + } + + /** + * @covers ::assertNoUniqueText + */ + public function testAssertNoUniqueTextMarkup() { + $this->page->getText()->willReturn('foo bar bar'); + $markupObject = $this->prophesize(MarkupInterface::class); + $markupObject->__toString()->willReturn('bar'); + $this->assertNoUniqueText($markupObject->reveal()); + } + + /** + * @covers ::assertOptionSelected + */ + public function testAssertOptionSelected() { + $option_field = $this->prophesize(NodeElement::class); + $option_field->hasAttribute('selected')->willReturn(TRUE); + + $this->webAssert + ->optionExists('myselect', 'two') + ->willReturn($option_field->reveal()); + + $this->assertOptionSelected('myselect', 'two'); + } + + /** + * @covers ::assertOptionSelected + */ + public function testAssertOptionSelectedFail() { + $option_field = $this->prophesize(NodeElement::class); + $option_field->hasAttribute('selected')->willReturn(FALSE); + + $this->webAssert + ->optionExists('myselect', 'two') + ->willReturn($option_field->reveal()); + + $this->setExpectedException(PHPUnit_Framework_ExpectationFailedException::class); + $this->assertOptionSelected('myselect', 'two'); + } + + /** + * Returns a mocked behat session object. + * + * @return \Behat\Mink\Session + * The mocked session. + */ + protected function getSession() { + return $this->session->reveal(); + } + + /** + * {@inheritdoc} + */ + public function assertSession($name = NULL) { + return $this->webAssert->reveal(); + } + +}