-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_Base.php
67 lines (52 loc) · 1.41 KB
/
_Base.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
class WebTest
extends PHPUnit_Extensions_Selenium2TestCase
{
private $screenshotpath;
private $screenurl;
private $sitemapurl = '#SITEMAPURL#';
private $starturl;
public function setUp()
{
$this->setBrowser('firefox');
$url = parse_url($this->sitemapurl);
$this->starturl = $url['scheme'] . '://' . $url['host'];
$this->setBrowserUrl($this->starturl);
$url = parse_url($this->getBrowserUrl());
$this->screenurl = $url['host'];
$this->screenshotpath = __DIR__ . '/screenshots/' . $this->screenurl;
if (! is_dir($this->screenshotpath)) {
mkdir($this->screenshotpath, 0777, true);
}
}
private function screenshot($url)
{
$filedata = $this->currentScreenshot();
$url = preg_replace('/^\//', '', $url);
$url = preg_replace('/\/$/', '', $url);
$url = preg_replace('/\//', '_', $url);
if ($url == '') {
$url = 'index';
}
file_put_contents($this->screenshotpath . '/' . $url . '.png', $filedata);
}
public function testSitemap()
{
libxml_use_internal_errors(true);
$xml = simplexml_load_string(file_get_contents($this->sitemapurl));
if (! $xml) {
foreach(libxml_get_errors() AS $e) {
echo $e . "\n";
}
} else {
foreach($xml->url AS $url) {
$loc = (string)$url->loc;
if (strpos($loc, $this->starturl) !== false) {
$url = str_replace($this->starturl, '', $loc);
$this->url($url);
$this->screenshot($url);
}
}
}
}
}