$this->expectDeprecation('AssertLegacyTrait::assertResponse() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->statusCodeEquals() instead. See https://www.drupal.org/node/3129738');
$this->drupalGet('test-encoded');
$this->assertResponse(200);
}
/**
* Tests legacy assertTitle().
*
* @group legacy
*/
publicfunctiontestAssertTitle(){
$this->expectDeprecation('AssertLegacyTrait::assertTitle() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->titleEquals() instead. See https://www.drupal.org/node/3129738');
$this->drupalGet('test-encoded');
$this->assertTitle("Page with encoded HTML | Drupal");
}
/**
* Tests legacy assertHeader().
*
* @group legacy
*/
publicfunctiontestAssertHeader(){
$this->expectDeprecation('AssertLegacyTrait::assertHeader() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseHeaderEquals() instead. See https://www.drupal.org/node/3129738');
$this->expectDeprecation('AssertLegacyTrait::assertPattern() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseMatches() instead. See https://www.drupal.org/node/3129738');
$this->drupalGet('test-escaped-characters');
$this->assertPattern('/div class.*escaped/');
}
/**
* Tests deprecated assertText.
*
* @group legacy
*/
publicfunctiontestAssertText(){
$this->expectDeprecation('AssertLegacyTrait::assertText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseContains() or $this->assertSession()->pageTextContains() instead. See https://www.drupal.org/node/3129738');
$this->expectDeprecation('Calling AssertLegacyTrait::assertText() 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()->responseContains() or $this->assertSession()->pageTextContains() instead. See https://www.drupal.org/node/3129738');
$this->drupalGet('test-encoded');
$dangerous='Bad html <script>alert(123);</script>';
$this->assertText(Html::escape($dangerous),'Sanitized text should be present.');
}
/**
* Tests deprecated assertNoText.
*
* @group legacy
*/
publicfunctiontestAssertNoText(){
$this->expectDeprecation('AssertLegacyTrait::assertNoText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseNotContains() or $this->assertSession()->pageTextNotContains() instead. See https://www.drupal.org/node/3129738');
$this->expectDeprecation('Calling AssertLegacyTrait::assertNoText() 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()->responseNotContains() or $this->assertSession()->pageTextNotContains() instead. See https://www.drupal.org/node/3129738');
$this->drupalGet('test-encoded');
$dangerous='Bad html <script>alert(123);</script>';
$this->assertNoText($dangerous,'Dangerous text should not be present.');
}
/**
* Tests legacy getRawContent().
*
* @group legacy
*/
publicfunctiontestGetRawContent(){
$this->expectDeprecation('AssertLegacyTrait::getRawContent() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->getSession()->getPage()->getContent() instead. See https://www.drupal.org/node/3129738');
$this->expectDeprecation('AssertLegacyTrait::buildXPathQuery() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->buildXPathQuery() instead. See https://www.drupal.org/node/3129738');
$this->buildXPathQuery('\\html');
}
/**
* Tests legacy assertFieldsByValue().
*
* @group legacy
*/
publicfunctiontestAssertFieldsByValue(){
$this->expectDeprecation('AssertLegacyTrait::assertFieldsByValue() is deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use iteration over the fields yourself instead and directly check the values in the test. See https://www.drupal.org/node/3129738');
* Tests legacy field asserts which use xpath directly.
*/
@@ -299,6 +403,36 @@ public function testXpathAsserts() {
}
}
/**
* Tests legacy field asserts using textfields.
*
* @group legacy
*/
publicfunctiontestAssertField(){
$this->expectDeprecation('AssertLegacyTrait::assertField() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldExists() or $this->assertSession()->buttonExists() instead. See https://www.drupal.org/node/3129738');
$this->expectDeprecation('AssertLegacyTrait::assertNoField() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldNotExists() or $this->assertSession()->buttonNotExists() instead. See https://www.drupal.org/node/3129738');
$this->drupalGet('test-field-xpath');
$this->assertField('name');
$this->assertNoField('invalid_name_and_id');
}
/**
* Tests legacy field asserts by id and by Xpath.
*
* @group legacy
*/
publicfunctiontestAssertFieldById(){
$this->expectDeprecation('AssertLegacyTrait::assertFieldById() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldExists() or $this->assertSession()->buttonExists() or $this->assertSession()->fieldValueEquals() instead. See https://www.drupal.org/node/3129738');
$this->expectDeprecation('AssertLegacyTrait::assertNoFieldById() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldNotExists() or $this->assertSession()->buttonNotExists() or $this->assertSession()->fieldValueNotEquals() instead. See https://www.drupal.org/node/3129738');
$this->expectDeprecation('AssertLegacyTrait::assertFieldByXPath() is deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use $this->xpath() instead and check the values directly in the test. See https://www.drupal.org/node/3129738');
$this->expectDeprecation('AssertLegacyTrait::assertNoFieldByXPath() is deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use $this->xpath() instead and assert that the result is empty. See https://www.drupal.org/node/3129738');
@@ -410,6 +544,64 @@ public function testFieldAssertsForTextfields() {
$this->assertSession()->fieldValueEquals('edit-test-textarea-with-newline',"Test text with\nnewline");
}
/**
* Tests legacy field asserts for options field type.
*
* @group legacy
*/
publicfunctiontestFieldAssertsForOptions(){
$this->expectDeprecation('AssertLegacyTrait::assertOptionByText() is deprecated in drupal:8.4.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionExists() instead. See https://www.drupal.org/node/3129738');
$this->expectDeprecation('AssertLegacyTrait::assertOption() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionExists() instead. See https://www.drupal.org/node/3129738');
$this->expectDeprecation('AssertLegacyTrait::assertNoOption() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionNotExists() instead. See https://www.drupal.org/node/3129738');
$this->drupalGet('test-field-xpath');
// Option field type.
$this->assertOptionByText('options','one');
try{
$this->assertOptionByText('options','four');
$this->fail('The select option "four" was found.');
}
catch(ExpectationException$e){
// Expected exception; just continue testing.
}
$this->assertOption('options',1);
try{
$this->assertOption('options',4);
$this->fail('The select option "4" was found.');
}
catch(ExpectationException$e){
// Expected exception; just continue testing.
}
$this->assertNoOption('options','non-existing');
try{
$this->assertNoOption('options','one');
$this->fail('The select option "one" was not found.');
$this->expectDeprecation('AssertLegacyTrait::assertFieldChecked() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->checkboxChecked() instead. See https://www.drupal.org/node/3129738');
$this->expectDeprecation('AssertLegacyTrait::assertNoFieldChecked() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->checkboxNotChecked() instead. See https://www.drupal.org/node/3129738');
$this->expectDeprecation('AssertLegacyTrait::assertNoEscaped() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->assertNoEscaped() instead. See https://www.drupal.org/node/3129738');
$this->expectDeprecation('AssertLegacyTrait::assertEscaped() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->assertEscaped() instead. See https://www.drupal.org/node/3129738');
$this->drupalGet('test-escaped-characters');
$this->assertNoEscaped('<div class="escaped">');
$this->assertEscaped('Escaped: <"\'&>');
}
/**
* Tests deprecation of drupalPostForm().
*
@@ -715,6 +933,19 @@ public function testDeprecationHeaders() {
$this->assertCount(1,$test_deprecation_messages);
}
/**
* Tests legacy assertFieldByName() and assertNoFieldByName().
*
* @group legacy
*/
publicfunctiontestLegacyFieldAssertsByName(){
$this->expectDeprecation('AssertLegacyTrait::assertFieldByName() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldExists() or $this->assertSession()->buttonExists() or $this->assertSession()->fieldValueEquals() instead. See https://www.drupal.org/node/3129738');
$this->expectDeprecation('AssertLegacyTrait::assertNoFieldByName() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldNotExists() or $this->assertSession()->buttonNotExists() or $this->assertSession()->fieldValueNotEquals() instead. See https://www.drupal.org/node/3129738');
$this->expectDeprecation('AssertLegacyTrait::getAllOptions() is deprecated in drupal:8.5.0 and is removed from drupal:10.0.0. Use $element->findAll(\'xpath\', \'option\') instead. See https://www.drupal.org/node/3129738');
* Translates Simpletest assertion methods to PHPUnit.
*
* Protected methods are custom. Public static methods override methods of
* \PHPUnit\Framework\Assert.
*
* @deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use
* PHPUnit's native assert methods instead.
*
* @see https://www.drupal.org/node/3129738
*/
traitAssertLegacyTrait{
/**
* @see \Drupal\simpletest\TestBase::assert()
*
* @deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use
* $this->assertTrue() instead.
*
* @see https://www.drupal.org/node/3129738
*/
protectedfunctionassert($actual,$message=''){
@trigger_error('AssertLegacyTrait::assert() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertTrue() instead. See https://www.drupal.org/node/3129738',E_USER_DEPRECATED);
parent::assertTrue((bool)$actual,$message);
}
/**
* @see \Drupal\simpletest\TestBase::assertEqual()
*
* @deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use
@trigger_error('AssertLegacyTrait::assertEqual() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertEquals() instead. See https://www.drupal.org/node/3129738',E_USER_DEPRECATED);
@trigger_error('AssertLegacyTrait::assertNotEqual() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertNotEquals() instead. See https://www.drupal.org/node/3129738',E_USER_DEPRECATED);
@trigger_error('AssertLegacyTrait::assertIdentical() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertSame() instead. See https://www.drupal.org/node/3129738',E_USER_DEPRECATED);
@trigger_error('AssertLegacyTrait::assertNotIdentical() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertNotSame() instead. See https://www.drupal.org/node/3129738',E_USER_DEPRECATED);
@trigger_error('AssertLegacyTrait::assertIdenticalObject() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertEquals() instead. See https://www.drupal.org/node/3129738',E_USER_DEPRECATED);
// Note: ::assertSame checks whether its the same object. ::assertEquals
* @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
*/
protectedfunctionpass($message){
@trigger_error('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',E_USER_DEPRECATED);
$this->assertTrue(TRUE,$message);
}
/**
* @see \Drupal\simpletest\TestBase::verbose()
*
* @deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use
* dump() instead.
*
* @see https://www.drupal.org/node/3197514
*/
protectedfunctionverbose($message){
@trigger_error('AssertLegacyTrait::verbose() is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use dump() instead. See https://www.drupal.org/node/3197514',E_USER_DEPRECATED);
if(in_array('--debug',$_SERVER['argv'],TRUE)){
// Write directly to STDOUT to not produce unexpected test output.
// The STDOUT stream does not obey output buffering.