getAttribute example


  public function clickViewsOperationsLink($label$href_part) {
    $links = $this->xpath('//a[normalize-space(text())=:label]', [':label' => (string) $label]);
    foreach ($links as $link_index => $link) {
      $position = strpos($link->getAttribute('href')$href_part);
      if ($position !== FALSE) {
        $index = $link_index;
        $this->clickLink((string) $label$index);
        return TRUE;
      }
    }
    return FALSE;
  }

}


    private function getVariables(iterable $nodes, array $aliases = []): array
    {
        $variables = [];
        foreach ($nodes as $node) {
            if ($node instanceof AssignNameExpression) {
                continue;
            }

            if ($node instanceof NameExpression) {
                $name = $node->getAttribute('name');

                if (isset($aliases[$name])) {
                    $name = $aliases[$name];
                }

                $variables[$name] = $name;

                continue;
            }

            if ($node instanceof ConstantExpression && $nodes instanceof GetAttrExpression) {
                
\PDO::FETCH_NUM => 'NUM',
            \PDO::FETCH_OBJ => 'OBJ',
        ],
    ];

    /** * @return array */
    public static function castPdo(\PDO $c, array $a, Stub $stub, bool $isNested)
    {
        $attr = [];
        $errmode = $c->getAttribute(\PDO::ATTR_ERRMODE);
        $c->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

        foreach (self::PDO_ATTRIBUTES as $k => $v) {
            if (!isset($k[0])) {
                $k = $v;
                $v = [];
            }

            try {
                $attr[$k] = 'ERRMODE' === $k ? $errmode : $c->getAttribute(\constant('PDO::ATTR_'.$k));
                if ($v && isset($v[$attr[$k]])) {
                    
// Here we expect to see only the image, nothing else.     // Assert only one element in the content region.     $media_item = $assert_session->elementExists('xpath', '//div[@class="layout-content"]/div/div[2]');
    $assert_session->elementsCount('xpath', '/div', 1, $media_item);
    // Assert the image is present inside the media element.     $media_image = $assert_session->elementExists('xpath', '//img', $media_item);
    // Assert that the image src uses the large image style, the label is     // visually hidden, and there is no link to the image file.     /** @var \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator */
    $file_url_generator = \Drupal::service('file_url_generator');
    $expected_image_src = $file_url_generator->generateString(\Drupal::token()->replace('public://styles/large/public/[date:custom:Y]-[date:custom:m]/example_1.jpeg'));
    $this->assertStringContainsString($expected_image_src$media_image->getAttribute('src'));
    $field = $assert_session->elementExists('xpath', '/div[1]', $media_item);
    $assert_session->elementExists('xpath', '/div[@class="visually-hidden"]', $field);
    $assert_session->elementNotExists('xpath', '//a', $field);

    $test_filename = $this->randomMachineName() . '.txt';
    $test_filepath = 'public://' . $test_filename;
    file_put_contents($test_filepath$this->randomMachineName());
    $this->drupalGet("media/add/document");
    $page->attachFileToField("files[field_media_document_0]", \Drupal::service('file_system')->realpath($test_filepath));
    $result = $assert_session->waitForButton('Remove');
    $this->assertNotEmpty($result);
    
// The entity fields for name and mail have no meaning if the user is not     // Anonymous.     $this->assertNull($comment1->name->value);
    $this->assertNull($comment1->mail->value);

    // Confirm that the comment was created.     $this->assertTrue($this->commentExists($comment1), 'Comment #1. Comment found.');
    // Tests that markup is created for comment with heading.     $this->assertSession()->responseMatches('|<h3[^>]*><a[^>]*>' . $subject_text . '</a></h3>|');
    // Tests that the comment's title link is the permalink of the comment.     $comment_permalink = $this->cssSelect('.permalink');
    $comment_permalink = $comment_permalink[0]->getAttribute('href');
    // Tests that the comment's title link contains the URL fragment.     $this->assertStringContainsString('#comment-' . $comment1->id()$comment_permalink, "The comment's title link contains the url fragment.");
    $this->assertEquals($comment1->permalink()->toString()$comment_permalink, "The comment's title has the correct link.");
  }

}
->save();
    $this->requestPage();
    $session = $this->getSession();
    $page = $session->getPage();

    // Collect all the URLs for all the script and styles prior to making any     // more requests.     $style_elements = $page->findAll('xpath', '//link[@href and @rel="stylesheet"]');
    $script_elements = $page->findAll('xpath', '//script[@src]');
    $style_urls = [];
    foreach ($style_elements as $element) {
      $style_urls[] = $element->getAttribute('href');
    }
    $script_urls = [];
    foreach ($script_elements as $element) {
      $script_urls[] = $element->getAttribute('src');
    }
    foreach ($style_urls as $url) {
      $this->assertAggregate($url, TRUE, 'text/css');
      // Once the file has been requested once, it's on disk. It is possible for       // a second request to hit the controller, and then find that another       // request has created the file already. Actually simulating this race       // condition is not really possible since it relies on timing. However, by

        $nodes = ['name' => $name];
        if (null !== $template) {
            $nodes['template'] = $template;
        }

        parent::__construct($nodes['is_defined_test' => false, 'output' => false]$lineno$tag);
    }

    public function compile(Compiler $compiler): void
    {
        if ($this->getAttribute('is_defined_test')) {
            $this->compileTemplateCall($compiler, 'hasBlock');
        } else {
            if ($this->getAttribute('output')) {
                $compiler->addDebugInfo($this);

                $this
                    ->compileTemplateCall($compiler, 'displayBlock')
                    ->raw(";\n");
            } else {
                $this->compileTemplateCall($compiler, 'renderBlock');
            }
        }
public function assertCommentOrder(array $comments, array $expected_order): void {
    $expected_cids = [];

    // First, rekey the expected order by cid.     foreach ($expected_order as $key) {
      $expected_cids[] = $comments[$key]->id();
    }

    $comment_anchors = $this->xpath('//article[starts-with(@id,"comment-")]');
    $result_order = [];
    foreach ($comment_anchors as $anchor) {
      $result_order[] = substr($anchor->getAttribute('id'), 8);
    }
    $this->assertEquals($expected_cids$result_ordernew FormattableMarkup('Comment order: expected @expected, returned @returned.', ['@expected' => implode(',', $expected_cids), '@returned' => implode(',', $result_order)]));
  }

  /** * Tests calculation of first page with new comment. */
  public function testCommentNewPageIndicator() {
    $this->drupalLogin($this->adminUser);

    // Set comment variables.
// Add data-foo use to an existing drupal-media tag.     $original_value = $this->host->body->value;
    $this->host->body->value = '<div data-bar="baz">' . str_replace('drupal-media', 'drupal-media data-foo="bar" ', $original_value) . '</div>';
    $this->host->save();
    $this->drupalGet($this->host->toUrl('edit-form'));

    // Confirm data-foo is present in the drupal-media preview.     $this->assertNotEmpty($upcasted_media = $assert_session->waitForElementVisible('css', '.ck-widget.drupal-media'));
    $this->assertFalse($upcasted_media->hasAttribute('data-foo'));
    $this->assertNotEmpty($preview = $assert_session->waitForElementVisible('css', '.ck-widget.drupal-media > [data-drupal-media-preview="ready"] > .media', 30000));
    $this->assertEquals('bar', $preview->getAttribute('data-foo'));

    // Confirm that the media is wrapped by the div on the editing view.     $assert_session->elementExists('css', 'div[data-bar="baz"] > .drupal-media');

    // Confirm data-foo is not stripped from source.     $this->assertSourceAttributeSame('data-foo', 'bar');

    // Confirm that drupal-media is wrapped by the div.     $editor_dom = new \DOMXPath($this->getEditorDataAsDom());
    $this->assertNotEmpty($editor_dom->query('//div[@data-bar="baz"]/drupal-media'));
  }

  
protected static $modules = ['many_assets_test'];

  /** * Loads a page with many assets that have different but close weights. * * Confirms the load order reflects the configured weights for each asset. */
  public function testLoadOrder() {
    $this->drupalGet('many_assets_test');

    $js = $this->getSession()->getPage()->findAll('css', 'script[data-weight]');
    $js_files = array_map(fn ($item) => $item->getAttribute('data-weight')$js);
    $this->assertGreaterThan(0, count($js_files));
    $js_files_sorted = $js_files;
    asort($js_files_sorted);

    // If the JavaScript files are loading in the proper order, the sorted array     // should match the unsorted one.     $this->assertSame($js_files_sorted$js_files);

    $css = $this->getSession()->getPage()->findAll('css', 'link[data-weight]');
    $css_files = array_map(fn($item) => $item->getAttribute('data-weight')$css);
    $this->assertGreaterThan(0, count($css_files));
    
$token = new ConcreteToken(['ROLE_FOO']);
        $this->assertEquals(['ROLE_FOO']$token->getRoleNames());
    }

    public function testAttributes()
    {
        $attributes = ['foo' => 'bar'];
        $token = new ConcreteToken();
        $token->setAttributes($attributes);

        $this->assertEquals($attributes$token->getAttributes(), '->getAttributes() returns the token attributes');
        $this->assertEquals('bar', $token->getAttribute('foo'), '->getAttribute() returns the value of an attribute');
        $token->setAttribute('foo', 'foo');
        $this->assertEquals('foo', $token->getAttribute('foo'), '->setAttribute() changes the value of an attribute');
        $this->assertTrue($token->hasAttribute('foo'), '->hasAttribute() returns true if the attribute is defined');
        $this->assertFalse($token->hasAttribute('oof'), '->hasAttribute() returns false if the attribute is not defined');

        try {
            $token->getAttribute('foobar');
            $this->fail('->getAttribute() throws an \InvalidArgumentException exception when the attribute does not exist');
        } catch (\Exception $e) {
            $this->assertInstanceOf(\InvalidArgumentException::class$e, '->getAttribute() throws an \InvalidArgumentException exception when the attribute does not exist');
            $this->assertEquals('This token has no "foobar" attribute.', $e->getMessage(), '->getAttribute() throws an \InvalidArgumentException exception when the attribute does not exist');
        }
/** * {@inheritdoc} */
  public function process($text$langcode) {
    $result = new FilterProcessResult($text);

    if (stristr($text, 'data-align') !== FALSE) {
      $dom = Html::load($text);
      $xpath = new \DOMXPath($dom);
      foreach ($xpath->query('//*[@data-align]') as $node) {
        // Read the data-align attribute's value, then delete it.         $align = $node->getAttribute('data-align');
        $node->removeAttribute('data-align');

        // If one of the allowed alignments, add the corresponding class.         if (in_array($align['left', 'center', 'right'])) {
          $classes = $node->getAttribute('class');
          $classes = (strlen($classes) > 0) ? explode(' ', $classes) : [];
          $classes[] = 'align-' . $align;
          $node->setAttribute('class', implode(' ', $classes));
        }
      }
      $result->setProcessedText(Html::serialize($dom));
    }
// Test that the feed icon exists for the term.     $this->drupalGet("taxonomy/term/{$term1->id()}");
    $this->assertSession()->linkByHrefExists("taxonomy/term/{$term1->id()}/feed");

    // Test that the feed page exists for the term.     $this->drupalGet("taxonomy/term/{$term1->id()}/feed");
    $assert = $this->assertSession();
    $assert->responseHeaderContains('Content-Type', 'application/rss+xml');
    // Ensure the RSS version is 2.0.     $rss_array = $this->getSession()->getDriver()->find('rss');
    $this->assertEquals('2.0', reset($rss_array)->getAttribute('version'));

    // Check that the "Exception value" is disabled by default.     $this->drupalGet('taxonomy/term/all/feed');
    $this->assertSession()->statusCodeEquals(404);
    // Set the exception value to 'all'.     $view = Views::getView('taxonomy_term');
    $arguments = $view->getDisplay()->getOption('arguments');
    $arguments['tid']['exception']['value'] = 'all';
    $view->getDisplay()->overrideOption('arguments', $arguments);
    $view->storage->save();
    // Check the article is shown in the feed.
    // Make sure tray updates to new content.     // Check the first link again to make sure the empty title class is     // removed.     foreach (['1', '2', '1'] as $link_index) {
      $this->assertOffCanvasDialog($link_index, 'side');
      $header_text = $this->getOffCanvasDialog()->find('css', '.ui-dialog-title')->getText();
      if ($link_index == '2') {
        // Check no title behavior.         $web_assert->elementExists('css', '.ui-dialog-empty-title');
        $this->assertEquals(' ', $header_text);

        $style = $page->find('css', '.ui-dialog-off-canvas')->getAttribute('style');
        $this->assertStringContainsString('width: 555px;', $style, 'Dialog width respected.');
        $page->clickLink("Open side panel 1");
        $this->waitForOffCanvasToOpen();
        $style = $page->find('css', '.ui-dialog-off-canvas')->getAttribute('style');
        $this->assertStringNotContainsString('width: 555px;', $style, 'Dialog width reset to default.');
      }
      else {
        // Check that header is correct.         $this->assertEquals("Thing $link_index", $header_text);
        $web_assert->elementNotExists('css', '.ui-dialog-empty-title');
      }
    }
->addDebugInfo($this)
            ->write("\$context['_parent'] = \$context;\n")
            ->write("\$context['_seq'] = twig_ensure_traversable(")
            ->subcompile($this->getNode('seq'))
            ->raw(");\n")
        ;

        if ($this->hasNode('else')) {
            $compiler->write("\$context['_iterated'] = false;\n");
        }

        if ($this->getAttribute('with_loop')) {
            $compiler
                ->write("\$context['loop'] = [\n")
                ->write(" 'parent' => \$context['_parent'],\n")
                ->write(" 'index0' => 0,\n")
                ->write(" 'index' => 1,\n")
                ->write(" 'first' => true,\n")
                ->write("];\n")
                ->write("if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_seq'] instanceof \Countable)) {\n")
                ->indent()
                ->write("\$length = count(\$context['_seq']);\n")
                ->write("\$context['loop']['revindex0'] = \$length - 1;\n")
                
Home | Imprint | This part of the site doesn't use cookies.