Skip to content

Commit da8b5ec

Browse files
committed
Add test suite around parsing function
1 parent 2f36044 commit da8b5ec

5 files changed

Lines changed: 96 additions & 0 deletions

File tree

composer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "indieweb/link-rel-parser",
3+
"type": "library",
4+
"description": "Parse rel values from HTTP headers",
5+
"keywords": ["indieweb", "http", "microformats2"],
6+
"license": "Apache-2.0",
7+
"homepage": "https://github.com/indieweb/link-rel-parser-php",
8+
"authors" : [
9+
{
10+
"name": "Tantek Çelik",
11+
"homepage": "http://tantek.com"
12+
},
13+
{
14+
"name": "Aaron Parecki",
15+
"homepage": "http://aaronparecki.com"
16+
}
17+
],
18+
"require": {
19+
"php": ">=5.3.0"
20+
}
21+
}

phpunit.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<phpunit bootstrap="tests/bootstrap.php">
3+
<testsuites>
4+
<testsuite name="date-formatter">
5+
<directory suffix="Test.php">tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
</phpunit>

src/IndieWeb/link_rel_parser.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
namespace IndieWeb;
3+
4+
function http_rels($headerString) {
5+
6+
// TODO: Implement this
7+
8+
return array(
9+
'rels' => array()
10+
);
11+
}

tests/BasicTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
class BasicTest extends PHPUnit_Framework_TestCase {
3+
4+
public function setUp() {
5+
}
6+
7+
private function _testEquals($expected, $headers) {
8+
$result = IndieWeb\http_rels($headers);
9+
$this->assertEquals($expected, $result);
10+
}
11+
12+
public function testInvalidStartDate() {
13+
$this->_testEquals(array(
14+
'rels' => array(
15+
'd' => array('http://example.org/query?a=b,c'),
16+
'e' => array('http://example.org/query?a=b,c'),
17+
'f' => array('http://example.org/'),
18+
)
19+
), "Link: <http://example.org/query?a=b,c>; rel=\"d e\", <http://example.org/>; rel=f");
20+
}
21+
22+
public function testAaronParecki() {
23+
$this->_testEquals(array(
24+
'rels' => array(
25+
'http://webmention.org/' => array('http://aaronparecki.com/webmention.php'),
26+
'indieauth' => array('https://indieauth.com'),
27+
)
28+
), "HTTP/1.1 200 OK
29+
Server: nginx/1.0.14
30+
Date: Sat, 26 Oct 2013 01:40:11 GMT
31+
Content-Type: text/html; charset=UTF-8
32+
Connection: keep-alive
33+
Link: <https://indieauth.com>; rel=\"indieauth\"
34+
X-Pingback: http://pingback.me/webmention?forward=http%3A%2F%2Faaronparecki.com%2Fwebmention.php
35+
Link: <http://aaronparecki.com/webmention.php>; rel=\"http://webmention.org/\"");
36+
}
37+
38+
public function testBarryFrost() {
39+
$this->_testEquals(array(
40+
'rels' => array(
41+
'webmention' => array('http://aaronparecki.com/webmention.php'),
42+
)
43+
), "HTTP/1.1 200 OK
44+
Cache-Control: max-age=0, private, must-revalidate
45+
Content-length: 19600
46+
Content-Type: text/html; charset=utf-8
47+
Date: Sat, 26 Oct 2013 01:49:21 GMT
48+
Link: <http://barryfrost.com/webmention>; rel=\"webmention\"");
49+
}
50+
51+
52+
}

tests/bootstrap.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
require dirname(__DIR__) . '/src/IndieWeb/link_rel_parser.php';
4+

0 commit comments

Comments
 (0)