Commit f9ce74cf authored by catch's avatar catch
Browse files

Issue #3376263 by Spokje: Tighten xpath selectors to decrease complexity in tests

(cherry picked from commit c8deebc1)
parent d7e7f3ac
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -88,20 +88,16 @@ protected function doTestAggregation(array $settings): void {

    // Collect all the URLs for all the script and styles prior to making any
    // more requests.
    $style_elements = $page->findAll('xpath', '//link[@rel="stylesheet"]');
    $script_elements = $page->findAll('xpath', '//script');
    $style_elements = $page->findAll('xpath', '//link[@href and @rel="stylesheet"]');
    $script_elements = $page->findAll('xpath', '//script[@src]');
    $style_urls = [];
    foreach ($style_elements as $element) {
      if ($element->hasAttribute('href')) {
      $style_urls[] = $element->getAttribute('href');
    }
    }
    $script_urls = [];
    foreach ($script_elements as $element) {
      if ($element->hasAttribute('src')) {
      $script_urls[] = $element->getAttribute('src');
    }
    }
    foreach ($style_urls as $url) {
      $this->assertAggregate($url);
      $this->assertAggregate($url, FALSE);
+25 −29
Original line number Diff line number Diff line
@@ -50,11 +50,10 @@ public function testUnversionedAssets(): void {
    $session = $this->getSession();
    $page = $session->getPage();

    $style_elements = $page->findAll('xpath', '//link[@rel="stylesheet"]');
    $style_elements = $page->findAll('xpath', '//link[@href and @rel="stylesheet"]');
    $this->assertNotEmpty($style_elements);
    $href = NULL;
    foreach ($style_elements as $element) {
      if ($element->hasAttribute('href')) {
      $href = $element->getAttribute('href');
      $url = $this->getAbsoluteUrl($href);
      // Not every script or style on a page is aggregated.
@@ -68,7 +67,6 @@ public function testUnversionedAssets(): void {
      $this->assertStringContainsString('original-content', $aggregate);
      $this->assertStringNotContainsString('extra-stuff', $aggregate);
    }
    }
    $file = file_get_contents('public://test.css') . '.extra-stuff{display:none;}';
    file_put_contents('public://test.css', $file);
    // Clear the library discovery and page caches again so that new URLs are
@@ -78,10 +76,9 @@ public function testUnversionedAssets(): void {
    $this->drupalGet('<front>');
    $session = $this->getSession();
    $page = $session->getPage();
    $style_elements = $page->findAll('xpath', '//link[@rel="stylesheet"]');
    $style_elements = $page->findAll('xpath', '//link[@href and @rel="stylesheet"]');
    $this->assertNotEmpty($style_elements);
    foreach ($style_elements as $element) {
      if ($element->hasAttribute('href')) {
      $new_href = $element->getAttribute('href');
      $this->assertNotSame($new_href, $href);
      $url = $this->getAbsoluteUrl($new_href);
@@ -97,6 +94,5 @@ public function testUnversionedAssets(): void {
      $this->assertStringContainsString('extra-stuff', $aggregate);
    }
  }
  }

}