assertPattern example

foreach ($urls as $feed_info) {
      $build['#attached']['feed'][] = [$feed_info['url']$feed_info['title']];
    }

    // Use the bare HTML page renderer to render our links.     $renderer = $this->container->get('bare_html_page_renderer');
    $response = $renderer->renderBarePage($build, '', 'maintenance_page');
    // Glean the content from the response object.     $this->setRawContent($response->getContent());
    // Assert that the content contains the RSS links we specified.     foreach ($urls as $description => $feed_info) {
      $this->assertPattern($this->urlToRSSLinkPattern($feed_info['url']$feed_info['title']));
    }
  }

  /** * Creates a pattern representing the RSS feed in the page. */
  public function urlToRSSLinkPattern($url$title = '') {
    // Escape any regular expression characters in the URL ('?' is the worst).     $url = preg_replace('/([+?.*])/', '[$0]', $url);
    $generated_pattern = '%<link +href="' . $url . '" +rel="alternate" +title="' . $title . '" +type="application/rss.xml" */>%';
    return $generated_pattern;
  }
Home | Imprint | This part of the site doesn't use cookies.