31 Class Drupal\testing_example\Tests\SimpleTestExampleTest extends deprecated class Drupal\simpletest\WebTestBase:

in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Instead,

use \Drupal\Tests\BrowserTestBase. See https://www.drupal.org/node/3030340.

Comments

darkdim created an issue. See original summary.

darkdim’s picture

darkdim’s picture

darkdim’s picture

Assigned: darkdim » Unassigned
Status: Active » Needs review
andypost’s picture

Status: Needs review » Needs work

Patch should be applicable with patch -p1

darkdim’s picture

Status: Needs work » Needs review
StatusFileSize
new3.09 KB

new patch, sorry

andypost’s picture

index 3a3b1e1..ef7c462 100644
--- a/testing_example/src/Tests/NaiveConversionTest.php

--- a/testing_example/src/Tests/NaiveConversionTest.php
+++ b/testing_example/src/Tests/NaiveConversionTest.php

@@ -6,15 +6,15 @@
-use Drupal\simpletest\WebTestBase;
+use Drupal\Tests\BrowserTestBase;

index 3e8a9e7..c7c5dd1 100644
--- a/testing_example/src/Tests/SimpleTestExampleMockModuleTest.php

--- a/testing_example/src/Tests/SimpleTestExampleMockModuleTest.php
+++ b/testing_example/src/Tests/SimpleTestExampleMockModuleTest.php

@@ -2,7 +2,7 @@
-use Drupal\simpletest\WebTestBase;
+use Drupal\Tests\BrowserTestBase;

You need to move the files as well - out of src to "tests"

darkdim’s picture

moved files to tests

mile23’s picture

It's an example of how to write a Simpletest-based test.

darkdim’s picture

mile23’s picture

Title: use \Drupal\Tests\BrowserTestBase. See https://www. drupal.org/node/3030340 » Remove all WebTestBase examples
Status: Needs review » Needs work

WebTestBase is deprecated, so we don't need any examples of how to make them. https://www.drupal.org/node/3030340

Just remove them.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new3.8 KB
new1.75 KB

This 3 are the only remains, so I removed NaiveConversionTest.php and cleaned a bit last 2

andypost’s picture

it may need to check code comment about simpletest but surely that's follow-up

andypost’s picture

StatusFileSize
new1015 bytes
new3.81 KB

Missed to fix namespace

mile23’s picture

OK, I got the rescope wrong.

This code, and the module containing it, is instructing you how to convert a WebTestBase test to a BrowserTestBase one.

This is information people will need moving forward.

Whether this information belongs in Examples or not is another story, because it's also present in documentation, linked from the change record: https://www.drupal.org/node/3030340

It's also true that @xjm has said that WTB might become undeprecated before the D9 release, in which case no one needs to learn how to convert WTB tests for another 4 years.

I suggest closing this issue as won't fix. Nothing is actually broken in this documentation-oriented project.

kristen pol’s picture

Issue tags: +Drupal 9 compatibility

Per a Slack discussion with Gábor Hojtsy regarding usage of D9 tags (Drupal 9, Drupal 9 compatibility, Drupal 9 readiness, etc.), "Drupal 9 compatibility" should be used for contributed projects that need updating and "Drupal 9" was the old tag for D8 issues before the D9 branch was ready. Doing tag cleanup here based on that discussion.

jungle’s picture

Version: 8.x-1.x-dev » 3.x-dev
jungle’s picture

+++ b/testing_example/tests/src/Functional/SimpleTestExampleTest.php
@@ -28,13 +27,13 @@ use Drupal\simpletest\WebTestBase;
+   * In Drupal 8's Tests, we declare module dependencies in a public
+   * static property called $modules. Testing system automatically enables these

Wrapped too early. But can be fixed on committing.

jungle’s picture

I suggest closing this issue as won't fix. Nothing is actually broken in this documentation-oriented project.

Do not understand @Mile23's comment in #15, I think this patch is good to go.

jungle’s picture

modules/contrib/examples/testing_example/src/Tests/NaiveConversionTest.php:
┌─────────┬──────┬──────────────────────────────────────────────────────────────┐
│ STATUS  │ LINE │                           MESSAGE                            │
├─────────┼──────┼──────────────────────────────────────────────────────────────┤
│ Fix now │ 17   │ Class Drupal\testing_example\Tests\NaiveConversionTest       │
│         │      │ extends deprecated class Drupal\simpletest\WebTestBase.      │
│         │      │ Deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. │
│         │      │ Instead, use Drupal\Tests\BrowserTestBase. See               │
│         │      │ https://www.drupal.org/node/3030340. Replacement available   │
│         │      │ from drupal:8.6.0.                                           │
│         │      │                                                              │
└─────────┴──────┴──────────────────────────────────────────────────────────────┘

modules/contrib/examples/testing_example/src/Tests/SimpleTestExampleMockModuleTe
st.php:
┌─────────┬──────┬──────────────────────────────────────────────────────────────┐
│ STATUS  │ LINE │                           MESSAGE                            │
├─────────┼──────┼──────────────────────────────────────────────────────────────┤
│ Fix now │ 32   │ Class                                                        │
│         │      │ Drupal\testing_example\Tests\SimpleTestExampleMockModuleTest │
│         │      │ extends deprecated class Drupal\simpletest\WebTestBase.      │
│         │      │ Deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. │
│         │      │ Instead, use Drupal\Tests\BrowserTestBase. See               │
│         │      │ https://www.drupal.org/node/3030340. Replacement available   │
│         │      │ from drupal:8.6.0.                                           │
│         │      │                                                              │
└─────────┴──────┴──────────────────────────────────────────────────────────────┘

modules/contrib/examples/testing_example/src/Tests/SimpleTestExampleTest.php:
┌─────────┬──────┬──────────────────────────────────────────────────────────────┐
│ STATUS  │ LINE │                           MESSAGE                            │
├─────────┼──────┼──────────────────────────────────────────────────────────────┤
│ Fix now │ 31   │ Class Drupal\testing_example\Tests\SimpleTestExampleTest     │
│         │      │ extends deprecated class Drupal\simpletest\WebTestBase.      │
│         │      │ Deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. │
│         │      │ Instead, use Drupal\Tests\BrowserTestBase. See               │
│         │      │ https://www.drupal.org/node/3030340. Replacement available   │
│         │      │ from drupal:8.6.0.                                           │
│         │      │                                                              │
└─────────┴──────┴──────────────────────────────────────────────────────────────┘

The patch kicked the deprecated messages above away.

andypost’s picture

I think this code needs removal for 9.x because there's no simpletest WTB (WebTestBase) in 9.0
Also there's great docs linked in https://www.drupal.org/node/3030340

I bet on just removal of outdated tests as they were used only to explain conversion process which is documented now

jungle’s picture

Thanks @andypost!

+++ b/testing_example/tests/src/Functional/SimpleTestExampleMockModuleTest.php
@@ -29,15 +29,10 @@ use Drupal\simpletest\WebTestBase;
-class SimpleTestExampleMockModuleTest extends WebTestBase {

+++ b/testing_example/tests/src/Functional/SimpleTestExampleTest.php
@@ -28,13 +27,13 @@ use Drupal\simpletest\WebTestBase;
+class SimpleTestExampleTest extends BrowserTestBase {

So to remove the two files as well?

jungle’s picture

StatusFileSize
new9.95 KB

All 3 test files in #20 removed. no interdiff.

vladimiraus’s picture

Status: Needs review » Needs work

Drupal rector report:

4 files with changes
====================

1) modules/contrib/examples/cron_example/cron_example.module

    ---------- begin diff ----------
--- Original
+++ New
@@ -37,7 +37,7 @@
   // We usually don't want to act every time cron runs (which could be every
   // minute) so keep a time for the next run in the site state.
   $next_execution = \Drupal::state()->get('cron_example.next_execution', 0);
-  if (REQUEST_TIME >= $next_execution) {
+  if (\Drupal::time()->getRequestTime() >= $next_execution) {
     // This is a silly example of a cron job.
     // It just makes it obvious that the job has run without
     // making any changes to your database.
@@ -46,7 +46,7 @@
       \Drupal::messenger()->addMessage(t('cron_example executed at %time', ['%time' => date('c')]));
       \Drupal::state()->set('cron_example_show_status_message', FALSE);
     }
-    \Drupal::state()->set('cron_example.next_execution', REQUEST_TIME + $interval);
+    \Drupal::state()->set('cron_example.next_execution', \Drupal::time()->getRequestTime() + $interval);
   }
 }
    ----------- end diff -----------


Applied rules:

 * DrupalRector\Rector\Deprecation\RequestTimeConstRector


2) modules/contrib/examples/cron_example/src/Form/CronExampleForm.php

    ---------- begin diff ----------
--- Original
+++ New
@@ -95,11 +95,11 @@
     ];

     $next_execution = $this->state->get('cron_example.next_execution');
-    $next_execution = !empty($next_execution) ? $next_execution : REQUEST_TIME;
+    $next_execution = !empty($next_execution) ? $next_execution : \Drupal::time()->getRequestTime();

     $args = [
       '%time' => date('c', $this->state->get('cron_example.next_execution')),
-      '%seconds' => $next_execution - REQUEST_TIME,
+      '%seconds' => $next_execution - \Drupal::time()->getRequestTime(),
     ];
     $form['status']['last'] = [
       '#type' => 'item',
@@ -220,7 +220,7 @@
       // Create a new item, a new data object, which is passed to the
       // QueueWorker's processItem() method.
       $item = new \stdClass();
-      $item->created = REQUEST_TIME;
+      $item->created = \Drupal::time()->getRequestTime();
       $item->sequence = $i;
       $queue->createItem($item);
     }
    ----------- end diff -----------


Applied rules:

 * DrupalRector\Rector\Deprecation\RequestTimeConstRector


3) modules/contrib/examples/hooks_example/hooks_example.api.php

    ---------- begin diff ----------
--- Original
+++ New
@@ -1,5 +1,6 @@
 <?php

+use Drupal\node\NodeInterface;
 /**
  * @file
  * Hooks specific to the Hooks Example module.
@@ -40,7 +41,7 @@
  * @param \Drupal\node\NodeInterface $node
  *   The node being viewed.
  */
-function hook_hooks_example_count_incremented($current_count, \Drupal\node\NodeInterface $node) {
+function hook_hooks_example_count_incremented($current_count, NodeInterface $node) {
   // If this is the first time the user has viewed this node we display a
   // message letting them know.
   if ($current_count === 1) {
    ----------- end diff -----------


4) modules/contrib/examples/render_example/src/Controller/RenderExampleController.php

    ---------- begin diff ----------
--- Original
+++ New
@@ -489,7 +489,7 @@
     $build = [
       'lazy_builder_time' => [
         '#markup' => '<p>' . \Drupal::translation()->translate('The current time is @time', [
-          '@time' => \Drupal::service('date.formatter')->format(REQUEST_TIME, 'long'),
+          '@time' => \Drupal::service('date.formatter')->format(\Drupal::time()->getRequestTime(), 'long'),
         ]) . '</p>',
       ],
     ];
    ----------- end diff -----------


[ERROR] Could not process                                                      
         "modules/contrib/examples/testing_example/tests/src/Unit/Controller/Con
         trivedControllerTest.php" file, due to:                                
         "Pick more specific node than "PhpParser\Node\Expr\MethodCall", e.g.   
         "$node->name"                                                          
                                                                                
         Caused in                                                              
         "modules/contrib/examples/testing_example/tests/src/Unit/Controller/Con
         trivedControllerTest.php" file on line 30 on code                      
         "$this->getMockBuilder(\Drupal\testing_example\Controller\ContrivedCont
         roller::class)->disableOriginalConstructor()"                          
                                                                                
         Look at                                                                
         vendor/palantirnet/drupal-rector/src/Rector/Deprecation/Base/GetMockBas
         e.php:47".    

Drupal check gives me this:

219/219 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ ------------------------------------------------------------- 
  Line   stream_wrapper_example/tests/src/Unit/SessionHelperTest.php  
 ------ ------------------------------------------------------------- 
  52     Call to deprecated method assertInternalType() of class      
         PHPUnit\Framework\Assert:                                    
         https://github.com/sebastianbergmann/phpunit/issues/3369     
 ------ ------------------------------------------------------------- 

 [ERROR] Found 1 error   
jungle’s picture

Status: Needs work » Needs review

Thanks, @VladimirAus! But I think #24 is out of scope here.

vladimiraus’s picture

You are right @jungle. I was thinking about one issue and reporting another.

pratik_kamble’s picture

Assigned: Unassigned » pratik_kamble
vladimiraus’s picture

Status: Needs review » Reviewed & tested by the community

* All references for WebTestBase are removed.
* No dependencies on removed tests found.

  • jungle committed d967e13 on 3.x
    Issue #3072419 by darkdim, andypost, jungle, Mile23, VladimirAus,...

  • jungle committed 091599f on 8.x-1.x
    Issue #3072419 by darkdim, andypost, jungle, Mile23, VladimirAus,...
jungle’s picture

Status: Reviewed & tested by the community » Fixed

Thanks @VladimirAus!

  • jungle committed e9a7a96 on 8.x-1.x
    Revert "Issue #3072419 by darkdim, andypost, jungle, Mile23, VladimirAus...
jungle’s picture

After discussed with @valthebald on slack. We decided to keep WTB tests in 8.x-1.x as examples still, so reverted the commit.

pratik_kamble’s picture

Assigned: pratik_kamble » Unassigned

Status: Fixed » Closed (fixed)

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