write tests for UrlFieldValidationRule

Created on 25 June 2023, over 1 year ago
Updated 24 July 2023, over 1 year ago

Problem/Motivation

write tests for UrlFieldValidationRule

๐Ÿ“Œ Task
Status

Fixed

Version

1.0

Component

Code

Created by

๐Ÿ‡จ๐Ÿ‡ณChina g089h515r806

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @g089h515r806
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.0.7 + Environment: PHP 8.2 & MySQL 8
    last update over 1 year ago
    194 pass
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sumit-k

    Adding patch for UrlFieldValidationRule test. Changes are

    1> Created test.
    2> Added dependencies module
    protected static $modules = ['node', 'field_validation', 'path_alias', 'user'];

    3> Replaced patch validator function inside UrlFieldValidationRule.php.

    -          $flag = \Drupal::service('path.validator')->isValid($normal_path);
    +          $flag = \Drupal::service('path.validator')->getUrlIfValidWithoutAccessCheck($normal_path);
  • ๐Ÿ‡จ๐Ÿ‡ณChina g089h515r806

    Good work.

    1,do not change the code of the validator:

    -          $flag = \Drupal::service('path.validator')->isValid($normal_path);
    +          $flag = \Drupal::service('path.validator')->getUrlIfValidWithoutAccessCheck($normal_path);
    

    If you think this is bug, you can create another issue.

    isValid is OK for most of use case. Drupal 7 version field validation use the similar function which perform a access check.

    2, maybe you do not need to install user module๏ผŒ if validate an internal path, we could use "/node" instead of "/user/1",

    3, Added dependencies module

    protected static $modules = ['node', 'field_validation', 'path_alias', 'user'];
    

    I am not familar with Drupal test. Is it possible override it in UrlFieldValidationRuleTest instead of FieldValidationRuleBase.

    path_alias is only used by this test.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.0.7 + Environment: PHP 8.2 & MySQL 8
    last update over 1 year ago
    195 pass
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sumit-k

    Thanks for the review and suggestion. Sharing new patches with suggested improvements. Considered points 1 , 2 and 3.

  • Status changed to Fixed over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024