Problem/Motivation

All the following WTB tests use getRawContent() which doesn't exist in BTB.

AddFeedTest
BigPipeTest
BlockRenderOrderTest
CommentBlockTest
CommentPreviewTest
CommentTestBase
CommentNonNodeTest
CommentTestBase
CommentRestExportTest
CommentUserNameTest
ConfigExportImportUITest
ConfigExportUITest
EditorAdminTest
EditorLoadingTest
ManageDisplayTest
FileListingTest
NumberFieldRdfaTest
StyleSerializerTest
FormTest
ThemeTest
RenderWebTest
SelectPagerDefaultTest
SelectTableSortDefaultTest
TemporaryQueryTest
LanguageSelectElementTest
DestinationTest
SessionAuthenticationTest
SessionTest
ShutdownFunctionsTest
EngineTwigTest
ThemeSuggestionsAlterTest
UpdateContribTest
UserBlocksTest
ViewsFormTest
ItemsPerPageTest
SortingTest
PreviewTest

Proposed resolution

Create getRawContent() in BTB so we can easily convert WTB to BTB as defined in #2735005: Convert all Simpletest web tests to BrowserTestBase (or UnitTestBase/KernelTestBase)

Comments

dawehner created an issue. See original summary.

jmuzz’s picture

Some of these tests already have patches.

AddFeedTest - #2757023: Convert all aggregator web tests to BrowserTestBase
ManageDisplayTest - #2794347: Convert web tests to browser tests for field_ui module

I didn't check all of them.

dawehner’s picture

@jmuzz
Given the decision which was made in #2735005: Convert all Simpletest web tests to BrowserTestBase (or UnitTestBase/KernelTestBase) we should change things on a per scope bit, not on a per module bit.

jmuzz’s picture

Ok. And a scope I assume is something like "tests using getRawContent()" so the relevant parts of the other patches should be included in a patch for this issue.

dawehner’s picture

Yeah that would be ideal. We want to not longer to individual conversions, but rather come up with some general pattern of stuff we have to fix.

jmuzz’s picture

What about adding the function to BTB for #2794285: [meta] Add backwards compatibility layer to browsertestbase to ease conversion from webtestcase ? xjm mentioned that before but I don't think it was ever responded to. It seems like it would be a lot faster than converting all the tests manually.

  /**
   * Retrieves the raw content from the current page.
   */
  protected function getRawContent() {
    return $this->getSession()->getPage()->getContent();
  }

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

goz’s picture

Assigned: Unassigned » goz
Issue tags: +DevDaysSeville
goz’s picture

Title: Convert Tests using getRawContent() to assertRaw() and similar. » WTB to BTB, add getRawContent() in BTB
Issue summary: View changes
goz’s picture

Status: Active » Needs review
StatusFileSize
new917 bytes

Status: Needs review » Needs work

The last submitted patch, 10: wtb_to_btb_add-2795111-10.patch, failed testing.

goz’s picture

Assigned: goz » Unassigned

First test pass. Unassign issue.

goz’s picture

Status: Needs work » Needs review
dawehner’s picture

Should we mark this method as deprecated already?

claudiu.cristea’s picture

Status: Needs review » Needs work

Please see @klausi's comment from #2757023-24: Convert all aggregator web tests to BrowserTestBase:

The original getRawContent() method is in AssertContentTrait, so I vote to implement it in AssertLegacyTrait. We should open an issue for that and add test coverage for it to BrowserTestBaseTest.

goz’s picture

Assigned: Unassigned » goz
goz’s picture

Assigned: goz » Unassigned
StatusFileSize
new1.07 KB
new1.3 KB

Move getRawContent() to AssertLegacyTrait and add deprecated message.

Still have to do:
- Discuss if this stay in assertLegacyTrait
- Discuss if we should add a change record and a @trigger.error()
- Add test coverage in BrowserTestBaseTest

claudiu.cristea’s picture

Status: Needs work » Needs review
dawehner’s picture

Status: Needs review » Needs work
+++ b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php
@@ -718,4 +718,14 @@ protected function buildXPathQuery($xpath, array $args = []) {
+   *
+   * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0.
+   *   Use $this->getSession()->getPage()->getContent() instead.
+   */

We should use trigger_error now, see https://www.drupal.org/core/deprecation

klausi’s picture

+++ b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php
@@ -718,4 +718,14 @@ protected function buildXPathQuery($xpath, array $args = []) {
+   * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0.
+   *   Use $this->getSession()->getPage()->getContent() instead.

The first line should be "@deprecated Scheduled for removal in Drupal 9.0.0." same as on the other methods here.

jofitz’s picture

Status: Needs work » Needs review
StatusFileSize
new902 bytes
new900 bytes
  • Added trigger_error
  • Match @deprecated with the rest of the file.
klausi’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thanks, now we need test coverage in BrowserTestBaseTest.

jofitz’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new3.08 KB
new2.2 KB

Added a test.

klausi’s picture

Status: Needs review » Needs work
+++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
@@ -232,4 +232,12 @@ public function testInstall() {
+  public function testRawContent() {
+    $this->drupalGet('test-json');
+    $this->assertEquals('{"some":"data"}', $this->getRawContent());
+  }

I think it is not necessary to add a whole new test method just to call getRawContent(). We can just add a line to testGoTo() like $this->assertSame($this->getSession()->getPage()->getContent(), $this->getRawContent());

That makes sure that the method exists and returns the expected thing without knowing anything about the content.

jofitz’s picture

Status: Needs work » Needs review
StatusFileSize
new1.48 KB
new1.89 KB

I have added your suggested assert to testLegacyTextAsserts() to keep legacy tests separate.

klausi’s picture

Status: Needs review » Needs work

Right, testLegacyTextAsserts() also works for me.

+++ b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php
@@ -718,4 +718,15 @@ protected function buildXPathQuery($xpath, array $args = []) {
+   * @deprecated Scheduled for removal in Drupal 9.0.0.
+   *   Use $this->getSession()->getPage()->getContent() instead.
+   */
+  protected function getRawContent() {
+    @trigger_error('AssertLegacyTrait::getRawContent() is scheduled for removal in Drupal 9.0.0. Use $this->assertSession()->buildXPathQuery() instead.', E_USER_DEPRECATED);

message is wrong, this should say the same as the doc comment.

jofitz’s picture

That does not seem to follow the guidelines: https://www.drupal.org/core/deprecation

klausi’s picture

Sorry, I meant that "$this->assertSession()->buildXPathQuery()" is wrong in the message. This should be "$this->getSession()->getPage()->getContent()".

jofitz’s picture

Status: Needs work » Needs review
StatusFileSize
new1.48 KB
new895 bytes

I don't know where that came from!
copy_paste--

claudiu.cristea’s picture

Status: Needs review » Reviewed & tested by the community

Looks ready. We need it :)

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 1e56b1f to 8.4.x and e425b10 to 8.3.x. Thanks!

  • alexpott committed 1e56b1f on 8.4.x
    Issue #2795111 by Jo Fitzgerald, GoZ, dawehner, klausi: WTB to BTB, add...

  • alexpott committed e425b10 on 8.3.x
    Issue #2795111 by Jo Fitzgerald, GoZ, dawehner, klausi: WTB to BTB, add...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.