Skip to content
Snippets Groups Projects

Resolve #3392903 "Validate inputs resolveexpression"

Closes #3392903

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
12 class TypeResolverTest extends UnitTestCase {
13
14 /**
15 * @dataProvider provideInvalidTypes
16 */
17 public function testInvalidType($name, $message, $data = []): void {
18 $this->expectException(\LogicException::class);
19 $this->expectExceptionMessage($message);
20 TypeResolver::resolveDynamicTypeName($name, $data);
21 }
22
23 public function provideInvalidTypes() {
24 return [
25 'invalid %variable' => [
26 '[foo.%bar.qux]',
27 'The only valid usages of a variable value with a % in it are %parent, %key, and %type in foo.%bar.qux',
  • Author Developer

    :nerd: Since this code was originally written, #3382581 renamed the term "variable value" to "expression". We should update that here too.

    Furthermore, I think this would be clearer if the various literals are quoted, to make them stand out:

    Suggested change
    29 'The only valid usages of a variable value with a % in it are %parent, %key, and %type in foo.%bar.qux',
    29 'The only valid usages of an expression with a `%` in it are `%parent`, `%key`, and `%type` in `foo.%bar.qux`',

    (I used backticks, but single quotes or double quotes are fine too. Drupal is not very consistent in this regard. Besides, this will only be visible to developers, not end users, so it won't matter a great deal.)

  • Joris Vercammen changed this line in version 4 of the diff

    changed this line in version 4 of the diff

  • Please register or sign in to reply
  • Wim Leers
  • 8 /**
    9 * @covers \Drupal\Core\Config\Schema\TypeResolver
    10 * @group config
    11 */
    12 class TypeResolverTest extends UnitTestCase {
    13
    14 /**
    15 * @dataProvider provideInvalidTypes
    16 */
    17 public function testInvalidType($name, $message, $data = []): void {
    18 $this->expectException(\LogicException::class);
    19 $this->expectExceptionMessage($message);
    20 TypeResolver::resolveDynamicTypeName($name, $data);
    21 }
    22
    23 public function provideInvalidTypes() {
  • Wim Leers added 1 commit

    added 1 commit

    • 70aca1cc - Strict types are now required by `phpcs`.

    Compare with previous version

  • Wim Leers
  • Wim Leers added 1 commit

    added 1 commit

    Compare with previous version

  • Joris Vercammen added 75 commits

    added 75 commits

    • 6a4bf960...33630ea5 - 71 commits from branch project:11.x
    • 50b8835b - Merge remote-tracking branch 'origin/11.x' into 3392903-validate-inputs-resolveexpression
    • 004178b7 - Fix remark by Wim about provider name
    • fd0956c6 - Add quotes as suggested by Wim
    • d36ac99b - Remove test that is now obsolete

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • 87 85 }
    88 86
    89 87 $parts = explode('.', $expression);
    88 $previous_name = NULL;
    90 89 // Process each value part, one at a time.
    91 90 while ($name = array_shift($parts)) {
    91 if (str_starts_with($name, '%') && !in_array($name, ['%parent', '%key', '%type'])) {
    92 throw new \LogicException('The only valid usages of a variable value with a `%` in it are `%parent`, `%key`, and `%type` in `' . $expression . '`');
    • Author Developer

      :bug: #3406487 changed this confusing "variable value" terminology to "dynamic type expression". And I think we can make the message a bit clearer too:

      Suggested change
      92 throw new \LogicException('The only valid usages of a variable value with a `%` in it are `%parent`, `%key`, and `%type` in `' . $expression . '`');
      92 throw new \LogicException('`' . $expression .'` is not a valid dynamic type expression. Dynamic type expressions must contain at least `%parent`, `%key`, or `%type`.`');
    • Joris Vercammen changed this line in version 6 of the diff

      changed this line in version 6 of the diff

    • Please register or sign in to reply
  • 74 74 * a bundle.
    75 75 *
    76 76 * @testWith ["%parent.entity_type_id", "entity_test_with_bundle"]
    77 * ["%paren.entity_type_id", "%paren.entity_type_id"]
    78 77 */
    • Comment on lines 76 to 78
      Author Developer

      :thinking: Right now this is leaving this test with only a single test case. Can we not instead expand this test coverage a bit? It'd be nice to test %parent.%parent.entity_type_id and %parent.%key for example.

    • The grandparent usecase is already tested in testEntityTypeIdFromMultipleParents.

    • Author Developer

      Fair.

      More importantly: there are now 2 test cases again. :thumbsup:

      Actually … this test case does not match the name nor docblock of this test :sweat_smile: We should probably rename the method to something like testDynamicEntityType() and change the first line of the docblock to Tests getting the entity type ID.?

    • Please register or sign in to reply
  • added 1 commit

    • 540d593f - Update LogicException message

    Compare with previous version

  • Joris Vercammen added 280 commits

    added 280 commits

    • 540d593f...f8a2ccac - 279 commits from branch project:11.x
    • 6da9d07c - Merge remote-tracking branch 'origin/11.x' into 3392903-validate-inputs-resolveexpression

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • 87 85 }
    88 86
    89 87 $parts = explode('.', $expression);
    88 $previous_name = NULL;
    90 89 // Process each value part, one at a time.
    91 90 while ($name = array_shift($parts)) {
    91 if (str_starts_with($name, '%') && !in_array($name, ['%parent', '%key', '%type'])) {
  • Adam G-H
  • Adam G-H
  • 10 /**
    11 * @covers \Drupal\Core\Config\Schema\TypeResolver
    12 * @group config
    13 */
    14 class TypeResolverTest extends UnitTestCase {
    15
    16 /**
    17 * @dataProvider providerInvalidTypes
    18 */
    19 public function testInvalidType($name, $message, $data = []): void {
    20 $this->expectException(\LogicException::class);
    21 $this->expectExceptionMessage($message);
    22 TypeResolver::resolveDynamicTypeName($name, $data);
    23 }
    24
    25 public function providerInvalidTypes() {
  • added 1 commit

    Compare with previous version

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading