-
Notifications
You must be signed in to change notification settings - Fork 5
/
GlValidatorTest.php
148 lines (133 loc) · 6.08 KB
/
GlValidatorTest.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/**
* Test GlValidator
*
* PHP version 5.4
*
* @category GLICER
* @package GlHtml\Tests
* @author Emmanuel ROECKER
* @author Rym BOUCHAGOUR
* @copyright 2015 GLICER
* @license MIT
* @link http://dev.glicer.com/
*
* Created : 20/02/15
* File : GlValidatorTest.php
*
*/
namespace GlValidator\Tests;
use GlValidator\GlW3CValidator;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
/**
* @covers \GlValidator\GlW3CValidator
*/
class GlValidatorTest extends \PHPUnit_Framework_TestCase
{
public function testHtml()
{
$finder = new Finder();
$files = $finder->files()->sortByName()->in(__DIR__ . "/entry/");
$files = [$files, __DIR__ . "/glicer.css", __DIR__ . "/glicer.html"];
$validator = new GlW3CValidator(__DIR__ . "/result", URL_HTML_VALIDATOR, URL_CSS_VALIDATOR);
$count = 0;
$result = $validator->validate(
$files,
['html'],
function (SplFileInfo $file) use (&$count) {
$filename = strtr($file->getRelativePathname(), ["\\" => "/"]);
if (strlen($filename) == "") {
$filename = $file->getBasename();
}
switch ($count) {
case 0:
$this->assertEquals("test1/index.html", $filename);
break;
case 1:
$this->assertEquals("test2/index.html", $filename);
break;
case 2:
$this->assertEquals("glicer.html", $filename);
break;
default:
$this->fail(
"Error count $count with $filename"
);
}
$count++;
}
);
$filestest = [
"test2/w3c_html_index.html"
];
$this->assertEquals(NULL,$result['test1/index.html']);
$this->assertNotEquals(NULL, $result['test2/index.html']);
$this->assertEquals(NULL, $result['/glicer.html']);
foreach ($filestest as $file) {
$src = __DIR__ . "/expected/" . $file;
$dst = __DIR__ . "/result/" . $file;
$this->assertFileEquals($src, $dst, "$src different to $dst");
}
}
public function testHtmlCss()
{
$finder = new Finder();
$files = $finder->files()->sortByName()->in(__DIR__ . "/entry/");
$files = [$files, __DIR__ . "/glicer.css", __DIR__ . "/glicer.html"];
$validator = new GlW3CValidator(__DIR__ . "/result", URL_HTML_VALIDATOR, URL_CSS_VALIDATOR);
$count = 0;
$result = $validator->validate(
$files,
['html', 'css'],
function (SplFileInfo $file) use (&$count) {
$filename = strtr($file->getRelativePathname(), ["\\" => "/"]);
if (strlen($filename) == "") {
$filename = $file->getBasename();
}
switch ($count) {
case 0:
$this->assertEquals("test1/css/glicer.css", $filename);
break;
case 1:
$this->assertEquals("test1/index.html", $filename);
break;
case 2:
$this->assertEquals("test2/css/glicer.css", $filename);
break;
case 3:
$this->assertEquals("test2/index.html", $filename);
break;
case 4:
$this->assertEquals("glicer.css", $filename);
break;
case 5:
$this->assertEquals("glicer.html", $filename);
break;
default:
$this->fail(
"Error count $count with $filename"
);
}
$count++;
}
);
$filestest = [
"test1/css/w3c_css_glicer.html",
"test2/w3c_html_index.html",
"test2/css/w3c_css_glicer.html",
"w3c_css_glicer.html"
];
$this->assertEquals(NULL, $result["test1/css/glicer.css"]);
$this->assertEquals(NULL,$result["test1/index.html"]);
$this->assertNotEquals(NULL, $result["test2/css/glicer.css"]);
$this->assertNotEquals(NULL, $result["test2/index.html"]);
$this->assertNotEquals(NULL, $result["/glicer.css"]);
$this->assertEquals(NULL, $result["/glicer.html"]);
foreach ($filestest as $file) {
$src = __DIR__ . "/expected/" . $file;
$dst = __DIR__ . "/result/" . $file;
$this->assertFileEquals($src, $dst, "$src different to $dst");
}
}
}