class AssertLegacyTraitTest in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php \Drupal\Tests\Core\Assert\AssertLegacyTraitTest
@coversDefaultClass \Drupal\FunctionalTests\AssertLegacyTrait @group Assert @group legacy
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\Core\Assert\AssertLegacyTraitTest uses AssertLegacyTrait
Expanded class hierarchy of AssertLegacyTraitTest
File
- core/
tests/ Drupal/ Tests/ Core/ Assert/ AssertLegacyTraitTest.php, line 19
Namespace
Drupal\Tests\Core\AssertView source
class AssertLegacyTraitTest extends UnitTestCase {
use AssertLegacyTrait;
/**
* The mocked Mink session object used for testing.
*
* @var \Behat\Mink\Session|\Prophecy\Prophecy\ObjectProphecy
*/
protected $session;
/**
* The mocked page element used for testing.
*
* @var Behat\Mink\Element\DocumentElement|\Prophecy\Prophecy\ObjectProphecy
*/
protected $page;
/**
* The mocked web assert class.
*
* @var \Drupal\Tests\WebAssert|\Prophecy\Prophecy\ObjectProphecy
*/
protected $webAssert;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->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
->expectException(ExpectationFailedException::class);
$this
->assertUniqueText('bar');
}
/**
* @covers ::assertUniqueText
*/
public function testAssertUniqueTextUnknown() {
$this->page
->getText()
->willReturn('foo bar bar');
$this
->expectException(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
->expectException(ExpectationFailedException::class);
$this
->assertNoUniqueText('foo');
}
/**
* @covers ::assertNoUniqueText
*/
public function testAssertNoUniqueTextUnknown() {
$this->page
->getText()
->willReturn('foo bar bar');
$this
->expectException(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
->expectException(ExpectationFailedException::class);
$this
->assertOptionSelected('myselect', 'two');
}
/**
* @covers ::assertNoPattern
* @expectedDeprecation AssertLegacyTrait::assertNoPattern() is deprecated in drupal:8.4.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseNotMatches() instead. See https://www.drupal.org/node/3129738
*/
public function testAssertNoPattern() {
$this->webAssert
->responseNotMatches('/.*foo$/')
->shouldBeCalled();
$this
->assertNoPattern('/.*foo$/');
}
/**
* @covers ::assertNoCacheTag
* @expectedDeprecation AssertLegacyTrait::assertNoCacheTag() is deprecated in drupal:8.4.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseHeaderNotContains() instead. See https://www.drupal.org/node/3129738
*/
public function testAssertNoCacheTag() {
$this->webAssert
->responseHeaderNotContains('X-Drupal-Cache-Tags', 'some-cache-tag')
->shouldBeCalled();
$this
->assertNoCacheTag('some-cache-tag');
}
/**
* 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();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead. | |
AssertLegacyTrait:: |
protected | function | Asserts whether an expected cache tag was present in the last response. | |
AssertLegacyTrait:: |
protected | function | Asserts that the element with the given CSS selector is not present. | |
AssertLegacyTrait:: |
protected | function | Asserts that the element with the given CSS selector is present. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead. | |
AssertLegacyTrait:: |
protected | function | Passes if the raw text IS found escaped on the loaded page, fail otherwise. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field exists with the given name or ID. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field exists with the given ID and value. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field exists with the given name and value. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field exists in the current page by the given XPath. | |
AssertLegacyTrait:: |
protected | function | Asserts that a checkbox field in the current page is checked. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field exists in the current page with a given Xpath result. | |
AssertLegacyTrait:: |
protected | function | Checks that current response header equals value. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertSame() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead. | |
AssertLegacyTrait:: |
protected | function | Passes if a link with the specified label is found. | |
AssertLegacyTrait:: |
protected | function | Passes if a link containing a given href (part) is found. | |
AssertLegacyTrait:: |
protected | function | Asserts whether an expected cache tag was absent in the last response. | |
AssertLegacyTrait:: |
protected | function | Passes if the raw text is not found escaped on the loaded page. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field does NOT exist with the given name or ID. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field does not exist with the given ID and value. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field does not exist with the given name and value. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field does not exist or its value does not match, by XPath. | |
AssertLegacyTrait:: |
protected | function | Asserts that a checkbox field in the current page is not checked. | |
AssertLegacyTrait:: |
protected | function | Passes if a link with the specified label is not found. | |
AssertLegacyTrait:: |
protected | function | Passes if a link containing a given href (part) is not found. | |
AssertLegacyTrait:: |
protected | function | Asserts that a select option does NOT exist in the current page. | |
AssertLegacyTrait:: |
protected | function | Triggers a pass if the Perl regex pattern is not found in the raw content. | |
AssertLegacyTrait:: |
protected | function | Passes if the raw text IS not found on the loaded page, fail otherwise. | 1 |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotEquals() instead. | |
AssertLegacyTrait:: |
protected | function | Passes if the page (with HTML stripped) does not contains the text. | 1 |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotSame() instead. | |
AssertLegacyTrait:: |
protected | function | Passes if the text is found MORE THAN ONCE on the text version of the page. | |
AssertLegacyTrait:: |
protected | function | Asserts that a select option in the current page exists. | |
AssertLegacyTrait:: |
protected | function | Asserts that a select option with the visible text exists. | |
AssertLegacyTrait:: |
protected | function | Asserts that a select option in the current page is checked. | |
AssertLegacyTrait:: |
protected | function | Triggers a pass if the Perl regex pattern is found in the raw content. | |
AssertLegacyTrait:: |
protected | function | Passes if the raw text IS found on the loaded page, fail otherwise. | 1 |
AssertLegacyTrait:: |
protected | function | Asserts the page responds with the specified response code. | 1 |
AssertLegacyTrait:: |
protected | function | Passes if the page (with HTML stripped) contains the text. | 1 |
AssertLegacyTrait:: |
protected | function | Helper for assertText and assertNoText. | |
AssertLegacyTrait:: |
protected | function | Pass if the page title is the given string. | |
AssertLegacyTrait:: |
protected | function | Passes if the text is found ONLY ONCE on the text version of the page. | |
AssertLegacyTrait:: |
protected | function | Passes if the internal browser's URL matches the given path. | |
AssertLegacyTrait:: |
protected | function | Builds an XPath query. | |
AssertLegacyTrait:: |
protected | function | Helper: Constructs an XPath for the given set of attributes and value. | |
AssertLegacyTrait:: |
protected | function | Get all option elements, including nested options, in a select. | |
AssertLegacyTrait:: |
protected | function | Gets the current raw content. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead. | |
AssertLegacyTrait:: |
protected | function | ||
AssertLegacyTraitTest:: |
protected | property | The mocked page element used for testing. | |
AssertLegacyTraitTest:: |
protected | property | The mocked Mink session object used for testing. | |
AssertLegacyTraitTest:: |
protected | property | The mocked web assert class. | |
AssertLegacyTraitTest:: |
public | function |
Returns WebAssert object. Overrides AssertLegacyTrait:: |
|
AssertLegacyTraitTest:: |
protected | function | Returns a mocked behat session object. | |
AssertLegacyTraitTest:: |
public | function |
Overrides UnitTestCase:: |
|
AssertLegacyTraitTest:: |
public | function | @covers ::assertNoCacheTag @expectedDeprecation AssertLegacyTrait::assertNoCacheTag() is deprecated in drupal:8.4.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseHeaderNotContains() instead. See… | |
AssertLegacyTraitTest:: |
public | function | @covers ::assertNoPattern @expectedDeprecation AssertLegacyTrait::assertNoPattern() is deprecated in drupal:8.4.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseNotMatches() instead. See https://www.drupal.org/node/3129738 | |
AssertLegacyTraitTest:: |
public | function | @covers ::assertNoUniqueText | |
AssertLegacyTraitTest:: |
public | function | @covers ::assertNoUniqueText | |
AssertLegacyTraitTest:: |
public | function | @covers ::assertNoUniqueText | |
AssertLegacyTraitTest:: |
public | function | @covers ::assertNoUniqueText | |
AssertLegacyTraitTest:: |
public | function | @covers ::assertOptionSelected | |
AssertLegacyTraitTest:: |
public | function | @covers ::assertOptionSelected | |
AssertLegacyTraitTest:: |
public | function | @covers ::assertUniqueText | |
AssertLegacyTraitTest:: |
public | function | @covers ::assertUniqueText | |
AssertLegacyTraitTest:: |
public | function | @covers ::assertUniqueText | |
AssertLegacyTraitTest:: |
public | function | @covers ::assertUniqueText | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |