See #2735005: Convert all Simpletest web tests to BrowserTestBase (or UnitTestBase/KernelTestBase).

In scope:

  1. ResourceTest
  2. ExcludedFieldTokenTest (out-of-scope till #2863267: Convert web tests of views lands — landed!)
  3. StyleSerializerTest (out-of-scope till #2863267: Convert web tests of views lands — landed!)

Out-of-scope based on #2808777: Research: Complex tests to convert — these 4 tests are all UpdatePathTestBase tests:

  1. EntityResourcePermissionsUpdateTest
  2. ResourceGranularityUpdateTest
  3. RestConfigurationEntitiesUpdateTest
  4. RestExportAuthUpdateTest
Members fund testing for the Drupal project. Drupal Association Learn more

Comments

jmuzz created an issue. See original summary.

xjm’s picture

Status: Active » Closed (duplicate)

Going forward, let's please stop doing individual module conversions and do larger chunks at once. See #2770921: Feb 21st: Convert chunk of WTB to BTB by just moving classes, changing use statements adding traits and https://www.drupal.org/core/scope#incomplete.

michielnugter’s picture

Version: 8.2.x-dev » 8.4.x-dev
Status: Closed (duplicate) » Active

There are still WebTests in rest after the big bang, reopening the issue.

Wim Leers’s picture

Title: Convert web tests to browser tests for rest module » Convert web tests to browser tests for REST module

You're right, in the deprecated \Drupal\rest\Tests\RESTTestBase and its subclasses.

Lendude’s picture

Took a quick look at \Drupal\rest\Tests\ResourceTest but that will require more then a quick look :)

Updated the IS to set some scope on this conversion

dawehner’s picture

I'm wondering whether this case is the chance for us to provide a ApiTestBase, aka. something which provides methods like:

$this->request()

On the other hand I believe we should just convert the test over, given that we have a MUCH better test coverage in phpunit already.

michielnugter’s picture

Issue tags: +phpunit initiative
Wim Leers’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
1.38 KB

#2863267: Convert web tests of views landed.

Here's a start.

Wim Leers’s picture

Issue summary: View changes
Wim Leers’s picture

Issue summary: View changes

Now the IS reflects the actual scope & status.

Wim Leers’s picture

Assigned: Unassigned » Wim Leers
Status: Needs review » Needs work

Also doing StyleSerializerTest. Just one last failure…

dawehner’s picture

StyleSerializerTest That test takes sooooooooooo much time.

Wim Leers’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
18.21 KB
19.53 KB

Completed StyleSerializerTest.

Now working on the last one.

Wim Leers’s picture

Assigned: Wim Leers » Unassigned
FileSize
5.66 KB
25.13 KB

This should be green.

michielnugter’s picture

Did a quick code review and it looks good! Haven't found anything yet.

+++ b/core/modules/rest/src/Tests/ResourceTest.php
@@ -3,16 +3,20 @@
-class ResourceTest extends RESTTestBase {
+class ResourceTest extends BrowserTestBase {

I think it's a good thing base classes are dropped. It does make the test a little less magical.

Wim Leers’s picture

#15, that, and RESTTestBase is already deprecated anyway:

/**
 * Test helper class that provides a REST client method to send HTTP requests.
 *
 * @deprecated in Drupal 8.3.x-dev and will be removed before Drupal 9.0.0. Use \Drupal\Tests\rest\Functional\ResourceTestBase and \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase instead. Only retained for contributed module tests that may be using this base class.
 */
abstract class RESTTestBase extends WebTestBase {

naveenvalecha’s picture

Shall we also convert the RESTTestBase dependent tests also as the part of this and close this one as duplicate #2889882: Convert ResponseGeneratorTest, DbLogResourceTest, RestRegisterUserTest to BTB

Wim Leers’s picture

No, I'd rather get this in separately — that'd mean progress! I think #2889882: Convert ResponseGeneratorTest, DbLogResourceTest, RestRegisterUserTest to BTB will be a bit more painful.

Wim Leers’s picture

Issue tags: +API-First Initiative
naveenvalecha’s picture

Let's move the new tests to their namespace. Changes look good on local.

$ ../vendor/bin/phpunit modules/rest/tests/src/Functional/Views/ExcludedFieldTokenTest.php
PHPUnit 4.8.35 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\rest\Functional\Views\ExcludedFieldTokenTest
.

Time: 3.95 minutes, Memory: 4.00MB

OK (1 test, 2 assertions)

$ ../vendor/bin/phpunit modules/rest/tests/src/Functional/Views/StyleSerializerTest.php
PHPUnit 4.8.35 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\rest\Functional\Views\StyleSerializerTest
.............

Time: 1.02 hours, Memory: 4.00MB

OK (13 tests, 130 assertions)

$ ../vendor/bin/phpunit modules/rest/tests/src/Functional/ResourceTest.php
PHPUnit 4.8.35 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\rest\Functional\ResourceTest
....

Time: 11 minutes, Memory: 4.00MB

OK (4 tests, 95 assertions)


#18, That's fine. Removed ResourceTest from here #2889882: Convert ResponseGeneratorTest, DbLogResourceTest, RestRegisterUserTest to BTB

//Naveen

Wim Leers’s picture

Let's move the new tests to their namespace.

+1

So… is this then RTBC? (@naveenvalecha, just moving files doesn't mean you can't RTBC anymore.)

michielnugter’s picture

Status: Needs review » Reviewed & tested by the community

Did another review pass, everything looks good. Setting to RTBC!

naveenvalecha’s picture

Issue summary: View changes

RTBC +1


#16 +1 It's good to leave deprecated RESTTestBase where it is. Let's RESTTestBase child classes(ResponseGeneratorTest, DbLogResourceTest, RestRegisterUserTest) use the BTB directly.

//Naveen

dawehner’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs review

No, I'd rather get this in separately — that'd mean progress! I think #2889882: Convert RESTTestBase, ResponseGeneratorTest, DbLogResourceTest,ResourceTest, ResponseGeneratorTest WTB to BTB will be a bit more painful.

I agree, we have followed that strategy in multiple places.

  1. +++ b/core/modules/rest/src/Tests/ResourceTest.php
    @@ -86,37 +96,55 @@ public function testAuthentication() {
    +      RequestOptions::HEADERS => ['Content-Type' => 'application/json'],
    +      RequestOptions::BODY => $serialized,
    

    These constants are nice!

  2. +++ b/core/modules/rest/src/Tests/Views/StyleSerializerTest.php
    @@ -374,19 +365,19 @@ public function testResponseFormatConfiguration() {
    -    $this->assertTrue(strpos($headers['content-type'], 'text/xml') !== FALSE, 'The header Content-type is correct.');
    +    $this->assertSame($headers['Content-Type'], ['text/xml; charset=UTF-8']);
    
    @@ -606,7 +597,8 @@ public function testSerializerViewsUI() {
    +    $json_preview = $result[0]->getText();
    +    $this->assertSame($this->drupalGet('test/serialize/field'), $json_preview, 'The expected JSON preview output was found.');
    

    These are two instances where we switched to use assertSame, but we have the wrong order. Let's not introduce a small regression here.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
1.86 KB
25.83 KB

Fixed #24.2.

dawehner’s picture

Thank you @Wim Leers!

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

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

  • catch committed ef16fa1 on 8.5.x
    Issue #2775553 by Wim Leers, naveenvalecha: Convert web tests to browser...
catch’s picture

Version: 8.5.x-dev » 8.4.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.5.x and cherry-picked to 8.4.x. Thanks!

  • catch committed d9cabe9 on 8.4.x
    Issue #2775553 by Wim Leers, naveenvalecha: Convert web tests to browser...
Wim Leers’s picture

🎉

Status: Fixed » Closed (fixed)

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