class AssertLegacyTraitTest

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php \Drupal\Tests\Core\Assert\AssertLegacyTraitTest

@coversDefaultClass \Drupal\FunctionalTests\AssertLegacyTrait @group Assert @group legacy

Hierarchy

Expanded class hierarchy of AssertLegacyTraitTest

File

core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php, line 20

Namespace

Drupal\Tests\Core\Assert
View 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() : void {
        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 ::assertTextHelper
     */
    public function testAssertTextHelper() {
        $this->expectDeprecation('AssertLegacyTrait::assertTextHelper() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->pageTextContains() or $this->assertSession()->pageTextNotContains() instead. See https://www.drupal.org/node/3129738');
        $this->page
            ->getContent()
            ->willReturn('foo bar bar');
        $this->assertTextHelper('foo', FALSE);
    }
    
    /**
     * @covers ::assertRaw
     */
    public function testAssertRaw() {
        $this->expectDeprecation('AssertLegacyTrait::assertRaw() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseContains() instead. See https://www.drupal.org/node/3129738');
        $this->expectDeprecation('Calling AssertLegacyTrait::assertRaw() with more that one argument is deprecated in drupal:8.2.0 and the method is removed from drupal:10.0.0. Use $this->assertSession()->responseContains() instead. See https://www.drupal.org/node/3129738');
        $this->page
            ->getText()
            ->willReturn('foo bar bar');
        $this->assertRaw('foo', '\'foo\' should be present.');
    }
    
    /**
     * @covers ::assertNoRaw
     */
    public function testAssertNoRaw() {
        $this->expectDeprecation('AssertLegacyTrait::assertNoRaw() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseNotContains() instead. See https://www.drupal.org/node/3129738');
        $this->expectDeprecation('Calling AssertLegacyTrait::assertNoRaw() with more that one argument is deprecated in drupal:8.2.0 and the method is removed from drupal:10.0.0. Use $this->assertSession()->responseNotContains() instead. See https://www.drupal.org/node/3129738');
        $this->page
            ->getText()
            ->willReturn('foo bar bar');
        $this->assertNoRaw('qux', '\'qux\' should not be present.');
    }
    
    /**
     * @covers ::assertUniqueText
     */
    public function testAssertUniqueText() {
        $this->expectDeprecation('AssertLegacyTrait::assertUniqueText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->getSession()->pageTextContainsOnce() or $this->getSession()->pageTextMatchesCount() instead. See https://www.drupal.org/node/3129738');
        $this->page
            ->getText()
            ->willReturn('foo bar bar');
        $this->assertUniqueText('foo');
    }
    
    /**
     * @covers ::assertUniqueText
     */
    public function testAssertUniqueTextFail() {
        $this->expectDeprecation('AssertLegacyTrait::assertUniqueText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->getSession()->pageTextContainsOnce() or $this->getSession()->pageTextMatchesCount() instead. See https://www.drupal.org/node/3129738');
        $this->page
            ->getText()
            ->willReturn('foo bar bar');
        $this->expectException(ExpectationFailedException::class);
        $this->assertUniqueText('bar');
    }
    
    /**
     * @covers ::assertUniqueText
     */
    public function testAssertUniqueTextUnknown() {
        $this->expectDeprecation('AssertLegacyTrait::assertUniqueText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->getSession()->pageTextContainsOnce() or $this->getSession()->pageTextMatchesCount() instead. See https://www.drupal.org/node/3129738');
        $this->page
            ->getText()
            ->willReturn('foo bar bar');
        $this->expectException(ExpectationFailedException::class);
        $this->assertUniqueText('alice');
    }
    
    /**
     * @covers ::assertUniqueText
     */
    public function testAssertUniqueTextMarkup() {
        $this->expectDeprecation('AssertLegacyTrait::assertUniqueText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->getSession()->pageTextContainsOnce() or $this->getSession()->pageTextMatchesCount() instead. See https://www.drupal.org/node/3129738');
        $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->expectDeprecation('AssertLegacyTrait::assertNoUniqueText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Instead, use $this->getSession()->pageTextMatchesCount() if you know the cardinality in advance, or $this->getSession()->getPage()->getText() and substr_count(). See https://www.drupal.org/node/3129738');
        $this->page
            ->getText()
            ->willReturn('foo bar bar');
        $this->assertNoUniqueText('bar');
    }
    
    /**
     * @covers ::assertNoUniqueText
     */
    public function testAssertNoUniqueTextFail() {
        $this->expectDeprecation('AssertLegacyTrait::assertNoUniqueText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Instead, use $this->getSession()->pageTextMatchesCount() if you know the cardinality in advance, or $this->getSession()->getPage()->getText() and substr_count(). See https://www.drupal.org/node/3129738');
        $this->page
            ->getText()
            ->willReturn('foo bar bar');
        $this->expectException(ExpectationFailedException::class);
        $this->assertNoUniqueText('foo');
    }
    
    /**
     * @covers ::assertNoUniqueText
     */
    public function testAssertNoUniqueTextUnknown() {
        $this->expectDeprecation('AssertLegacyTrait::assertNoUniqueText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Instead, use $this->getSession()->pageTextMatchesCount() if you know the cardinality in advance, or $this->getSession()->getPage()->getText() and substr_count(). See https://www.drupal.org/node/3129738');
        $this->page
            ->getText()
            ->willReturn('foo bar bar');
        $this->expectException(ExpectationFailedException::class);
        $this->assertNoUniqueText('alice');
    }
    
    /**
     * @covers ::assertNoUniqueText
     */
    public function testAssertNoUniqueTextMarkup() {
        $this->expectDeprecation('AssertLegacyTrait::assertNoUniqueText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Instead, use $this->getSession()->pageTextMatchesCount() if you know the cardinality in advance, or $this->getSession()->getPage()->getText() and substr_count(). See https://www.drupal.org/node/3129738');
        $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() {
        $this->expectDeprecation('AssertLegacyTrait::assertOptionSelected() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionExists() instead and check the "selected" attribute. See https://www.drupal.org/node/3129738');
        $option_field = $this->prophesize(NodeElement::class);
        $option_field->hasAttribute('selected')
            ->willReturn(TRUE);
        $this->webAssert
            ->optionExists('my_select', 'two')
            ->willReturn($option_field->reveal());
        $this->assertOptionSelected('my_select', 'two');
    }
    
    /**
     * @covers ::assertOptionSelected
     */
    public function testAssertOptionSelectedFail() {
        $this->expectDeprecation('AssertLegacyTrait::assertOptionSelected() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionExists() instead and check the "selected" attribute. See https://www.drupal.org/node/3129738');
        $option_field = $this->prophesize(NodeElement::class);
        $option_field->hasAttribute('selected')
            ->willReturn(FALSE);
        $this->webAssert
            ->optionExists('my_select', 'two')
            ->willReturn($option_field->reveal());
        $this->expectException(ExpectationFailedException::class);
        $this->assertOptionSelected('my_select', 'two');
    }
    
    /**
     * @covers ::assertNoPattern
     */
    public function testAssertNoPattern() {
        $this->expectDeprecation('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');
        $this->webAssert
            ->responseNotMatches('/.*foo$/')
            ->shouldBeCalled();
        $this->assertNoPattern('/.*foo$/');
    }
    
    /**
     * @covers ::assertCacheTag
     */
    public function testAssertCacheTag() {
        $this->expectDeprecation('AssertLegacyTrait::assertCacheTag() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseHeaderContains() instead. See https://www.drupal.org/node/3129738');
        $this->webAssert
            ->responseHeaderContains('X-Drupal-Cache-Tags', 'some-cache-tag')
            ->shouldBeCalled();
        $this->assertCacheTag('some-cache-tag');
    }
    
    /**
     * @covers ::assertNoCacheTag
     */
    public function testAssertNoCacheTag() {
        $this->expectDeprecation('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');
        $this->webAssert
            ->responseHeaderNotContains('X-Drupal-Cache-Tags', 'some-cache-tag')
            ->shouldBeCalled();
        $this->assertNoCacheTag('some-cache-tag');
    }
    
    /**
     * @covers ::assertUrl
     */
    public function testAssertUrl() {
        $this->expectDeprecation('AssertLegacyTrait::assertUrl() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->addressEquals() instead. See https://www.drupal.org/node/3129738');
        $this->expectDeprecation('Calling AssertLegacyTrait::assertUrl() with more than one argument is deprecated in drupal:8.2.0 and the method is removed from drupal:10.0.0. Use $this->assertSession()->addressEquals() instead. See https://www.drupal.org/node/3129738');
        $this->webAssert
            ->addressEquals('bingo')
            ->shouldBeCalled();
        $this->assertUrl('bingo', 'Redundant message.');
    }
    
    /**
     * @covers ::assertElementPresent
     */
    public function testAssertElementPresent() {
        $this->expectDeprecation('AssertLegacyTrait::assertElementPresent() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->elementExists() instead. See https://www.drupal.org/node/3129738');
        $this->webAssert
            ->elementExists('css', '.pager')
            ->shouldBeCalled();
        $this->assertElementPresent('.pager');
    }
    
    /**
     * @covers ::assertElementNotPresent
     */
    public function testAssertElementNotPresent() {
        $this->expectDeprecation('AssertLegacyTrait::assertElementNotPresent() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->elementNotExists() instead. See https://www.drupal.org/node/3129738');
        $this->webAssert
            ->elementNotExists('css', '.pager')
            ->shouldBeCalled();
        $this->assertElementNotPresent('.pager');
    }
    
    /**
     * @covers ::pass
     */
    public function testPass() {
        $this->expectDeprecation('AssertLegacyTrait::pass() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. PHPUnit interrupts a test as soon as a test assertion fails, so there is usually no need to call this method. If a test\'s logic relies on this method, refactor the test. See https://www.drupal.org/node/3129738');
        $this->pass('Passed.');
    }
    
    /**
     * @covers ::assertLinkByHref
     */
    public function testAssertLinkByHref() {
        $this->expectDeprecation('AssertLegacyTrait::assertLinkByHref() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->linkByHrefExists() instead. See https://www.drupal.org/node/3129738');
        $this->webAssert
            ->linkByHrefExists('boo', 0)
            ->shouldBeCalled();
        $this->assertLinkByHref('boo', 0);
    }
    
    /**
     * @covers ::assertNoLinkByHref
     */
    public function testAssertNoLinkByHref() {
        $this->expectDeprecation('AssertLegacyTrait::assertNoLinkByHref() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->linkByHrefNotExists() instead. See https://www.drupal.org/node/3129738');
        $this->webAssert
            ->linkByHrefNotExists('boo')
            ->shouldBeCalled();
        $this->assertNoLinkByHref('boo');
    }
    
    /**
     * @covers ::constructFieldXpath
     */
    public function testConstructFieldXpath() {
        $this->expectDeprecation('AssertLegacyTrait::constructFieldXpath() is deprecated in drupal:8.5.0 and is removed from drupal:10.0.0. Use $this->getSession()->getPage()->findField() instead. See https://www.drupal.org/node/3129738');
        $this->webAssert
            ->buildXPathQuery(Argument::any(), Argument::any())
            ->willReturn('qux');
        $this->assertSame('qux', $this->constructFieldXpath('foo', [
            'bar',
        ]));
    }
    
    /**
     * 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

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
AssertLegacyTrait::assert Deprecated protected function
AssertLegacyTrait::assertCacheTag Deprecated protected function Asserts whether an expected cache tag was present in the last response.
AssertLegacyTrait::assertElementNotPresent Deprecated protected function Asserts that the element with the given CSS selector is not present.
AssertLegacyTrait::assertElementPresent Deprecated protected function Asserts that the element with the given CSS selector is present.
AssertLegacyTrait::assertEqual Deprecated protected function
AssertLegacyTrait::assertEscaped Deprecated protected function Passes if the raw text IS found escaped on the loaded page, fail otherwise.
AssertLegacyTrait::assertField Deprecated protected function Asserts that a field exists with the given name or ID.
AssertLegacyTrait::assertFieldById Deprecated protected function Asserts that a field exists with the given ID and value.
AssertLegacyTrait::assertFieldByName Deprecated protected function Asserts that a field exists with the given name and value.
AssertLegacyTrait::assertFieldByXPath Deprecated protected function Asserts that a field exists in the current page by the given XPath.
AssertLegacyTrait::assertFieldChecked Deprecated protected function Asserts that a checkbox field in the current page is checked.
AssertLegacyTrait::assertFieldsByValue Deprecated protected function Asserts that a field exists in the current page with a given Xpath result.
AssertLegacyTrait::assertHeader Deprecated protected function Checks that current response header equals value.
AssertLegacyTrait::assertIdentical Deprecated protected function
AssertLegacyTrait::assertIdenticalObject Deprecated protected function
AssertLegacyTrait::assertLink Deprecated protected function Passes if a link with the specified label is found.
AssertLegacyTrait::assertLinkByHref Deprecated protected function Passes if a link containing a given href (part) is found.
AssertLegacyTrait::assertNoCacheTag Deprecated protected function Asserts whether an expected cache tag was absent in the last response.
AssertLegacyTrait::assertNoEscaped Deprecated protected function Passes if the raw text is not found escaped on the loaded page.
AssertLegacyTrait::assertNoField Deprecated protected function Asserts that a field does NOT exist with the given name or ID.
AssertLegacyTrait::assertNoFieldById Deprecated protected function Asserts that a field does not exist with the given ID and value.
AssertLegacyTrait::assertNoFieldByName Deprecated protected function Asserts that a field does not exist with the given name and value.
AssertLegacyTrait::assertNoFieldByXPath Deprecated protected function Asserts that a field does not exist or its value does not match, by XPath.
AssertLegacyTrait::assertNoFieldChecked Deprecated protected function Asserts that a checkbox field in the current page is not checked.
AssertLegacyTrait::assertNoLink Deprecated protected function Passes if a link with the specified label is not found.
AssertLegacyTrait::assertNoLinkByHref Deprecated protected function Passes if a link containing a given href (part) is not found.
AssertLegacyTrait::assertNoOption Deprecated protected function Asserts that a select option does NOT exist in the current page.
AssertLegacyTrait::assertNoPattern Deprecated protected function Triggers a pass if the Perl regex pattern is not found in the raw content.
AssertLegacyTrait::assertNoRaw Deprecated protected function Passes if the raw text IS not found on the loaded page, fail otherwise.
AssertLegacyTrait::assertNotEqual Deprecated protected function
AssertLegacyTrait::assertNoText Deprecated protected function Passes if the page (with HTML stripped) does not contains the text.
AssertLegacyTrait::assertNotIdentical Deprecated protected function
AssertLegacyTrait::assertNoUniqueText Deprecated protected function Passes if the text is found MORE THAN ONCE on the text version of the page.
AssertLegacyTrait::assertOption Deprecated protected function Asserts that a select option in the current page exists.
AssertLegacyTrait::assertOptionByText Deprecated protected function Asserts that a select option with the visible text exists.
AssertLegacyTrait::assertOptionSelected Deprecated protected function Asserts that a select option in the current page is checked.
AssertLegacyTrait::assertPattern Deprecated protected function Triggers a pass if the Perl regex pattern is found in the raw content.
AssertLegacyTrait::assertRaw Deprecated protected function Passes if the raw text IS found on the loaded page, fail otherwise.
AssertLegacyTrait::assertResponse Deprecated protected function Asserts the page responds with the specified response code.
AssertLegacyTrait::assertText Deprecated protected function Passes if the page (with HTML stripped) contains the text.
AssertLegacyTrait::assertTextHelper Deprecated protected function Helper for assertText and assertNoText.
AssertLegacyTrait::assertTitle Deprecated protected function Pass if the page title is the given string.
AssertLegacyTrait::assertUniqueText Deprecated protected function Passes if the text is found ONLY ONCE on the text version of the page.
AssertLegacyTrait::assertUrl Deprecated protected function Passes if the internal browser's URL matches the given path.
AssertLegacyTrait::buildXPathQuery Deprecated protected function Builds an XPath query.
AssertLegacyTrait::constructFieldXpath Deprecated protected function Helper: Constructs an XPath for the given set of attributes and value.
AssertLegacyTrait::getAllOptions Deprecated protected function Get all option elements, including nested options, in a select.
AssertLegacyTrait::getRawContent Deprecated protected function Gets the current raw content.
AssertLegacyTrait::pass Deprecated protected function
AssertLegacyTrait::verbose Deprecated protected function
AssertLegacyTraitTest::$page protected property The mocked page element used for testing.
AssertLegacyTraitTest::$session protected property The mocked Mink session object used for testing.
AssertLegacyTraitTest::$webAssert protected property The mocked web assert class.
AssertLegacyTraitTest::assertSession public function Returns WebAssert object. Overrides AssertLegacyTrait::assertSession
AssertLegacyTraitTest::getSession protected function Returns a mocked behat session object.
AssertLegacyTraitTest::setUp public function Overrides UnitTestCase::setUp
AssertLegacyTraitTest::testAssertCacheTag public function @covers ::assertCacheTag
AssertLegacyTraitTest::testAssertElementNotPresent public function @covers ::assertElementNotPresent
AssertLegacyTraitTest::testAssertElementPresent public function @covers ::assertElementPresent
AssertLegacyTraitTest::testAssertLinkByHref public function @covers ::assertLinkByHref
AssertLegacyTraitTest::testAssertNoCacheTag public function @covers ::assertNoCacheTag
AssertLegacyTraitTest::testAssertNoLinkByHref public function @covers ::assertNoLinkByHref
AssertLegacyTraitTest::testAssertNoPattern public function @covers ::assertNoPattern
AssertLegacyTraitTest::testAssertNoRaw public function @covers ::assertNoRaw
AssertLegacyTraitTest::testAssertNoUniqueText public function @covers ::assertNoUniqueText
AssertLegacyTraitTest::testAssertNoUniqueTextFail public function @covers ::assertNoUniqueText
AssertLegacyTraitTest::testAssertNoUniqueTextMarkup public function @covers ::assertNoUniqueText
AssertLegacyTraitTest::testAssertNoUniqueTextUnknown public function @covers ::assertNoUniqueText
AssertLegacyTraitTest::testAssertOptionSelected public function @covers ::assertOptionSelected
AssertLegacyTraitTest::testAssertOptionSelectedFail public function @covers ::assertOptionSelected
AssertLegacyTraitTest::testAssertRaw public function @covers ::assertRaw
AssertLegacyTraitTest::testAssertTextHelper public function @covers ::assertTextHelper
AssertLegacyTraitTest::testAssertUniqueText public function @covers ::assertUniqueText
AssertLegacyTraitTest::testAssertUniqueTextFail public function @covers ::assertUniqueText
AssertLegacyTraitTest::testAssertUniqueTextMarkup public function @covers ::assertUniqueText
AssertLegacyTraitTest::testAssertUniqueTextUnknown public function @covers ::assertUniqueText
AssertLegacyTraitTest::testAssertUrl public function @covers ::assertUrl
AssertLegacyTraitTest::testConstructFieldXpath public function @covers ::constructFieldXpath
AssertLegacyTraitTest::testPass public function @covers ::pass
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals Deprecated protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUpBeforeClass public static function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.