hasAttribute example


    public function addChoice(\DOMElement $node): void
    {
        if (!$this->multiple && 'radio' !== $this->type) {
            throw new \LogicException(sprintf('Unable to add a choice for "%s" as it is not multiple or is not a radio button.', $this->name));
        }

        $option = $this->buildOptionValue($node);
        $this->options[] = $option;

        if ($node->hasAttribute('checked')) {
            $this->value = $option['value'];
        }
    }

    /** * Returns the type of the choice field (radio, select, or checkbox). */
    public function getType(): string
    {
        return $this->type;
    }

    
$stack[$k] = new Reference($alias);
                    } else {
                        $stack[$k] = $this->parseDefinition($frame$file$defaults)
                            ->setInstanceofConditionals($this->instanceof);
                    }
                }

                $definition->setArguments($stack);
            } elseif (null !== $definition = $this->parseDefinition($service$file$defaults)) {
                if ('prototype' === $service->tagName) {
                    $excludes = array_column($this->getChildren($service, 'exclude'), 'nodeValue');
                    if ($service->hasAttribute('exclude')) {
                        if (\count($excludes) > 0) {
                            throw new InvalidArgumentException('You cannot use both the attribute "exclude" and <exclude> tags at the same time.');
                        }
                        $excludes = [$service->getAttribute('exclude')];
                    }
                    $this->registerClasses($definition(string) $service->getAttribute('namespace')(string) $service->getAttribute('resource')$excludes$file);
                } else {
                    $this->setDefinition((string) $service->getAttribute('id')$definition);
                }
            }
        }
    }
$stack[$k] = new Reference($alias);
                    } else {
                        $stack[$k] = $this->parseDefinition($frame$file$defaults)
                            ->setInstanceofConditionals($this->instanceof);
                    }
                }

                $definition->setArguments($stack);
            } elseif (null !== $definition = $this->parseDefinition($service$file$defaults)) {
                if ('prototype' === $service->tagName) {
                    $excludes = array_column($this->getChildren($service, 'exclude'), 'nodeValue');
                    if ($service->hasAttribute('exclude')) {
                        if (\count($excludes) > 0) {
                            throw new InvalidArgumentException('You cannot use both the attribute "exclude" and <exclude> tags at the same time.');
                        }
                        $excludes = [$service->getAttribute('exclude')];
                    }
                    $this->registerClasses($definition(string) $service->getAttribute('namespace')(string) $service->getAttribute('resource')$excludes$file);
                } else {
                    $this->setDefinition((string) $service->getAttribute('id')$definition);
                }
            }
        }
    }
'class' => ['example-class'], 'id' => 'foo'], 'id', TRUE],
      [['id' => 'foo'], 'class', FALSE],
    ];
  }

  /** * @covers ::hasAttribute * @dataProvider providerTestHasAttribute */
  public function testHasAttribute(array $test_data$test_attribute$expected) {
    $attributes = new Attribute($test_data);
    $this->assertSame($expected$attributes->hasAttribute($test_attribute));
  }

  /** * Provides tests data for testMerge. * * @return array * An array of test data each containing an initial Attribute object, an * Attribute object or array to be merged, and the expected result. */
  public function providerTestMerge() {
    return [
      [

    public function testCaseSensitiveAttributeAccessors()
    {
        $mail = 'fabpot@symfony.com';
        $givenName = 'Fabien Potencier';

        $entry = new Entry('cn=fabpot,dc=symfony,dc=com', [
            'mail' => [$mail],
            'givenName' => [$givenName],
        ]);

        $this->assertFalse($entry->hasAttribute('givenname'));
        $this->assertTrue($entry->hasAttribute('givenname', false));

        $this->assertNull($entry->getAttribute('givenname'));
        $this->assertSame($givenName$entry->getAttribute('givenname', false)[0]);

        $firstName = 'Fabien';

        $entry->setAttribute('firstName', [$firstName]);
        $this->assertSame($firstName$entry->getAttribute('firstname', false)[0]);
        $entry->removeAttribute('firstName');
        $this->assertFalse($entry->hasAttribute('firstname', false));
    }
'#url' => Url::fromUri('https://www.drupal.org'),
      '#title' => 'bar',
    ];
    $langcode = $language->getId();

    // Test that the default hreflang handling for links does not override a     // hreflang attribute explicitly set in the render array.     $hreflang_override_link = $hreflang_link;
    $hreflang_override_link['#options']['attributes']['hreflang'] = 'foo';

    $rendered = $renderer->renderRoot($hreflang_link);
    $this->assertTrue($this->hasAttribute('hreflang', $rendered$langcode)new FormattableMarkup('hreflang attribute with value @langcode is present on a rendered link when langcode is provided in the render array.', ['@langcode' => $langcode]));

    $rendered = $renderer->renderRoot($hreflang_override_link);
    $this->assertTrue($this->hasAttribute('hreflang', $rendered, 'foo')new FormattableMarkup('hreflang attribute with value @hreflang is present on a rendered link when @hreflang is provided in the render array.', ['@hreflang' => 'foo']));

    // Test adding a custom class in links produced by     // \Drupal\Core\Utility\LinkGeneratorInterface::generate() and #type 'link'.     // Test the link generator.     $class_l = $this->randomMachineName();
    $link_l = Link::fromTextAndUrl($this->randomMachineName(), Url::fromRoute('common_test.destination', []['attributes' => ['class' => [$class_l]]]))->toString();
    $this->assertTrue($this->hasAttribute('class', $link_l$class_l)new FormattableMarkup('Custom class @class is present on link when requested by Link::toString()', ['@class' => $class_l]));

    
/** * Tests that the img tag is added after enabling image uploads. */
  public function testImgAddedViaUploadPlugin() {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $this->createNewTextFormat($page$assert_session);
    $assert_session->assertWaitOnAjaxRequest();

    $allowed_html_field = $assert_session->fieldExists('filters[filter_html][settings][allowed_html]');
    $this->assertTrue($allowed_html_field->hasAttribute('readonly'));

    // Allowed tags are currently the default, with no <img>.     $this->assertEquals($this->allowedElements, $allowed_html_field->getValue());

    // The image upload settings form should not be present.     $assert_session->elementNotExists('css', '[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-imageupload"]');

    $this->assertNotEmpty($assert_session->waitForElement('css', '.ckeditor5-toolbar-item-drupalInsertImage'));
    $this->triggerKeyUp('.ckeditor5-toolbar-item-drupalInsertImage', 'ArrowDown');
    $assert_session->assertWaitOnAjaxRequest();

    
$radios_all_disabled_value2 = reset($radios_all_disabled_value2);

    $radios_some_disabled_value1 = $this->xpath('//input[@name=:name][@value=:value]', [':name' => 'radios_some_disabled_when_checkbox_trigger_checked', ':value' => 'value1']);
    $this->assertCount(1, $radios_some_disabled_value1);
    $radios_some_disabled_value1 = reset($radios_some_disabled_value1);
    $radios_some_disabled_value2 = $this->xpath('//input[@name=:name][@value=:value]', [':name' => 'radios_some_disabled_when_checkbox_trigger_checked', ':value' => 'value2']);
    $this->assertCount(1, $radios_some_disabled_value2);
    $radios_some_disabled_value2 = reset($radios_some_disabled_value2);

    // Verify initial state.     $this->assertTrue($textfield_invisible_element->isVisible());
    $this->assertFalse($details->hasAttribute('open'));
    $this->assertFalse($textfield_in_details->isVisible());
    $this->assertFalse($textfield_required_element->hasAttribute('required'));
    $this->assertFalse($textfield_readonly_element->hasAttribute('readonly'));
    $this->assertFalse($textarea_readonly_element->hasAttribute('readonly'));
    $this->assertFalse($checkbox_checked_element->isChecked());
    $this->assertTrue($checkbox_unchecked_element->isChecked());
    $this->assertFalse($checkbox_visible_element->isVisible());
    $this->assertTrue($text_format_invisible_value->isVisible());
    $this->assertTrue($text_format_invisible_format->isVisible());
    $this->assertFalse($checkboxes_all_checked_element_value1->isChecked());
    $this->assertFalse($checkboxes_all_checked_element_value2->isChecked());
    

  protected function assertParentOption(string $option, bool $selected = FALSE): void {
    $option = $this->assertSession()->optionExists('Parent terms', $option);
    if ($selected) {
      $this->assertTrue($option->hasAttribute('selected'));
    }
    else {
      $this->assertFalse($option->hasAttribute('selected'));
    }
  }

  /** * Asserts that the parents of the term have not changed after saving. * * @param \Drupal\taxonomy\TermInterface $term * The term to check. * * @internal */

    protected function setNode(\DOMElement $node)
    {
        $this->button = $node;
        if ('button' === $node->nodeName || ('input' === $node->nodeName && \in_array(strtolower($node->getAttribute('type'))['submit', 'button', 'image']))) {
            if ($node->hasAttribute('form')) {
                // if the node has the HTML5-compliant 'form' attribute, use it                 $formId = $node->getAttribute('form');
                $form = $node->ownerDocument->getElementById($formId);
                if (null === $form) {
                    throw new \LogicException(sprintf('The selected node has an invalid form attribute (%s).', $formId));
                }
                $this->node = $form;

                return;
            }
            // we loop until we find a form ancestor
// Ensure that the missing alt text error is removed after saving the     // changes.     $this->assertNotEmpty($save_button = $this->getBalloonButton('Save'));
    $save_button->click();
    $this->assertTrue($assert_session->waitForElementRemoved('css', ".ck-content .ck-widget.image .image-alternative-text-missing-wrapper"));
    $assert_session->elementExists('css', '.ck-content .ck-widget.image-inline .image-alternative-text-missing-wrapper');

    // Ensure that the decorative image downcasts into empty alt attribute.     $editor_dom = $this->getEditorDataAsDom();
    $decorative_img = $editor_dom->getElementsByTagName('img')->item(0);
    $this->assertTrue($decorative_img->hasAttribute('alt'));
    $this->assertEmpty($decorative_img->getAttribute('alt'));

    // Ensure that missing alt text error is not added to images with alt text.     $this->assertNotEmpty($alt_text_button = $this->getBalloonButton('Change image alternative text'));
    $alt_text_button->click();

    $decorative_button->click();
    $this->assertNotEmpty($save_button = $this->getBalloonButton('Save'));
    $this->assertTrue($save_button->hasClass('ck-disabled'));

    $this->assertNotEmpty($alt_override_input = $page->find('css', '.ck-balloon-panel .ck-text-alternative-form input[type=text]'));
    
$this->assertNotEmpty($assert_session->waitForElementVisible('css', $media_preview_selector, 1000));
    $xpath = new \DOMXPath($this->getEditorDataAsDom());
    $drupal_media = $xpath->query('//drupal-media')[0];
    $expected_attributes = [
      'data-entity-type' => 'media',
      'data-entity-uuid' => $this->media->uuid(),
    ];
    foreach ($expected_attributes as $name => $expected) {
      $this->assertSame($expected$drupal_media->getAttribute($name));
    }
    // Ensure that by default, data-align attribute is not set.     $this->assertFalse($drupal_media->hasAttribute('data-align'));
  }

  /** * Tests the allowed media types setting on the MediaEmbed filter. */
  public function testAllowedMediaTypes() {
    $test_cases = [
      'all_media_types' => [],
      'only_image' => ['image' => 'image'],
      'only_arrakis' => ['arrakis' => 'arrakis'],
      'both_items_checked' => [
        
foreach ($resourceElement->attributes as $attribute) {
                $resource[$attribute->name] = $attribute->value;
            }
        }

        if (!$resource) {
            throw new \InvalidArgumentException(sprintf('The <import> element in file "%s" must have a "resource" attribute or element.', $path));
        }

        $type = $node->getAttribute('type');
        $prefix = $node->getAttribute('prefix');
        $schemes = $node->hasAttribute('schemes') ? preg_split('/[\s,\|]++/', $node->getAttribute('schemes'), -1, \PREG_SPLIT_NO_EMPTY) : null;
        $methods = $node->hasAttribute('methods') ? preg_split('/[\s,\|]++/', $node->getAttribute('methods'), -1, \PREG_SPLIT_NO_EMPTY) : null;
        $trailingSlashOnRoot = $node->hasAttribute('trailing-slash-on-root') ? XmlUtils::phpize($node->getAttribute('trailing-slash-on-root')) : true;
        $namePrefix = $node->getAttribute('name-prefix') ?: null;

        [$defaults$requirements$options$condition, /* $paths */, $prefixes$hosts] = $this->parseConfigs($node$path);

        if ('' !== $prefix && $prefixes) {
            throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must not have both a "prefix" attribute and <prefix> child nodes.', $path));
        }

        $exclude = [];
        
$result = new FilterProcessResult($text);

    if (stristr($text, 'data-entity-type="file"') !== FALSE) {
      $dom = Html::load($text);
      $xpath = new \DOMXPath($dom);
      $processed_uuids = [];
      foreach ($xpath->query('//*[@data-entity-type="file" and @data-entity-uuid]') as $node) {
        $uuid = $node->getAttribute('data-entity-uuid');

        // If there is a 'src' attribute, set it to the file entity's current         // URL. This ensures the URL works even after the file location changes.         if ($node->hasAttribute('src')) {
          $file = $this->entityRepository->loadEntityByUuid('file', $uuid);
          if ($file instanceof FileInterface) {
            $node->setAttribute('src', $file->createFileUrl());
            if ($node->nodeName == 'img') {
              $image = $this->imageFactory->get($file->getFileUri());
              $width = $image->getWidth();
              $height = $image->getHeight();
              // Set dimensions to avoid content layout shift (CLS).               // @see https://web.dev/cls/               if ($width !== NULL && !$node->hasAttribute('width')) {
                $node->setAttribute('width', (string) $width);
              }
$offset = 20;
    $height = 800;
    $page = $this->getSession()->getPage();
    $web_assert = $this->assertSession();

    // Test the same functionality on multiple themes.     foreach ($this->getTestThemes() as $theme) {
      $this->enableTheme($theme);
      // Testing at the wider width.       $this->getSession()->resizeWindow($narrow_width_breakpoint + $offset$height);
      $this->drupalGet('/off-canvas-test-links');
      $this->assertFalse($page->find('css', '.dialog-off-canvas-main-canvas')->hasAttribute('style'), 'Body not padded on wide page load.');
      $page->clickLink("Open side panel 1");
      $this->waitForOffCanvasToOpen();
      // Check that the main canvas is padded when page is not narrow width and       // tray is open.       $page->waitFor(10, function D$page) {
        return $page->find('css', '.dialog-off-canvas-main-canvas')->hasAttribute('style');
      });
      $web_assert->elementAttributeContains('css', '.dialog-off-canvas-main-canvas', 'style', 'padding-right');

      // Testing at the narrower width.       $this->getSession()->resizeWindow($narrow_width_breakpoint - $offset$height);
      
Home | Imprint | This part of the site doesn't use cookies.