Repository navigation
Expand file tree
/
Copy pathWebkitDriverTest.php
More file actions
61 lines (47 loc) · 1.69 KB
/
Copy pathWebkitDriverTest.php
File metadata and controls
61 lines (47 loc) · 1.69 KB
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
<?php
namespace AsyncPHP\Paper\Tests;
use AsyncPHP\Paper\Runner\AmpRunner;
use AsyncPHP\Paper\Driver\WebkitDriver;
use AsyncPHP\Paper\Driver\SyncDriver;
use PHPUnit\Framework\TestCase;
class WebkitDriverTest extends TestCase
{
public function testWebkitDriver()
{
$which = `which wkhtmltopdf`;
if (empty($which) || $which === "wkhtmltopdf not found") {
$this->markTestSkipped("
It appears you don't have the wkhtmltopdf installed or in your path. Better to
skip the test, in that case.
");
}
error_reporting(E_ERROR | E_PARSE);
$driver = new SyncDriver(new WebkitDriver($binary = "/usr/local/bin/wkhtmltopdf", $temp = __DIR__));
$runner = new AmpRunner();
$result = $driver
->header("this is the header")
->body(file_get_contents(__DIR__ . "/fixtures/sample.html"))
->footer("this is the footer")
->size("A4")
->orientation("portrait")
->dpi(300)
->render($runner);
file_put_contents(__DIR__ . "/test-webkit.pdf", $result);
exec("diff-pdf -v " . __DIR__ . "/test-webkit.pdf " . __DIR__ . "/fixtures/test-webkit.pdf", $output);
foreach ($output as $line) {
if (stristr($line, "differs")) {
$this->fail();
}
}
unlink(__DIR__ . "/test-webkit.pdf");
}
/**
* Remove unique dates from PDF content, so it can be compared.
*/
private function scrubDates($content): string
{
$content = preg_replace("/\/CreationDate[^\\n]+/", "", $content);
$content = preg_replace("/\/ModDate[^\\n]+/", "", $content);
return $content;
}
}