Commit 2a740bf0 authored by Alex Pott's avatar Alex Pott Committed by catch
Browse files

Issue #3227265 by mondrake, murilohp: Remove the legacy assert traits

parent 00b88c25
Loading
Loading
Loading
Loading
+0 −993

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −231
Original line number Diff line number Diff line
@@ -257,41 +257,6 @@ public function testInvalidLinkNotExistsExact() {
    $this->assertSession()->linkNotExistsExact('foo|bar|baz');
  }

  /**
   * Tests legacy assertResponse().
   *
   * @group legacy
   */
  public function testAssertResponse() {
    $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
   */
  public function testAssertTitle() {
    $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
   */
  public function testAssertHeader() {
    $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');
    $account = $this->drupalCreateUser();
    $this->drupalLogin($account);
    $this->drupalGet('test-page');
    $this->assertHeader('X-Drupal-Cache-Tags', 'http_response rendered');
  }

  /**
   * Tests legacy text asserts.
   */
@@ -303,75 +268,6 @@ public function testTextAsserts() {
    $this->assertSession()->responseContains($sanitized);
  }

  /**
   * Tests legacy assertPattern().
   *
   * @group legacy
   */
  public function testAssertPattern() {
    $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
   */
  public function testAssertText() {
    $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
   */
  public function testAssertNoText() {
    $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
   */
  public function testGetRawContent() {
    $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->drupalGet('test-encoded');
    $this->assertSame($this->getSession()->getPage()->getContent(), $this->getRawContent());
  }

  /**
   * Tests legacy buildXPathQuery().
   *
   * @group legacy
   */
  public function testBuildXPathQuery() {
    $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
   */
  public function testAssertFieldsByValue() {
    $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');
    $this->drupalGet('test-field-xpath');
    $this->assertFieldsByValue($this->xpath("//h1[@class = 'page-title']"), NULL);
  }

  /**
   * Tests legacy field asserts which use xpath directly.
   */
@@ -403,36 +299,6 @@ public function testXpathAsserts() {
    }
  }

  /**
   * Tests legacy field asserts using textfields.
   *
   * @group legacy
   */
  public function testAssertField() {
    $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
   */
  public function testAssertFieldById() {
    $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');
    $this->drupalGet('test-field-xpath');
    $this->assertFieldById('edit-save', NULL);
    $this->assertNoFieldById('invalid', NULL);
    $this->assertFieldByXPath("//input[@id = 'edit-name']", 'Test name');
    $this->assertNoFieldByXPath("//input[@id = 'edit-name']", 'wrong value');
  }

  /**
   * Tests field asserts using textfields.
   */
@@ -544,64 +410,6 @@ 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
   */
  public function testFieldAssertsForOptions() {
    $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.');
    }
    catch (ExpectationException $e) {
      // Expected exception; just continue testing.
    }

    $this->assertTrue($this->assertSession()->optionExists('options', 2)->isSelected());
    try {
      $this->assertTrue($this->assertSession()->optionExists('options', 4)->isSelected());
      $this->fail('The select option "4" was selected.');
    }
    catch (ExpectationException $e) {
      // Expected exception; just continue testing.
    }

    try {
      $this->assertTrue($this->assertSession()->optionExists('options', 1)->isSelected());
      $this->fail('The select option "1" was selected.');
    }
    catch (ExpectationFailedException $e) {
      // Expected exception; just continue testing.
    }

  }

  /**
   * Tests legacy field asserts for button field type.
   */
@@ -637,19 +445,6 @@ public function testFieldAssertsForButton() {
    }
  }

  /**
   * Tests legacy assertFieldChecked() and assertNoFieldChecked().
   *
   * @group legacy
   */
  public function testLegacyFieldAssertsForCheckbox() {
    $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->drupalGet('test-field-xpath');
    $this->assertFieldChecked('edit-checkbox-enabled');
    $this->assertNoFieldChecked('edit-checkbox-disabled');
  }

  /**
   * Tests legacy field asserts for checkbox field type.
   */
@@ -875,19 +670,6 @@ public function testEscapingAssertions() {
    $assert->assertNoEscaped("<script>alert('Marked safe');alert(\"Marked safe\");</script>");
  }

  /**
   * Tests deprecation of legacy assertEscaped() and assertNoEscaped().
   *
   * @group legacy
   */
  public function testLegacyEscapingAssertions(): void {
    $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().
   *
@@ -933,19 +715,6 @@ public function testDeprecationHeaders() {
    $this->assertCount(1, $test_deprecation_messages);
  }

  /**
   * Tests legacy assertFieldByName() and assertNoFieldByName().
   *
   * @group legacy
   */
  public function testLegacyFieldAssertsByName() {
    $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->drupalGet('test-field-xpath');
    $this->assertFieldByName('checkbox_enabled', TRUE);
    $this->assertNoFieldByName('checkbox_enabled', FALSE);
  }

  /**
   * Tests legacy drupalGetHeader().
   *
+0 −36
Original line number Diff line number Diff line
<?php

namespace Drupal\FunctionalTests\Core\Test;

use Drupal\Tests\BrowserTestBase;

/**
 * Tests deprecated AssertLegacyTrait functionality.
 *
 * @group browsertestbase
 * @group legacy
 */
class AssertLegacyTraitDeprecatedTest extends BrowserTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  protected static $modules = ['form_test'];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * Tests getAllOptions().
   */
  public function testGetAllOptions() {
    $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');
    $this->drupalGet('/form-test/select');
    $this->assertCount(6, $this->getAllOptions($this->cssSelect('select[name="opt_groups"]')[0]));
  }

}
+0 −131
Original line number Diff line number Diff line
<?php

namespace Drupal\KernelTests;

/**
 * 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
 */
trait AssertLegacyTrait {

  /**
   * @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
   */
  protected function assert($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
   *   $this->assertEquals() instead.
   *
   * @see https://www.drupal.org/node/3129738
   */
  protected function assertEqual($actual, $expected, $message = '') {
    @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);
    $this->assertEquals($expected, $actual, (string) $message);
  }

  /**
   * @see \Drupal\simpletest\TestBase::assertNotEqual()
   *
   * @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
   */
  protected function assertNotEqual($actual, $expected, $message = '') {
    @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);
    $this->assertNotEquals($expected, $actual, (string) $message);
  }

  /**
   * @see \Drupal\simpletest\TestBase::assertIdentical()
   *
   * @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
   */
  protected function assertIdentical($actual, $expected, $message = '') {
    @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);
    $this->assertSame($expected, $actual, (string) $message);
  }

  /**
   * @see \Drupal\simpletest\TestBase::assertNotIdentical()
   *
   * @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
   */
  protected function assertNotIdentical($actual, $expected, $message = '') {
    @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);
    $this->assertNotSame($expected, $actual, (string) $message);
  }

  /**
   * @see \Drupal\simpletest\TestBase::assertIdenticalObject()
   *
   * @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
   */
  protected function assertIdenticalObject($actual, $expected, $message = '') {
    @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
    // though compares

    $this->assertEquals($expected, $actual, (string) $message);
  }

  /**
   * @see \Drupal\simpletest\TestBase::pass()
   *
   * @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
   */
  protected function pass($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
   */
  protected function verbose($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.
      fwrite(STDOUT, $message . "\n");
    }
  }

}
+0 −1
Original line number Diff line number Diff line
@@ -82,7 +82,6 @@
 */
abstract class KernelTestBase extends TestCase implements ServiceProviderInterface {

  use AssertLegacyTrait;
  use AssertContentTrait;
  use RandomGeneratorTrait;
  use ConfigTestTrait;
Loading