/**
  * Save the HTML of the session into a file
  * Optionally resolve all the links with a base uri
  *
  * @param  string              $filename
  * @throws InvalidArgumentException if directory doesnt exist or is not writable
  * @param  UriInterface|string $base
  */
 public function saveHtml($filename, $base = null)
 {
     $this->ensureWritableDirectory(dirname($filename));
     $html = new Html($this->getHtml());
     if (null !== $base) {
         $html->resolveLinks(\GuzzleHttp\Psr7\uri_for($base));
     }
     file_put_contents($filename, $html->get());
     return $this;
 }
Example #2
0
 /**
  * @covers ::resolveLinks
  * @covers ::resolveLinkAttribute
  * @covers ::get
  */
 public function testResolveLinks()
 {
     $html = new Html(file_get_contents(__DIR__ . '/../html/index.html'));
     $result = $html->resolveLinks(new Uri('http://google.com:9090'))->get();
     $content = new DOMDocument();
     $content->loadHtml($result);
     $xpath = new DOMXPath($content);
     $this->assertEquals('http://google.com:9090/test_functest/subpage1', $xpath->query('//a[@id="navlink-1"]')->item(0)->getAttribute('href'), 'Links href should be resolved with base');
     $this->assertEquals('http://google.com:9090/Logo.png', $xpath->query('//img[@alt="Logo Image"]')->item(0)->getAttribute('src'), 'Img src should be resolved with base');
     $this->assertEquals('http://google.com:9090/test_functest/contact', $xpath->query('//form')->item(0)->getAttribute('action'), 'Img src should be resolved with base');
 }