Verified Commit 30ac7f79 authored by Dave Long's avatar Dave Long
Browse files

docs: #3513561 Fix LongLineDeclaration in KernelTests

By: quietone
By: smustgrave
By: longwave
By: oily
(cherry picked from commit 83e557e4)
parent a55b4e7d
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
    <include-pattern>core/*/FunctionalJavascript/*</include-pattern>
    <include-pattern>core/*/Kernel/*</include-pattern>
    <include-pattern>core/*/Functional/*</include-pattern>
    <include-pattern>core/*/KernelTests/*</include-pattern>
    <include-pattern>core/lib/*</include-pattern>
    <include-pattern>core/modules/*/tests/modules/*</include-pattern>
    <include-pattern>core/modules/*/Plugin/*</include-pattern>
+20 −5
Original line number Diff line number Diff line
@@ -1194,7 +1194,10 @@ protected function assertOptionByText($id, $text, $message = '') {
   */
  protected function assertOptionWithDrupalSelector($drupal_selector, $option, $message = '') {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
    $options = $this->xpath('//select[@data-drupal-selector=:data_drupal_selector]//option[@value=:option]', [':data_drupal_selector' => $drupal_selector, ':option' => $option]);
    $options = $this->xpath(
      '//select[@data-drupal-selector=:data_drupal_selector]//option[@value=:option]',
      [':data_drupal_selector' => $drupal_selector, ':option' => $option],
    );
    $message = $message ?: sprintf('Option %s for field %s exists.', $option, $drupal_selector);
    $this->assertTrue(isset($options[0]), $message);
  }
@@ -1257,7 +1260,10 @@ protected function assertNoOption($id, $option, $message = ''): bool {
   */
  protected function assertOptionSelected($id, $option, $message = ''): bool {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
    $message = $message ?: new FormattableMarkup('Option @option for field @id is selected.', ['@option' => $option, '@id' => $id]);
    $message = $message ?: new FormattableMarkup(
      'Option @option for field @id is selected.',
      ['@option' => $option, '@id' => $id]
    );
    $elements = $this->xpath('//select[@id=:id]//option[@value=:option]', [':id' => $id, ':option' => $option]);
    $this->assertNotEmpty($elements, $message);
    $this->assertNotEmpty($elements[0]['selected'], $message);
@@ -1290,8 +1296,14 @@ protected function assertOptionSelected($id, $option, $message = ''): bool {
   */
  protected function assertOptionSelectedWithDrupalSelector($drupal_selector, $option, $message = ''): bool {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
    $message = $message ?: new FormattableMarkup('Option @option for field @data_drupal_selector is selected.', ['@option' => $option, '@data_drupal_selector' => $drupal_selector]);
    $elements = $this->xpath('//select[@data-drupal-selector=:data_drupal_selector]//option[@value=:option]', [':data_drupal_selector' => $drupal_selector, ':option' => $option]);
    $message = $message ?: new FormattableMarkup(
      'Option @option for field @data_drupal_selector is selected.',
      ['@option' => $option, '@data_drupal_selector' => $drupal_selector]
    );
    $elements = $this->xpath(
      '//select[@data-drupal-selector=:data_drupal_selector]//option[@value=:option]',
      [':data_drupal_selector' => $drupal_selector, ':option' => $option]
    );
    $this->assertNotEmpty($elements, $message);
    $this->assertNotEmpty($elements[0]['selected'], $message);
    return TRUE;
@@ -1321,7 +1333,10 @@ protected function assertOptionSelectedWithDrupalSelector($drupal_selector, $opt
   */
  protected function assertNoOptionSelected($id, $option, $message = ''): bool {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:11.1.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3476110', E_USER_DEPRECATED);
    $message = $message ?: new FormattableMarkup('Option @option for field @id is not selected.', ['@option' => $option, '@id' => $id]);
    $message = $message ?: new FormattableMarkup(
      'Option @option for field @id is not selected.',
      ['@option' => $option, '@id' => $id]
    );
    $elements = $this->xpath('//select[@id=:id]//option[@value=:option]', [':id' => $id, ':option' => $option]);
    $this->assertNotEmpty($elements, $message);
    $this->assertEmpty($elements[0]['selected'], $message);
+2 −0
Original line number Diff line number Diff line
@@ -514,6 +514,7 @@ public static function providerMappingInterpretation(): \Generator {
  /**
 * Tests invalid mapping key definition.
 */
  // phpcs:disable Drupal.Arrays.Array.LongLineDeclaration
  #[TestWith([FALSE, 42, "The mapping definition at `foobar` is invalid: its `invalid` key contains a integer. It must be an array."])]
  #[TestWith([FALSE, 10.2, "The mapping definition at `foobar` is invalid: its `invalid` key contains a double. It must be an array."])]
  #[TestWith([FALSE, "type", "The mapping definition at `foobar` is invalid: its `invalid` key contains a string. It must be an array."])]
@@ -522,6 +523,7 @@ public static function providerMappingInterpretation(): \Generator {
  #[TestWith([TRUE, 10.2, "The mapping definition at `my_module.settings:foobar` is invalid: its `invalid` key contains a double. It must be an array."])]
  #[TestWith([TRUE, "type", "The mapping definition at `my_module.settings:foobar` is invalid: its `invalid` key contains a string. It must be an array."])]
  #[TestWith([TRUE, FALSE, "The mapping definition at `my_module.settings:foobar` is invalid: its `invalid` key contains a boolean. It must be an array."])]
  // phpcs:enable
  public function testInvalidMappingKeyDefinition(bool $has_parent, mixed $invalid_key_definition, string $expected_message): void {
    $definition = new MapDataDefinition([
      'type' => 'mapping',
+15 −1
Original line number Diff line number Diff line
@@ -114,7 +114,21 @@ public function testTypedDataAPI(): void {

    $typed_config = $typed_config_manager->createFromNameAndData($config_test_entity->getConfigDependencyName(), $config_test_entity->toArray());
    $this->assertInstanceOf(TypedConfigInterface::class, $typed_config);
    $this->assertEquals(['uuid', 'langcode', 'status', 'dependencies', 'id', 'label', 'weight', 'style', 'size', 'size_value', 'protected_property'], array_keys($typed_config->getElements()));
    $this->assertEquals(
      [
        'uuid',
        'langcode',
        'status',
        'dependencies',
        'id',
        'label',
        'weight',
        'style',
        'size',
        'size_value',
        'protected_property',
      ],
      array_keys($typed_config->getElements()));
  }

  /**
+55 −11
Original line number Diff line number Diff line
@@ -82,12 +82,20 @@ public function testEntityMethod(): void {
    $config_test_entity = $storage->load('dotted.default');
    $this->assertSame('Test value 2', $config_test_entity->getProtectedProperty());

    $manager->applyAction('entity_method:config_test.dynamic:concatProtectedProperty', 'config_test.dynamic.dotted.default', ['Test value ', '3']);
    $manager->applyAction(
      'entity_method:config_test.dynamic:concatProtectedProperty',
      'config_test.dynamic.dotted.default',
      ['Test value ', '3'],
    );
    /** @var \Drupal\config_test\Entity\ConfigTest $config_test_entity */
    $config_test_entity = $storage->load('dotted.default');
    $this->assertSame('Test value 3', $config_test_entity->getProtectedProperty());

    $manager->applyAction('entity_method:config_test.dynamic:concatProtectedPropertyOptional', 'config_test.dynamic.dotted.default', ['Test value ', '4']);
    $manager->applyAction(
      'entity_method:config_test.dynamic:concatProtectedPropertyOptional',
      'config_test.dynamic.dotted.default',
      ['Test value ', '4'],
    );
    /** @var \Drupal\config_test\Entity\ConfigTest $config_test_entity */
    $config_test_entity = $storage->load('dotted.default');
    $this->assertSame('Test value 4', $config_test_entity->getProtectedProperty());
@@ -118,17 +126,29 @@ public function testEntityMethod(): void {
    $config_test_entity = $storage->load('dotted.default');
    $this->assertSame(['foo', 'bar'], $config_test_entity->getArrayProperty());

    $manager->applyAction('entity_method:config_test.dynamic:addToArray', 'config_test.dynamic.dotted.default', ['a', 'b', 'c']);
    $manager->applyAction(
      'entity_method:config_test.dynamic:addToArray',
      'config_test.dynamic.dotted.default',
      ['a', 'b', 'c']
    );
    /** @var \Drupal\config_test\Entity\ConfigTest $config_test_entity */
    $config_test_entity = $storage->load('dotted.default');
    $this->assertSame(['foo', 'bar', ['a', 'b', 'c']], $config_test_entity->getArrayProperty());

    $manager->applyAction('entity_method:config_test.dynamic:setArray', 'config_test.dynamic.dotted.default', ['a', 'b', 'c']);
    $manager->applyAction(
      'entity_method:config_test.dynamic:setArray',
      'config_test.dynamic.dotted.default',
      ['a', 'b', 'c']
    );
    /** @var \Drupal\config_test\Entity\ConfigTest $config_test_entity */
    $config_test_entity = $storage->load('dotted.default');
    $this->assertSame(['a', 'b', 'c'], $config_test_entity->getArrayProperty());

    $manager->applyAction('entity_method:config_test.dynamic:setArray', 'config_test.dynamic.dotted.default', [['a', 'b', 'c'], ['a']]);
    $manager->applyAction(
      'entity_method:config_test.dynamic:setArray',
      'config_test.dynamic.dotted.default',
      [['a', 'b', 'c'], ['a']]
    );
    /** @var \Drupal\config_test\Entity\ConfigTest $config_test_entity */
    $config_test_entity = $storage->load('dotted.default');
    $this->assertSame([['a', 'b', 'c'], ['a']], $config_test_entity->getArrayProperty());
@@ -182,25 +202,41 @@ public function testPluralizedEntityMethod(): void {
    /** @var \Drupal\Core\Config\Action\ConfigActionManager $manager */
    $manager = $this->container->get('plugin.manager.config_action');
    // Call a pluralized method action.
    $manager->applyAction('entity_method:config_test.dynamic:addToArrayMultipleTimes', 'config_test.dynamic.dotted.default', ['a', 'b', 'c', 'd']);
    $manager->applyAction(
      'entity_method:config_test.dynamic:addToArrayMultipleTimes',
      'config_test.dynamic.dotted.default',
      ['a', 'b', 'c', 'd']
    );
    /** @var \Drupal\config_test\Entity\ConfigTest $config_test_entity */
    $config_test_entity = $storage->load('dotted.default');
    $this->assertSame(['a', 'b', 'c', 'd'], $config_test_entity->getArrayProperty());

    $manager->applyAction('entity_method:config_test.dynamic:addToArrayMultipleTimes', 'config_test.dynamic.dotted.default', [['foo'], 'bar']);
    $manager->applyAction(
      'entity_method:config_test.dynamic:addToArrayMultipleTimes',
      'config_test.dynamic.dotted.default',
      [['foo'], 'bar']
    );
    /** @var \Drupal\config_test\Entity\ConfigTest $config_test_entity */
    $config_test_entity = $storage->load('dotted.default');
    $this->assertSame(['a', 'b', 'c', 'd', ['foo'], 'bar'], $config_test_entity->getArrayProperty());

    $config_test_entity->setProtectedProperty('')->save();
    $manager->applyAction('entity_method:config_test.dynamic:appends', 'config_test.dynamic.dotted.default', ['1', '2', '3']);
    $manager->applyAction(
      'entity_method:config_test.dynamic:appends',
      'config_test.dynamic.dotted.default',
      ['1', '2', '3']
    );
    /** @var \Drupal\config_test\Entity\ConfigTest $config_test_entity */
    $config_test_entity = $storage->load('dotted.default');
    $this->assertSame('123', $config_test_entity->getProtectedProperty());

    // Test that the inflector converts to a good plural form.
    $config_test_entity->setProtectedProperty('')->save();
    $manager->applyAction('entity_method:config_test.dynamic:concatProtectedProperties', 'config_test.dynamic.dotted.default', [['1', '2'], ['3', '4']]);
    $manager->applyAction(
      'entity_method:config_test.dynamic:concatProtectedProperties',
      'config_test.dynamic.dotted.default',
      [['1', '2'], ['3', '4']]
    );
    /** @var \Drupal\config_test\Entity\ConfigTest $config_test_entity */
    $config_test_entity = $storage->load('dotted.default');
    $this->assertSame('34', $config_test_entity->getProtectedProperty());
@@ -316,7 +352,11 @@ public function testShorthandActionIds(): void {
    $this->assertCount(0, $storage->loadMultiple(), 'There are no config_test entities');
    /** @var \Drupal\Core\Config\Action\ConfigActionManager $manager */
    $manager = $this->container->get('plugin.manager.config_action');
    $manager->applyAction('createIfNotExists', 'config_test.dynamic.action_test', ['label' => 'Action test', 'protected_property' => '']);
    $manager->applyAction(
      'createIfNotExists',
      'config_test.dynamic.action_test',
      ['label' => 'Action test', 'protected_property' => '']
    );
    /** @var \Drupal\config_test\Entity\ConfigTest[] $config_test_entities */
    $config_test_entities = $storage->loadMultiple();
    $this->assertCount(1, $config_test_entities, 'There is 1 config_test entity');
@@ -344,7 +384,11 @@ public function testDuplicateShorthandActionIds(): void {
    $manager = $this->container->get('plugin.manager.config_action');
    $this->expectException(DuplicateConfigActionIdException::class);
    $this->expectExceptionMessage("The plugins 'entity_method:config_test.dynamic:setProtectedProperty' and 'config_action_duplicate_test:config_test.dynamic:setProtectedProperty' both resolve to the same shorthand action ID for the 'config_test' entity type");
    $manager->applyAction('createIfNotExists', 'config_test.dynamic.action_test', ['label' => 'Action test', 'protected_property' => '']);
    $manager->applyAction(
      'createIfNotExists',
      'config_test.dynamic.action_test',
      ['label' => 'Action test', 'protected_property' => '']
    );
  }

  /**
Loading