You are here

protected function CriticalCssHeadTest::getCssFiles in Critical CSS 8

Get which CSS files are being used in a HTML string.

Parameters

string $html: HTML to be parsed.

string $query: XPath expression to be used.

Return value

array Array with CSS files

1 call to CriticalCssHeadTest::getCssFiles()
CriticalCssHeadTest::testCriticalCssInHead in tests/src/Functional/CriticalCssHeadTest.php
Test critical CSS inside <head> element.

File

tests/src/Functional/CriticalCssHeadTest.php, line 120

Class

CriticalCssHeadTest
Tests Critical CSS functionality on HTML HEAD.

Namespace

Drupal\Tests\critical_css\Functional

Code

protected function getCssFiles($html, $query = '//link[@rel="stylesheet"]') {
  $stylesheetLinks = [];
  $document = Html::load($html);
  $xpath = new \DOMXPath($document);
  $dom_nodes = $xpath
    ->query($query);
  foreach ($dom_nodes as $dom_node) {
    $stylesheetLinks[] = $dom_node
      ->getAttribute('href');
  }
  return $stylesheetLinks;
}