drupal-check against redirect-8.x-1.x-dev (6 Jan 2019)

 ------ ------------------------------------------------------- 
  Line     redirect.module                                                     
 ------ ------------------------------------------------------- 
  176    Call to deprecated function drupal_get_destination().  
  180    Call to deprecated function drupal_get_destination().  
  217    Call to deprecated function db_or().                   
 ------ ------------------------------------------------------- 

 ------ -------------------------------------------------------- 
  Line   modules/redirect_404/src/Controller/Fix404IgnoreController.php  
 ------ -------------------------------------------------------- 
  70     Call to deprecated function drupal_set_message().       
 ------ -------------------------------------------------------- 

 ------ --------------------------------------------------------- 
  Line   modules/redirect_404/src/Tests/Redirect404LogSuppressorTest.php  
 ------ --------------------------------------------------------- 
  59     Call to deprecated function db_query().                  
  60     Call to deprecated function db_query().                  
  76     Call to deprecated function db_query().                  
  77     Call to deprecated function db_query().                  
 ------ --------------------------------------------------------- 

 ------ ------------------------------------------------------------- 
  Line   modules/redirect_404/tests/src/Kernel/Fix404RedirectCronJobTest.php  
 ------ ------------------------------------------------------------- 
  48     Call to deprecated function db_query().                      
  54     Call to deprecated function db_query().                      
  88     Call to deprecated function db_query().                      
  94     Call to deprecated function db_query().                      
  130    Call to deprecated function db_insert().                     
  177    Call to deprecated function db_select().                     
 ------ ------------------------------------------------------------- 

 ------ --------------------------------------------------- 
  Line   modules/redirect_domain/src/Form/RedirectDomainForm.php    
 ------ --------------------------------------------------- 
  163    Call to deprecated function drupal_set_message().  
 ------ --------------------------------------------------- 

 ------ ------------------------------------------------------------------------- 
  Line   modules/redirect_domain/tests/src/Unit/DomainRedirectRequestSubscriberTest.php   
 ------ ------------------------------------------------------------------------- 
  78     Call to deprecated method getMock() of class Drupal\Tests\UnitTestCase.  
 ------ ------------------------------------------------------------------------- 

 ------ --------------------------------------------- 
  Line   src/Exception/RedirectLoopException.php                    
 ------ --------------------------------------------- 
  21     Call to deprecated method format() of class  
         Drupal\Component\Utility\SafeMarkup.         
  21     Call to method format() of deprecated class  
         Drupal\Component\Utility\SafeMarkup.         
 ------ --------------------------------------------- 

 ------ --------------------------------------------------- 
  Line   src/Form/RedirectDeleteForm.php                             
 ------ --------------------------------------------------- 
  37     Call to deprecated function drupal_set_message().  
 ------ --------------------------------------------------- 

 ------ --------------------------------------------------- 
  Line   src/Form/RedirectDeleteMultipleForm.php                     
 ------ --------------------------------------------------- 
  135    Call to deprecated function drupal_set_message().  
 ------ --------------------------------------------------- 

 ------ ------------------------------------------------------------ 
  Line   src/Form/RedirectForm.php                                            
 ------ ------------------------------------------------------------ 
  53     Call to deprecated function drupal_set_message().           
  129    Call to deprecated method entityManager() of class Drupal.  
  139    Call to deprecated method url() of class                    
         Drupal\Core\Entity\EntityInterface.                         
  149    Call to deprecated function drupal_set_message().           
 ------ ------------------------------------------------------------ 

 ------ --------------------------------------------------- 
  Line   src/Form/RedirectSettingsForm.php                           
 ------ --------------------------------------------------- 
  90     Call to deprecated function drupal_set_message().  
 ------ --------------------------------------------------- 

 ------ --------------------------------------------------------------------- 
  Line   src/Plugin/Field/FieldWidget/RedirectSourceWidget.php                                 
 ------ --------------------------------------------------------------------- 
  83     Call to deprecated method url() of class Drupal\Core\Entity\Entity.  
 ------ --------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------ 
  Line   src/Tests/AssertRedirectTrait.php (in context of class Drupal\redirect\Tests\RedirectUITest)  
 ------ ------------------------------------------------------------------------------------ 
  29     Call to deprecated method format() of class                                         
         Drupal\Component\Utility\SafeMarkup.                                                
  29     Call to method format() of deprecated class                                         
         Drupal\Component\Utility\SafeMarkup.                                                
 ------ ------------------------------------------------------------------------------------ 

 ------ ---------------------------------------------- 
  Line   src/Tests/GlobalRedirectTest.php                        
 ------ ---------------------------------------------- 
  105    Call to deprecated function entity_create().  
  114    Call to deprecated function entity_create().  
  120    Call to deprecated function entity_create().  
  255    Call to deprecated method format() of class   
         Drupal\Component\Utility\SafeMarkup.          
  255    Call to method format() of deprecated class   
         Drupal\Component\Utility\SafeMarkup.          
 ------ ---------------------------------------------- 

 ------ --------------------------------------------------------------------- 
  Line   src/Tests/RedirectUITest.php                                                   
 ------ --------------------------------------------------------------------- 
  126    Call to deprecated method url() of class Drupal\Core\Entity\Entity.  
  142    Call to deprecated method url() of class Drupal\Core\Entity\Entity.  
  339    Call to deprecated function db_select().                             
  346    Call to deprecated method format() of class                          
         Drupal\Component\Utility\SafeMarkup.                                 
  346    Call to method format() of deprecated class                          
         Drupal\Component\Utility\SafeMarkup.                                 
  347    Call to deprecated method format() of class                          
         Drupal\Component\Utility\SafeMarkup.                                 
  347    Call to method format() of deprecated class                          
         Drupal\Component\Utility\SafeMarkup.                                 
  356    Call to deprecated function entity_create().                         
  373    Call to deprecated function entity_create().                         
 ------ --------------------------------------------------------------------- 

 ------ ---------------------------------------------------------- 
  Line   tests/src/Kernel/Migrate/d6/PathRedirectTest.php                
 ------ ---------------------------------------------------------- 
  40     Call to deprecated method lookupDestinationId() of class  
         Drupal\migrate\Plugin\MigrateIdMapInterface.              
 ------ ---------------------------------------------------------- 

 ------ ---------------------------------------------------------- 
  Line   tests/src/Kernel/Migrate/d7/PathRedirectTest.php                
 ------ ---------------------------------------------------------- 
  52     Call to deprecated method lookupDestinationId() of class  
         Drupal\migrate\Plugin\MigrateIdMapInterface.              
 ------ ---------------------------------------------------------- 

 ------ ------------------------------------------------------ 
  Line   tests/src/Kernel/RedirectAPITest.php                        
 ------ ------------------------------------------------------ 
  63     Call to deprecated method assertEqual() of class      
         Drupal\KernelTests\KernelTestBase.                    
  68     Call to deprecated method assertEqual() of class      
         Drupal\KernelTests\KernelTestBase.                    
  73     Call to deprecated method assertEqual() of class      
         Drupal\KernelTests\KernelTestBase.                    
  84     Call to deprecated method assertEqual() of class      
         Drupal\KernelTests\KernelTestBase.                    
  94     Call to deprecated method assertEqual() of class      
         Drupal\KernelTests\KernelTestBase.                    
  107    Call to deprecated method assertEqual() of class      
         Drupal\KernelTests\KernelTestBase.                    
  122    Call to deprecated method assertEqual() of class      
         Drupal\KernelTests\KernelTestBase.                    
  135    Call to deprecated method assertEqual() of class      
         Drupal\KernelTests\KernelTestBase.                    
  150    Call to deprecated method assertEqual() of class      
         Drupal\KernelTests\KernelTestBase.                    
  157    Call to deprecated method assertEqual() of class      
         Drupal\KernelTests\KernelTestBase.                    
  195    Call to deprecated method assertIdentical() of class  
         Drupal\KernelTests\KernelTestBase.                    
  224    Call to deprecated method assertEqual() of class      
         Drupal\KernelTests\KernelTestBase.                    
  238    Call to deprecated method pass() of class             
         Drupal\KernelTests\KernelTestBase.                    
  284    Call to deprecated method assertEqual() of class      
         Drupal\KernelTests\KernelTestBase.                    
  285    Call to deprecated method assertEqual() of class      
         Drupal\KernelTests\KernelTestBase.                    
  297    Call to deprecated method assertEqual() of class      
         Drupal\KernelTests\KernelTestBase.                    
  298    Call to deprecated method assertEqual() of class      
         Drupal\KernelTests\KernelTestBase.                    
 ------ ------------------------------------------------------ 

 ------ ---------------------------------------------------------------------- 
  Line   tests/src/Unit/Migrate/d7/PathRedirectTest.php                              
 ------ ---------------------------------------------------------------------- 
  12     Class Drupal\Tests\redirect\Unit\Migrate\d7\PathRedirectTest extends  
         deprecated class Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase.  
  51     Call to method setUp() of deprecated class                            
         Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase.                   
 ------ ---------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------- 
  Line   tests/src/Unit/RedirectRequestSubscriberTest.php                               
 ------ ------------------------------------------------------------------------- 
  139    Call to deprecated method getMock() of class Drupal\Tests\UnitTestCase.  
 ------ ------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------- 
  Line   tests/src/Unit/RouteNormalizerRequestSubscriberTest.php                        
 ------ ------------------------------------------------------------------------- 
  27     Call to deprecated method getMock() of class Drupal\Tests\UnitTestCase.  
 ------ ------------------------------------------------------------------------- 

                                                                                                                                                                                      

Comments

waverate created an issue. See original summary.

sinn’s picture

Assigned: Unassigned » sinn
sinn’s picture

Status: Active » Needs review
Issue tags: +DrupalCampBelarus2019
StatusFileSize
new37.14 KB
sinn’s picture

All deprecations are in one place. Including deprecations from D8.7.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/modules/redirect_404/tests/src/Kernel/Fix404RedirectCronJobTest.php
    @@ -174,7 +175,7 @@ class Fix404RedirectCronJobTest extends KernelTestBase {
       protected function assert404RowHelper($path, $langcode = 'en', $not_exists = TRUE) {
    -    $result = db_select('redirect_404', 'r404')
    +    $result = Database::getConnection()->select('redirect_404', 'r404')
           ->fields('r404', ['path'])
    

    I'd rather use \Drupal::database()

  2. +++ b/redirect.generate.inc
    @@ -165,13 +166,18 @@ function redirect_generate_batch_generate($num, array &$context) {
         // An error occurred.
         // $operations contains the operations that remained unprocessed.
         $error_operation = reset($operations);
    -    drupal_set_message(t('An error occurred while processing @operation with arguments : @args', ['@operation' => $error_operation[0], '@args' => print_r($error_operation[0], TRUE)]));
    +      \Drupal::messenger()
    +        ->addMessage(t('An error occurred while processing @operation with arguments : @args', [
    +          '@operation' => $error_operation[0],
    +          '@args' => print_r($error_operation[0], TRUE),
    +        ]));
       }
     }
     
    diff --git a/redirect.install b/redirect.install
    

    Incorrect indentation, should start on the same level as before, I'd also prefer to keep it on a single level, easier to see what changed.

  3. +++ b/src/Tests/GlobalRedirectTest.php
    @@ -102,7 +102,7 @@ class GlobalRedirectTest extends WebTestBase {
         // Create a taxonomy term for the forum.
    -    $term = entity_create('taxonomy_term', [
    +    $term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->create([
           'name' => 'Test Forum Term',
           'vid' => 'forums',
    

    this conflicts with a patch that I just committed, that used Term::load()/Vocabulary::load(), which is fine too, so these parts should be removed from the patch.

Didn't spot any 8.7 specific deprecations, on the next reroll, please run a test with 8.7 and 8.6, so we can see if it fails on 8.6. If that's the case, then committing this needs to be postponed to when 8.6 is no longer supported.

berdir’s picture

The messenger changes have been separately committed as well now, so that's another thing that can be removed in the reroll.

berdir’s picture

We could maybe also keep this as a meta issue and do separate issues for the patches.. there will likely be more deprecations before D9 is out. There was one for db functions that I closed as a duplicate, we could reopen that or create a new one. Still not quite sure how to handle these issues.

karan_mudi’s picture

StatusFileSize
new35.73 KB

Attached patch for above issues.

karan_mudi’s picture

karan_mudi’s picture

karan_mudi’s picture

StatusFileSize
new36.02 KB
dieterholvoet’s picture

- fixed the indentation on the addMessage call
- removed the xdebug_break call

berdir’s picture

Status: Needs work » Needs review
berdir’s picture

Status: Needs review » Needs work
  1. +++ b/redirect.generate.inc
    @@ -165,13 +166,18 @@ function redirect_generate_batch_generate($num, array &$context) {
     function redirect_generate_batch_finished($success, $results, $operations) {
       if ($success) {
    -    \Drupal::messenger()->addMessage(\Drupal::translation()->formatPlural(count($results), 'One URL redirect created.', '@count URL redirects created.'));
    +    \Drupal::messenger()->addMessage(\Drupal::translation()
    +      ->formatPlural(count($results), 'One URL redirect created.', '@count URL redirects created.'));
       }
       else {
         // An error occurred.
         // $operations contains the operations that remained unprocessed.
         $error_operation = reset($operations);
    -    \Drupal::messenger()->addMessage(t('An error occurred while processing @operation with arguments : @args', ['@operation' => $error_operation[0], '@args' => print_r($error_operation[0], TRUE)]));
    +    \Drupal::messenger()
    +      ->addMessage(t('An error occurred while processing @operation with arguments : @args', [
    +        '@operation' => $error_operation[0],
    +        '@args' => print_r($error_operation[0], TRUE),
    +      ]));
       }
     }
     
    

    These changes are unrelated, the messenger conversion already happened and we shouldn't make unrelated coding standard changes here.

  2. +++ b/src/Form/RedirectSettingsForm.php
    @@ -87,7 +87,7 @@ class RedirectSettingsForm extends ConfigFormBase {
         }
         $config->save();
    -    parent::submitForm($form, $form_state);
    +    $this->messenger()->addMessage($this->t('Configuration was saved.'));
       }
    

    this too is an unnecessary change, the existing code is fine.

  3. +++ b/src/Tests/GlobalRedirectTest.php
    @@ -104,7 +104,7 @@ class GlobalRedirectTest extends WebTestBase {
     
         // Create a taxonomy term for the forum.
    -    $term = Term::create([
    +    $term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->create([
           'name' => 'Test Forum Term',
    

    Same, one can argue over better DI, but the calls here for Term:: and Vocabulary:: are not deprecated and don't need to be changed anymore.

  4. +++ b/tests/src/Functional/RedirectUITest.php
    @@ -179,7 +178,7 @@ class RedirectUITest extends BrowserTestBase {
       function createVocabulary() {
         // Create a vocabulary.
    -    $vocabulary = Vocabulary::create([
    +    $vocabulary = \Drupal::entityTypeManager()->getStorage('taxonomy_vocabulary')->create([
           'name' => $this->randomMachineName(),
           'description' => $this->randomMachineName(),
           'vid' => mb_strtolower($this->randomMachineName()),
    @@ -196,7 +195,7 @@ class RedirectUITest extends BrowserTestBase {
    
    @@ -196,7 +195,7 @@ class RedirectUITest extends BrowserTestBase {
       function createTerm($vocabulary) {
         $filter_formats = filter_formats();
         $format = array_pop($filter_formats);
    -    $term = Term::create([
    +    $term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->create([
           'name' => $this->randomMachineName(),
    

    same.

  5. +++ b/tests/src/FunctionalJavascript/RedirectJavascriptTest.php
    @@ -130,7 +130,7 @@ class RedirectJavascriptTest extends WebDriverTestBase {
           t(
             'The base source path %source is already being redirected. Do you want to <a href="@edit-page">edit the existing redirect</a>?',
    -        ['%source' => 'non-existing?key=value', '@edit-page' => $redirect->url('edit-form')]
    +        ['%source' => 'non-existing?key=value', '@edit-page' => $redirect->toUrl('edit-form')]
           )
    

    missing a toString()

  6. +++ b/tests/src/FunctionalJavascript/RedirectJavascriptTest.php
    @@ -157,7 +157,7 @@ class RedirectJavascriptTest extends WebDriverTestBase {
             'The source path %source is already being redirected. Do you want to <a href="@edit-page">edit the existing redirect</a>?',
    -        ['%source' => 'non-existing?key=value', '@edit-page' => $redirect->url('edit-form')]
    +        ['%source' => 'non-existing?key=value', '@edit-page' => $redirect->toUrl('edit-form')]
           )
         );
     
    diff --git a/tests/src/Kernel/Migrate/d6/PathRedirectTest.php b/tests/src/Kernel/Migrate/d6/PathRedirectTest.php
    

    here too.

  7. +++ b/tests/src/Kernel/RedirectAPITest.php
    @@ -60,17 +59,17 @@ class RedirectAPITest extends KernelTestBase {
         $redirect->save();
    -    $this->assertEqual(Redirect::generateHash('some-url', ['key1' => 'val1'], Language::LANGCODE_NOT_SPECIFIED), $redirect->getHash());
    +    $this->assertEquals(Redirect::generateHash('some-url', ['key1' => 'val1'], Language::LANGCODE_NOT_SPECIFIED), $redirect->getHash());
         // Update the redirect source path and check if hash has been updated as
    

    the order arguments between assertEqual() and assertEquals() changes, the expected value should be first. Also I think there might be an existing issue for this, if that is correct then lets remove these changes here, it's not strictly required for D9 anyway.

When picking up large patches, it's really important to provide interdiffs, so that it's possible to see what exactly has changed.

berdir’s picture

Also, running drupal-check with the patch applied gives:

 ------ ---------------------------------------------------------------- 
  Line   redirect.drush.inc                                              
 ------ ---------------------------------------------------------------- 
  56     Call to deprecated function drupal_set_time_limit():            
         in drupal:8.7.0 and is removed from drupal:9.0.0. Use           
         \Drupal\Component\Utility\Environment::setTimeLimit() instead.  
 ------ ---------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------------------------- 
  Line   src/Tests/GlobalRedirectTest.php                                                                        
 ------ -------------------------------------------------------------------------------------------------------- 
  17     Class Drupal\redirect\Tests\GlobalRedirectTest extends deprecated class Drupal\simpletest\WebTestBase:  
         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.                             
  69     Call to method setUp() of deprecated class Drupal\simpletest\WebTestBase:                               
         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.                             
 ------ -------------------------------------------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------------------------------------------- 
  Line   tests/src/Unit/Migrate/d7/PathRedirectTest.php                                                            
 ------ ---------------------------------------------------------------------------------------------------------- 
         Class Drupal\Tests\redirect\Unit\Migrate\d7\MigrateSourceTestBase not found and could not be autoloaded.  
 ------ ---------------------------------------------------------------------------------------------------------- 

The remaining simpletest should be ignored here, there is a separate issue and it's really hard.

But something is strange with the unit test base class, and there's also a time limit call to fix.

And we should include the core_version_requirement key, see https://www.drupal.org/node/3070687. Lets require ^8.7.7 || ^9. And make sure to to it in all info.yml files in the project. In turn, you can remove the drupal:system dependency.

berdir’s picture

Also, there are still quite a few entityManager references, that needs to be updated too.

gmangones’s picture

Status: Needs work » Needs review
StatusFileSize
new37.78 KB
new37.78 KB

Hi, Running drupal-check with the patch and applying the suggested.

Now display the following.

Line   tests/src/Unit/Migrate/d7/PathRedirectTest.php                                                            
 ------ ---------------------------------------------------------------------------------------------------------- 
         Class Drupal\Tests\redirect\Unit\Migrate\d7\MigrateSourceTestBase not found and could not be autoloaded.

Thank's

berdir’s picture

Status: Needs review » Needs work

That interdiff seems to be identical to the full patch.

  1. +++ b/redirect.drush.inc
    @@ -27,12 +27,13 @@ function redirect_drush_command() {
      * Command callback. Generate a number of redirects.
      */
     function drush_redirect_generate_redirects($count = NULL) {
    +  $options = [];
       if (drush_generate_is_number($count) == FALSE) {
         return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', t('Invalid number of redirects.'));
       }
       module_load_include('inc', 'redirect', 'redirect.generate');
       drush_generate_include_devel();
    -  redirect_run_unprogressive_batch('redirect_generate_redirects_batch_info', $count, drush_get_option('delete'));
    +  redirect_run_unprogressive_batch('redirect_generate_redirects_batch_info', $count, $options['delete']);
     }
     
    

    this is not correct, $options doesn't do anything. This should not be changed here, it is deprecated by drush, not by Drupal core. And the whole file is for Drush 8 and needs to use Drush 8 API.

  2. +++ b/redirect.generate.inc
    @@ -165,13 +166,18 @@ function redirect_generate_batch_generate($num, array &$context) {
       if ($success) {
    -    \Drupal::messenger()->addMessage(\Drupal::translation()->formatPlural(count($results), 'One URL redirect created.', '@count URL redirects created.'));
    +    \Drupal::messenger()->addMessage(\Drupal::translation()
    +      ->formatPlural(count($results), 'One URL redirect created.', '@count URL redirects created.'));
       }
       else {
         // An error occurred.
         // $operations contains the operations that remained unprocessed.
         $error_operation = reset($operations);
    -    \Drupal::messenger()->addMessage(t('An error occurred while processing @operation with arguments : @args', ['@operation' => $error_operation[0], '@args' => print_r($error_operation[0], TRUE)]));
    +    \Drupal::messenger()
    +      ->addMessage(t('An error occurred while processing @operation with arguments : @args', [
    +        '@operation' => $error_operation[0],
    +        '@args' => print_r($error_operation[0], TRUE),
    +      ]));
    

    Still has unrelated messenger changes. No need to change these lines here.

  3. +++ b/redirect.info.yml
    @@ -2,6 +2,7 @@ name: Redirect
     description: Allows users to redirect from old URLs to new URLs.
     core: 8.x
    +core_version_requirement: ^8.7.10 || ^9
     configure: redirect.settings
     
    

    Should be ^8.7.7 as I wrote. Users should update to the the latest 8.7 version, but 8.7.7 is the lowest-supported version that we can specify, so lets use that.

  4. +++ b/redirect.install
    @@ -68,10 +68,10 @@ function redirect_update_8101() {
       // Update the last installed field definition and field schema.
       /** @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface $key_value_store */
    -  \Drupal::entityManager()->clearCachedFieldDefinitions();
    +  \Drupal::entityTypeManager()->clearCachedFieldDefinitions();
       $key_value_store_definition = \Drupal::keyValue('entity.definitions.installed');
       $storage_definitions = $key_value_store_definition->get('redirect.field_storage_definitions');
    -  $storage_definitions['hash'] = $storage_definition = \Drupal::entityManager()
    +  $storage_definitions['hash'] = $storage_definition = \Drupal::entityTypeManager()
         ->getFieldStorageDefinitions('redirect')['hash'];
       $key_value_store_definition->set('redirect.field_storage_definitions', $storage_definitions);
    

    this is not correct, should use the entity_field.manager service.

  5. +++ b/src/Form/RedirectSettingsForm.php
    @@ -87,7 +87,7 @@ class RedirectSettingsForm extends ConfigFormBase {
         $config->save();
    -    parent::submitForm($form, $form_state);
    +    $this->messenger()->addMessage($this->t('Configuration was saved.'));
       }
     
     }
    

    also wrong change.

  6. +++ b/src/Tests/GlobalRedirectTest.php
    @@ -2,9 +2,10 @@
     use Drupal\language\Entity\ConfigurableLanguage;
     use Drupal\taxonomy\Entity\Term;
     use Drupal\taxonomy\Entity\Vocabulary;
    @@ -14,7 +15,7 @@ use Drupal\taxonomy\Entity\Vocabulary;
    
    @@ -14,7 +15,7 @@ use Drupal\taxonomy\Entity\Vocabulary;
      *
      * @group redirect
      */
    -class GlobalRedirectTest extends WebTestBase {
    +class GlobalRedirectTest extends BrowserTestBase {
     
       /**
    

    Also wrong, this is still a web test, and converting it is complicated and shouldn't be done here.

    All changes in this file except the SafeMarkup should be reverted.

  7. +++ b/tests/src/Functional/AssertRedirectTrait.php
    @@ -37,11 +38,12 @@ trait AssertRedirectTrait {
    -    $this->assertEquals($expected_ending_status, $response->getStatusCode());
    -
    -    $ending_url = $response->getHeader('location');
    -    $ending_url = $ending_url ? $ending_url[0] : NULL;
    -    $message = "Testing redirect from $path to $expected_ending_url. Ending url: $ending_url";
    +    $ending_url = isset($headers[0]['location']) ? $headers[0]['location'] : NULL;
    +    $message = new FormattableMarkup('Testing redirect from %from to %to. Ending url: %url', [
    +      '%from' => $path,
    +      '%to' => $expected_ending_url,
    +      '%url' => $ending_url,
    +    ]);
     
    

    wrong change, was somehow merged with an old version.

  8. +++ b/tests/src/Functional/RedirectUITest.php
    @@ -179,7 +178,7 @@ class RedirectUITest extends BrowserTestBase {
         // Create a vocabulary.
    -    $vocabulary = Vocabulary::create([
    +    $vocabulary = \Drupal::entityTypeManager()->getStorage('taxonomy_vocabulary')->create([
           'name' => $this->randomMachineName(),
           'description' => $this->randomMachineName(),
           'vid' => mb_strtolower($this->randomMachineName()),
    @@ -196,7 +195,7 @@ class RedirectUITest extends BrowserTestBase {
    
    @@ -196,7 +195,7 @@ class RedirectUITest extends BrowserTestBase {
       function createTerm($vocabulary) {
         $filter_formats = filter_formats();
         $format = array_pop($filter_formats);
    -    $term = Term::create([
    +    $term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->create([
    

    unecessary.

  9. +++ b/tests/src/FunctionalJavascript/RedirectJavascriptTest.php
    @@ -130,7 +130,7 @@ class RedirectJavascriptTest extends WebDriverTestBase {
             'The base source path %source is already being redirected. Do you want to <a href="@edit-page">edit the existing redirect</a>?',
    -        ['%source' => 'non-existing?key=value', '@edit-page' => $redirect->url('edit-form')]
    +        ['%source' => 'non-existing?key=value', '@edit-page' => $redirect->toUrl('edit-form')]
           )
         );
     
    @@ -157,7 +157,7 @@ class RedirectJavascriptTest extends WebDriverTestBase {
    
    @@ -157,7 +157,7 @@ class RedirectJavascriptTest extends WebDriverTestBase {
         $this->assertRaw(
           t(
             'The source path %source is already being redirected. Do you want to <a href="@edit-page">edit the existing redirect</a>?',
    -        ['%source' => 'non-existing?key=value', '@edit-page' => $redirect->url('edit-form')]
    +        ['%source' => 'non-existing?key=value', '@edit-page' => $redirect->toUrl('edit-form')]
           )
         );
     
    

    still missing a toString()

And yes, the migrate test is also string wrong, which breaks tests completely.

berdir’s picture

I think it might be easier to start from scratch as there's probably more wrong/unnecessary in this patch than right at this point.

Also, it might make sense to split up another issue with the easy conversions like db_query(), SafeMarkup and url changes. leaving the hairy ones for later, where we can focus on them.

gmangones’s picture

Status: Needs work » Needs review
StatusFileSize
new36.79 KB
new1.62 KB

I started again from comment #13. Applied this patch and applied some changes only about ```drupal_set_time_limit function``` deprecated ```Drupal\simpletest\WebTestBase```.
Fix interdiff as well.
Need work about:

------ ------------------------------------------------- 
  Line   redirect.drush.inc                               
 ------ ------------------------------------------------- 
  35     Call to deprecated function drush_get_option().  
 ------ ------------------------------------------------- 

Thank's

berdir’s picture

Status: Needs review » Needs work

See my review in #15, plenty of things aren't correct in #13 either.

gmangones’s picture

Status: Needs work » Needs review
StatusFileSize
new33.65 KB
new5.96 KB

Hi @Berdir,

Thank you for your corrections. So, Following your suggestions, I left it as it was and re-created the patch again with a new additions fixing the errors displayed after to run drupal-check command.

------ ---------------------------------------------------------------- 
  Line   redirect.drush.inc                                              
 ------ ---------------------------------------------------------------- 
  56     Call to deprecated function drupal_set_time_limit():            
         in drupal:8.7.0 and is removed from drupal:9.0.0. Use           
         \Drupal\Component\Utility\Environment::setTimeLimit() instead.  
 ------ ---------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------------------------- 
  Line   src/Tests/GlobalRedirectTest.php                                                                        
 ------ -------------------------------------------------------------------------------------------------------- 
  17     Class Drupal\redirect\Tests\GlobalRedirectTest extends deprecated class Drupal\simpletest\WebTestBase:  
         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.                             
  69     Call to method setUp() of deprecated class Drupal\simpletest\WebTestBase:                               
         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.

Thanks

berdir’s picture

Status: Needs review » Needs work

Thanks, this is looking much better, now we're moving into the right direction.

  1. +++ b/redirect.install
    @@ -68,10 +68,10 @@ function redirect_update_8101() {
       // Update the last installed field definition and field schema.
       /** @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface $key_value_store */
    -  \Drupal::entityManager()->clearCachedFieldDefinitions();
    +  \Drupal::entityTypeManager()->clearCachedFieldDefinitions();
       $key_value_store_definition = \Drupal::keyValue('entity.definitions.installed');
       $storage_definitions = $key_value_store_definition->get('redirect.field_storage_definitions');
    -  $storage_definitions['hash'] = $storage_definition = \Drupal::entityManager()
    +  $storage_definitions['hash'] = $storage_definition = \Drupal::entityTypeManager()
         ->getFieldStorageDefinitions('redirect')['hash'];
       $key_value_store_definition->set('redirect.field_storage_definitions', $storage_definitions);
    

    clearCachedFieldDefinitions() and getFieldStorageDefinitions() needs to be called on entity_field.manager.

  2. +++ b/src/Form/RedirectDeleteForm.php
    @@ -34,7 +34,11 @@ class RedirectDeleteForm extends ContentEntityConfirmFormBase {
         $this->entity->delete();
    -    $this->messenger()->addMessage($this->t('The redirect %redirect has been deleted.', ['%redirect' => $this->entity->getRedirectUrl()->toString()]));
    +    $this->messenger()
    +      ->addMessage($this->t('The redirect %redirect has been deleted.', [
    +        '%redirect' => $this->entity->getRedirectUrl()
    +          ->toString(),
    +      ]));
         $form_state->setRedirect('redirect.list');
    

    Another one to undo.

  3. +++ b/src/Tests/GlobalRedirectTest.php
    @@ -14,7 +14,7 @@ use Drupal\taxonomy\Entity\Vocabulary;
      * @group redirect
      */
    -class GlobalRedirectTest extends WebTestBase {
    +class GlobalRedirectTest extends BrowserTestBase {
     
    

    This is a really hard test to convert with a dedicated issue, the only change in here should be the SafeMarkup change.

  4. +++ b/tests/src/Functional/AssertRedirectTrait.php
    @@ -37,11 +38,12 @@ trait AssertRedirectTrait {
    -    $this->assertEquals($expected_ending_status, $response->getStatusCode());
    -
    -    $ending_url = $response->getHeader('location');
    -    $ending_url = $ending_url ? $ending_url[0] : NULL;
    -    $message = "Testing redirect from $path to $expected_ending_url. Ending url: $ending_url";
    +    $ending_url = isset($headers[0]['location']) ? $headers[0]['location'] : NULL;
    +    $message = new FormattableMarkup('Testing redirect from %from to %to. Ending url: %url', [
    +      '%from' => $path,
    +      '%to' => $expected_ending_url,
    +      '%url' => $ending_url,
    +    ]);
    

    Changes to this file can also be completely reverted, we also updated that to not use SafeMarkup at all in another issue.

  5. +++ b/tests/src/Functional/RedirectUITest.php
    @@ -2,12 +2,11 @@
     use Drupal\Core\Logger\RfcLogLevel;
     use Drupal\Core\Url;
    -use Drupal\taxonomy\Entity\Term;
    -use Drupal\taxonomy\Entity\Vocabulary;
    +use Drupal\Core\Database\Database;
     use Drupal\Tests\BrowserTestBase;
    

    The use statements need to be kept.

  6. +++ b/tests/src/Functional/RedirectUITest.php
    @@ -162,15 +161,15 @@ class RedirectUITest extends BrowserTestBase {
           $this->assertEqual($log->severity, RfcLogLevel::WARNING);
    -      $this->assertEqual(SafeMarkup::format($log->message, unserialize($log->variables)),
    -        SafeMarkup::format('Redirect loop identified at %path for redirect %id', ['%path' => '/node', '%id' => $redirect1->id()]));
    +      $this->assertEqual(new FormattableMarkup($log->message, unserialize($log->variables)),
    +        new FormattableMarkup('Redirect loop identified at %path for redirect %id', ['%path' => '/node', '%id' => $redirect1->id()]));
         }
    

    Maybe we should just compare the message and the unserialized array directly instead of passing it to FormatableMarkup? With two separate assertEquals comparisons.

  7. +++ b/tests/src/Unit/Migrate/d7/PathRedirectTest.php
    @@ -2,14 +2,14 @@
     
     namespace Drupal\Tests\redirect\Unit\Migrate\d7;
     
    -use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
    +use Drupal\Core\Database\Driver\sqlite\Connection;
     
     /**
      * Tests D7 redirect source plugin.
      *
      * @group redirect
      */
    -class PathRedirectTest extends MigrateSqlSourceTestCase {
    +class PathRedirectTest extends MigrateSourceTestBase {
    

    the new use seems wrong, that's why tests are failing so hard.

    The new base class is a kernel test. That means we need to move this to the src/Kernel folder and update the namespace (and fix the use).

berdir’s picture

Assigned: sinn » berdir
berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new34.63 KB

Did that cleanup.

6. Did that change and realized the the logging was actually logging the message with replaced placeholders, so the assertion only worked because the result was the same. That's bad for translatability, fixed.

7. I'm pretty confused about those migrate tests, I'm not sure what this is exactly testing and why there's more than test class for D7 that seems to be testing the same thing.

quietone’s picture

Review the migrate changes here and all of it looks good to me. There is one small nit about the array key names in the unit test. In core they are as shown below and I am just used to them. Change if you think it is worth the time.

  1. +++ b/tests/src/Kernel/Migrate/d7/PathRedirectSourceTest.php
    @@ -0,0 +1,54 @@
    +    $tests[0][0]['variable'] = [
    ...
    +    $tests[0][0]['redirect'] = [
    

    Usually instead of $tests[0][0] it is $tests[0]['source_data']

  2. +++ b/tests/src/Kernel/Migrate/d7/PathRedirectSourceTest.php
    @@ -0,0 +1,54 @@
    +    $tests[0][1] = $tests[0][0]['redirect'];
    

    And there it is $tests[0]['expected_data']

berdir’s picture

Title: Drupal 9 Deprecated Code Report » Remove Drupal 8.7 and earlier deprecations, compatibility with Drupal 8
StatusFileSize
new50.48 KB
new19.56 KB

Thanks, addressed that and also a lot of additional deprecations that drupal-check doesn't find. Constants, injections, service calls.

The only thing left are 8.8 path alias deprecations, the hooks, PathAliasManager and a route in a test. Might be possible to address that while remaining 8.7 compatible but will consider that

Berdir credited arunkumark.

berdir’s picture

  • Berdir committed 2913123 on 8.x-1.x
    Issue #3051124 by gmangones, karan_mudi, Berdir, sinn, DieterHolvoet,...
berdir’s picture

Title: Remove Drupal 8.7 and earlier deprecations, compatibility with Drupal 8 » Remove Drupal 8.7 and earlier deprecations, compatibility with Drupal 9
Status: Needs review » Fixed

Committed.

gmangones’s picture

Great, thanks @Berdir.

mondrake’s picture

Hi

The only thing left are 8.8 path alias deprecations, the hooks, PathAliasManager and a route in a test. Might be possible to address that while remaining 8.7 compatible but will consider that

is there as issue for that already?

berdir’s picture

No

mondrake’s picture

OK, filed #3102143: Remove Drupal 8.8 deprecations, compatibility with Drupal 9 so to track that for following up in dependent projects

Status: Fixed » Closed (fixed)

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