Follow-up for #3041908: Drupal 9 Deprecated Code Report and #3037233: Replace deprectated UITestBase in CToolsViewsBasicViewBlockTest

for file_unmanaged_copy and .

------ ---------------------------------------------------------------------------------------------------------------------------------------------------
  Line   src/Tests/Wizard/CToolsWizardTest.php
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\Tests\ctools\Functional\CToolsWizardTest was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ ------------------------------


 ------ ----------------------------------------------------------------------------------------- 
  Line   modules/ctools_views/tests/src/Functional/CToolsViewsBasicViewBlockTest.php              
 ------ ----------------------------------------------------------------------------------------- 
  158    Call to deprecated method assertText() of class Drupal\Tests\BrowserTestBase.            
  159    Call to deprecated method assertText() of class Drupal\Tests\BrowserTestBase.            
  318    Call to deprecated method assertNoFieldByXPath() of class Drupal\Tests\BrowserTestBase.  
  319    Call to deprecated method assertNoFieldByXPath() of class Drupal\Tests\BrowserTestBase.  
 ------ ----------------------------------------------------------------------------------------- 

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joelpittet created an issue. See original summary.

joelpittet’s picture

Status: Active » Needs review
FileSize
1.77 KB

Status: Needs review » Needs work

The last submitted patch, 2: 3047026-2.patch, failed testing. View results

joelpittet’s picture

Issue tags: +Novice, +Seattle2019
mglaman’s picture

Just verifying: this was a test which existed, had a correct namespace but bad placement. This test is now having failures. And by the failures it is OK on PHP7 but not PHP5. This file was never discovered or autoloaded.

joelpittet’s picture

That's what I gathered from the result, haven't dug into it yet though.

thalles’s picture

Issue summary: View changes
thalles’s picture

Status: Needs work » Needs review
FileSize
2.54 KB
1000 bytes

Follow a new patch with modifications on tests

Status: Needs review » Needs work

The last submitted patch, 8: ctools-Drupal_9_Deprecated_Code-3047026-8-D8.patch, failed testing. View results

thalles’s picture

Status: Needs work » Needs review
joelpittet’s picture

Thanks again @thalles.

Can you explain why this was needing to change?

-    $this->assertText('Page 1');
-    $this->assertText('Next ›');
+    $this->assertTextHelper('Page 1', FALSE);
+    $this->assertTextHelper('Next ›', FALSE);

Did the content type give a false positive or something?

thalles’s picture

I do not remember well, but if I'm not mistaken I went to the class and looked where it was redirecting

thalles’s picture

Follow a new patch!

You're right:

  /**
   * Passes if the page (with HTML stripped) contains the text.
   *
   * Note that stripping HTML tags also removes their attributes, such as
   * the values of text fields.
   *
   * @param string $text
   *   Plain text to look for.
   *
   * @deprecated Scheduled for removal in Drupal 9.0.0.
   *   Use instead:
   *     - $this->assertSession()->responseContains() for non-HTML responses,
   *       like XML or Json.
   *     - $this->assertSession()->pageTextContains() for HTML responses. Unlike
   *       the deprecated assertText(), the passed text should be HTML decoded,
   *       exactly as a human sees it in the browser.
   */
  protected function assertText($text) {
    // Cast MarkupInterface to string.
    $text = (string) $text;

    $content_type = $this->getSession()->getResponseHeader('Content-type');
    // In case of a Non-HTML response (example: XML) check the original
    // response.
    if (strpos($content_type, 'html') === FALSE) {
      $this->assertSession()->responseContains($text);
    }
    else {
      $this->assertTextHelper($text, FALSE);
    }
  }

Status: Needs review » Needs work
thalles’s picture

Status: Needs work » Needs review
mglaman’s picture

+++ b/modules/ctools_block/tests/src/Functional/EntityFieldBlockTest.php
@@ -45,7 +45,10 @@ class EntityFieldBlockTest extends BrowserTestBase {
+    /** @var \Drupal\Core\File\FileSystemInterface $file_system */
+    $file_system = \Drupal::service('file_system');
+    $file_system->copy($source, 'public://sample.png');

In the tests we have access to the container. You should be able to do

$this->container->get('file_system')

Instead of reaching into the static class.

thalles’s picture

Status: Needs review » Needs work
thalles’s picture

Status: Needs work » Needs review
mglaman’s picture

Status: Needs review » Reviewed & tested by the community

I'm going to go ahead and mark that as a big ole RTBC!

+++ b/modules/ctools_block/tests/src/Functional/EntityFieldBlockTest.php
@@ -44,20 +44,22 @@ class EntityFieldBlockTest extends BrowserTestBase {
+    $entityTypeManager = $this->container->get('entity_type.manager');
+    $source = $this->container->get('module_handler')->getModule('image')->getPath() . '/sample.png';
...
+    $file_system = $this->container->get('file_system');

🎉🙌

+++ b/modules/ctools_block/tests/src/Functional/EntityFieldBlockTest.php
@@ -44,20 +44,22 @@ class EntityFieldBlockTest extends BrowserTestBase {
+    $source = $this->container->get('module_handler')->getModule('image')->getPath() . '/sample.png';

This is kind of long, but in tests I generally am more lax about long chains.

  • joelpittet committed 75499f0 on 8.x-3.x authored by thalles
    Issue #3047026 by thalles, joelpittet, mglaman: Drupal 9 Deprecated Code
    
joelpittet’s picture

Status: Reviewed & tested by the community » Fixed

Thanks committed to the latest dev branch.

Status: Fixed » Closed (fixed)

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