Commit a4bd3e0d authored by bhuvan krishna's avatar bhuvan krishna

Merge tag 'upstream/0.3.2'

parents 9f590765 dc0d90d4
language: php
php:
- 5.4
- 5.5
- 5.6
- 7.0
- nightly
before_script: composer install
# Creative Commons Legal Code
## CC0 1.0 Universal
http://creativecommons.org/publicdomain/zero/1.0
Official translations of this legal tool are available> CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER.
### _Statement of Purpose_
The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.
For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.
**1. Copyright and Related Rights.** A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:
1. the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
2. moral rights retained by the original author(s) and/or performer(s);
3. publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
4. rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
5. rights protecting the extraction, dissemination, use and reuse of data in a Work;
6. database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
7. other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
**2. Waiver.** To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.
**3. Public License Fallback.** Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.
**4. Limitations and Disclaimers.**
1. No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
2. Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
3. Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
4. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.
This diff is collapsed.
This diff is collapsed.
...@@ -31,9 +31,7 @@ if (!file_exists($url)) { ...@@ -31,9 +31,7 @@ if (!file_exists($url)) {
} }
} }
$html = file_get_contents($url); $result = Mf2\fetch($url);
$result = Mf2\parse($html, $url);
if (defined('JSON_PRETTY_PRINT')) { if (defined('JSON_PRETTY_PRINT')) {
echo json_encode($result, JSON_PRETTY_PRINT); echo json_encode($result, JSON_PRETTY_PRINT);
......
...@@ -4,23 +4,25 @@ ...@@ -4,23 +4,25 @@
"description": "A pure, generic microformats2 parser — makes HTML as easy to consume as a JSON API", "description": "A pure, generic microformats2 parser — makes HTML as easy to consume as a JSON API",
"keywords": ["microformats", "microformats 2", "parser", "semantic", "html"], "keywords": ["microformats", "microformats 2", "parser", "semantic", "html"],
"authors" : [ "authors" : [
{ {
"name": "Barnaby Walters", "name": "Barnaby Walters",
"homepage": "http://waterpigs.co.uk" "homepage": "http://waterpigs.co.uk"
} }
], ],
"bin": ["bin/fetch-mf2", "bin/parse-mf2"], "bin": ["bin/fetch-mf2", "bin/parse-mf2"],
"require": { "require": {
"php": ">=5.3.0" "php": ">=5.4.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "3.7.*" "phpunit/phpunit": "4.8.*",
"phpdocumentor/phpdocumentor": "v2.8.4",
"mf2/tests": "@dev"
}, },
"autoload": { "autoload": {
"files": ["Mf2/Parser.php"] "files": ["Mf2/Parser.php"]
}, },
"license": "MIT", "license": "CC0",
"suggest": { "suggest": {
"barnabywalters/mf-cleaner": "To more easily handle the canonical data php-mf2 gives you" "barnabywalters/mf-cleaner": "To more easily handle the canonical data php-mf2 gives you"
} }
} }
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
...@@ -195,8 +195,7 @@ class CombinedMicroformatsTest extends PHPUnit_Framework_TestCase { ...@@ -195,8 +195,7 @@ class CombinedMicroformatsTest extends PHPUnit_Framework_TestCase {
"properties": { "properties": {
"name": ["Mozilla Foundation"], "name": ["Mozilla Foundation"],
"url": ["http://mozilla.org/"] "url": ["http://mozilla.org/"]
}, }
"value": "Mozilla Foundation"
}] }]
}] }]
}'; }';
...@@ -230,6 +229,9 @@ class CombinedMicroformatsTest extends PHPUnit_Framework_TestCase { ...@@ -230,6 +229,9 @@ class CombinedMicroformatsTest extends PHPUnit_Framework_TestCase {
$input = '<div class="h-entry"><div class="h-card e-content"><p>Hello</p></div></div>'; $input = '<div class="h-entry"><div class="h-card e-content"><p>Hello</p></div></div>';
$mf = Mf2\parse($input); $mf = Mf2\parse($input);
$this->assertArrayHasKey('value', $mf['items'][0]['properties']['content'][0]);
$this->assertEquals($mf['items'][0]['properties']['content'][0]['value'], 'Hello');
$this->assertArrayHasKey('html', $mf['items'][0]['properties']['content'][0]);
$this->assertEquals($mf['items'][0]['properties']['content'][0]['html'], '<p>Hello</p>'); $this->assertEquals($mf['items'][0]['properties']['content'][0]['html'], '<p>Hello</p>');
} }
...@@ -242,6 +244,56 @@ class CombinedMicroformatsTest extends PHPUnit_Framework_TestCase { ...@@ -242,6 +244,56 @@ class CombinedMicroformatsTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($mf['items'][0]['properties']['url'][0]['value'], 'This should be the value'); $this->assertEquals($mf['items'][0]['properties']['url'][0]['value'], 'This should be the value');
} }
public function testMicroformatsNestedUnderUPropertyClassnamesDeriveValueFromURL() {
$input = '<div class="h-entry">
<h1 class="p-name">Name</h1>
<p class="e-content">Hello World</p>
<ul>
<li class="u-comment h-cite">
<a class="u-author h-card" href="http://jane.example.com/">Jane Bloggs</a>
<p class="p-content p-name">lol</p>
<a class="u-url" href="http://example.org/post1234"><time class="dt-published">2015-07-12 12:03</time></a>
</li>
</ul>
</div>';
$expected = '{
"items": [{
"type": ["h-entry"],
"properties": {
"name": ["Name"],
"content": [{
"html": "Hello World",
"value": "Hello World"
}],
"comment": [{
"type": ["h-cite"],
"properties": {
"author": [{
"type": ["h-card"],
"properties": {
"name": ["Jane Bloggs"],
"url": ["http:\/\/jane.example.com\/"]
},
"value": "http:\/\/jane.example.com\/"
}],
"content": ["lol"],
"name": ["lol"],
"url": ["http:\/\/example.org\/post1234"],
"published": ["2015-07-12 12:03"]
},
"value": "http:\/\/example.org\/post1234"
}]
}
}],
"rels":[]
}';
$mf = Mf2\parse($input);
$this->assertJsonStringEqualsJsonString(json_encode($mf), $expected);
$this->assertEquals($mf['items'][0]['properties']['comment'][0]['value'], 'http://example.org/post1234');
$this->assertEquals($mf['items'][0]['properties']['comment'][0]['properties']['author'][0]['value'], 'http://jane.example.com/');
}
public function testMicroformatsNestedUnderPPropertyClassnamesDeriveValueFromFirstPName() { public function testMicroformatsNestedUnderPPropertyClassnamesDeriveValueFromFirstPName() {
$input = '<div class="h-entry"><div class="p-author h-card">This post was written by <span class="p-name">Zoe</span>.</div></div>'; $input = '<div class="h-entry"><div class="p-author h-card">This post was written by <span class="p-name">Zoe</span>.</div></div>';
...@@ -249,4 +301,19 @@ class CombinedMicroformatsTest extends PHPUnit_Framework_TestCase { ...@@ -249,4 +301,19 @@ class CombinedMicroformatsTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($mf['items'][0]['properties']['author'][0]['value'], 'Zoe'); $this->assertEquals($mf['items'][0]['properties']['author'][0]['value'], 'Zoe');
} }
/**
* @see https://github.com/indieweb/php-mf2/issues/98
* @see https://github.com/microformats/tests/issues/58
*/
public function testNoValueForNestedMicroformatWithoutProperty() {
$input = '<div class="h-card" ><a class="h-card" href="jane.html">Jane Doe</a><p></p></div>';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayHasKey('children', $output['items'][0]);
$this->assertArrayNotHasKey('value', $output['items'][0]['children'][0]);
}
} }
...@@ -81,6 +81,8 @@ class ParseImpliedTest extends PHPUnit_Framework_TestCase { ...@@ -81,6 +81,8 @@ class ParseImpliedTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('http://example.com/img.png', $output['items'][0]['properties']['photo'][0]); $this->assertEquals('http://example.com/img.png', $output['items'][0]['properties']['photo'][0]);
} }
/*
* see testImpliedPhotoFromNestedObject() and testImpliedPhotoFromNestedObject()
public function testIgnoresImgIfNotOnlyChild() { public function testIgnoresImgIfNotOnlyChild() {
$input = '<div class="h-card"><img src="http://example.com/img.png" /> <p>Moar text</p></div>'; $input = '<div class="h-card"><img src="http://example.com/img.png" /> <p>Moar text</p></div>';
$parser = new Parser($input); $parser = new Parser($input);
...@@ -88,7 +90,7 @@ class ParseImpliedTest extends PHPUnit_Framework_TestCase { ...@@ -88,7 +90,7 @@ class ParseImpliedTest extends PHPUnit_Framework_TestCase {
$this->assertArrayNotHasKey('photo', $output['items'][0]['properties']); $this->assertArrayNotHasKey('photo', $output['items'][0]['properties']);
} }
public function testIgnoresDoublyNestedImgIfNotOnlyDoublyNestedChild() { public function testIgnoresDoublyNestedImgIfNotOnlyDoublyNestedChild() {
$input = '<div class="h-card"><span><img src="http://example.com/img.png" /> <p>Moar text</p></span></div>'; $input = '<div class="h-card"><span><img src="http://example.com/img.png" /> <p>Moar text</p></span></div>';
$parser = new Parser($input); $parser = new Parser($input);
...@@ -96,7 +98,7 @@ class ParseImpliedTest extends PHPUnit_Framework_TestCase { ...@@ -96,7 +98,7 @@ class ParseImpliedTest extends PHPUnit_Framework_TestCase {
$this->assertArrayNotHasKey('photo', $output['items'][0]['properties']); $this->assertArrayNotHasKey('photo', $output['items'][0]['properties']);
} }
*/
public function testParsesImpliedUUrlFromAHref() { public function testParsesImpliedUUrlFromAHref() {
$input = '<a class="h-card" href="http://example.com/">Some Name</a>'; $input = '<a class="h-card" href="http://example.com/">Some Name</a>';
...@@ -182,4 +184,73 @@ class ParseImpliedTest extends PHPUnit_Framework_TestCase { ...@@ -182,4 +184,73 @@ class ParseImpliedTest extends PHPUnit_Framework_TestCase {
$result = Mf2\parse($input); $result = Mf2\parse($input);
$this->assertEquals('Barnaby Walters', $result['items'][0]['properties']['name'][0]); $this->assertEquals('Barnaby Walters', $result['items'][0]['properties']['name'][0]);
} }
public function testImpliedPhotoFromObject() {
$input = '<object class="h-card" data="http://example/photo1.jpg">John Doe</object>';
$result = Mf2\parse($input);
$this->assertArrayHasKey('photo', $result['items'][0]['properties']);
$this->assertEquals('http://example/photo1.jpg', $result['items'][0]['properties']['photo'][0]);
}
/**
* Correcting previous test testIgnoresImgIfNotOnlyChild()
* This *should* return the photo since h-x>img[src]:only-of-type:not[.h-*]
* @see https://indiewebcamp.com/User:Tantek.com
*/
public function testImpliedPhotoFromNestedImg() {
$input = '<span class="h-card"><a href="http://tantek.com/" class="external text" style="border: 0px none;"><img src="https://pbs.twimg.com/profile_images/423350922408767488/nlA_m2WH.jpeg" style="width:128px;float:right;margin-left:1em"><b><span style="font-size:2em">Tantek Çelik</span></b></a></span>';
$result = Mf2\parse($input);
$this->assertArrayHasKey('photo', $result['items'][0]['properties']);
$this->assertEquals('https://pbs.twimg.com/profile_images/423350922408767488/nlA_m2WH.jpeg', $result['items'][0]['properties']['photo'][0]);
}
public function testIgnoredPhotoIfMultipleImg() {
$input = '<div class="h-card"><img src="http://example/photo2.jpg" /> <img src="http://example/photo3.jpg" /> </div>';
$result = Mf2\parse($input);
$this->assertArrayNotHasKey('photo', $result['items'][0]['properties']);
}
/**
* Correcting previous test testIgnoresDoublyNestedImgIfNotOnlyDoublyNestedChild()
* This *should* return the photo since .h-x>object[data]:only-of-type:not[.h-*]
*/
public function testImpliedPhotoFromNestedObject() {
$input = '<div class="h-card"><object data="http://example/photo3.jpg">John Doe</object> <p>Moar text</p></div>';
$result = Mf2\parse($input);
$this->assertArrayHasKey('photo', $result['items'][0]['properties']);
$this->assertEquals('http://example/photo3.jpg', $result['items'][0]['properties']['photo'][0]);
}
public function testIgnoredPhotoIfMultipleObject() {
$input = '<div class="h-card"><object data="http://example/photo3.jpg">John Doe</object> <object data="http://example/photo4.jpg"></object> </div>';
$result = Mf2\parse($input);
$this->assertArrayNotHasKey('photo', $result['items'][0]['properties']);
}
public function testIgnoredPhotoIfNestedImgH() {
$input = '<div class="h-entry"> <img src="http://example/photo2.jpg" class="h-card" /> </div>';
$result = Mf2\parse($input);
$this->assertArrayNotHasKey('photo', $result['items'][0]['properties']);
}
public function testIgnoredPhotoIfNestedImgHasHClass() {
$input = '<div class="h-entry"> <img src="http://example/photo2.jpg" alt="John Doe" class="h-card" /> </div>';
$result = Mf2\parse($input);
$this->assertArrayNotHasKey('photo', $result['items'][0]['properties']);
}
public function testIgnoredPhotoIfNestedObjectHasHClass() {
$input = '<div class="h-entry"> <object data="http://example/photo3.jpg" class="h-card">John Doe</object> </div>';
$result = Mf2\parse($input);
$this->assertArrayNotHasKey('photo', $result['items'][0]['properties']);
}
} }
This diff is collapsed.
...@@ -67,6 +67,18 @@ class ParsePTest extends PHPUnit_Framework_TestCase { ...@@ -67,6 +67,18 @@ class ParsePTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('Example User', $output['items'][0]['properties']['name'][0]); $this->assertEquals('Example User', $output['items'][0]['properties']['name'][0]);
} }
/**
* @group parseP
*/
public function testParsePHandlesDataWithBlankValueAttribute() {
$input = '<div class="h-card"><data class="p-name" value="">Example User</data></div>';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayHasKey('name', $output['items'][0]['properties']);
$this->assertEquals('', $output['items'][0]['properties']['name'][0]);
}
/** /**
* @group parseP * @group parseP
*/ */
...@@ -102,4 +114,28 @@ EOT; ...@@ -102,4 +114,28 @@ EOT;
$this->assertEquals('Blah blah http://waterpigs.co.uk/photos/five-legged-elephant.jpg', $result['items'][0]['properties']['summary'][0]); $this->assertEquals('Blah blah http://waterpigs.co.uk/photos/five-legged-elephant.jpg', $result['items'][0]['properties']['summary'][0]);
} }
/**
* @see https://github.com/indieweb/php-mf2/issues/69
*/
public function testBrWhitespaceIssue69() {
$input = '<div class="h-card"><p class="p-adr"><span class="p-street-address">Street Name 9</span><br/><span class="p-locality">12345 NY, USA</span></p></div>';
$result = Mf2\parse($input);
$this->assertEquals('Street Name 9' . "\n" . '12345 NY, USA', $result['items'][0]['properties']['adr'][0]);
$this->assertEquals('Street Name 9', $result['items'][0]['properties']['street-address'][0]);
$this->assertEquals('12345 NY, USA', $result['items'][0]['properties']['locality'][0]);
$this->assertEquals('Street Name 9' . "\n" . '12345 NY, USA', $result['items'][0]['properties']['name'][0]);
}
/**
* @see https://github.com/indieweb/php-mf2/issues/89
*/
public function testEmptyAlt() {
$input = '<div class="p-author h-card"><a href="/" class="p-org p-name"><img class="u-logo" src="/static/logo.jpg" alt="" />mention.tech</a></div>';
$result = Mf2\parse($input);
$this->assertEquals('mention.tech', $result['items'][0]['properties']['org'][0]);
$this->assertEquals('mention.tech', $result['items'][0]['properties']['name'][0]);
}
} }
...@@ -25,7 +25,31 @@ class ParseUTest extends PHPUnit_Framework_TestCase { ...@@ -25,7 +25,31 @@ class ParseUTest extends PHPUnit_Framework_TestCase {
$this->assertArrayHasKey('url', $output['items'][0]['properties']); $this->assertArrayHasKey('url', $output['items'][0]['properties']);
$this->assertEquals('http://example.com', $output['items'][0]['properties']['url'][0]); $this->assertEquals('http://example.com', $output['items'][0]['properties']['url'][0]);
} }
/**
* @group parseU
*/
public function testParseUHandlesEmptyHrefAttribute() {
$input = '<div class="h-card"><a class="u-url" href="">Awesome example website</a></div>';
$parser = new Parser($input, "http://example.com/");
$output = $parser->parse();
$this->assertArrayHasKey('url', $output['items'][0]['properties']);
$this->assertEquals('http://example.com/', $output['items'][0]['properties']['url'][0]);
}
/**
* @group parseU
*/
public function testParseUHandlesMissingHrefAttribute() {
$input = '<div class="h-card"><a class="u-url">Awesome example website</a></div>';
$parser = new Parser($input, "http://example.com/");
$output = $parser->parse();
$this->assertArrayHasKey('url', $output['items'][0]['properties']);
$this->assertEquals('Awesome example website', $output['items'][0]['properties']['url'][0]);
}
/** /**
* @group parseU * @group parseU
*/ */
...@@ -73,6 +97,18 @@ class ParseUTest extends PHPUnit_Framework_TestCase { ...@@ -73,6 +97,18 @@ class ParseUTest extends PHPUnit_Framework_TestCase {
$this->assertArrayHasKey('photo', $output['items'][0]['properties']); $this->assertArrayHasKey('photo', $output['items'][0]['properties']);
$this->assertEquals('http://example.com/someimage.png', $output['items'][0]['properties']['photo'][0]); $this->assertEquals('http://example.com/someimage.png', $output['items'][0]['properties']['photo'][0]);
} }
/**
* @group parseU
*/
public function testParseUHandlesAbbrNoTitle() {
$input = '<div class="h-card"><abbr class="u-photo">no title attribute</abbr></div>';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayHasKey('photo', $output['items'][0]['properties']);
$this->assertEquals('no title attribute', $output['items'][0]['properties']['photo'][0]);
}
/** /**
* @group parseU * @group parseU
...@@ -161,6 +197,17 @@ class ParseUTest extends PHPUnit_Framework_TestCase { ...@@ -161,6 +197,17 @@ class ParseUTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('http://example.com/video.mp4', $output['items'][0]['properties']['video'][0]); $this->assertEquals('http://example.com/video.mp4', $output['items'][0]['properties']['video'][0]);
} }
/**
* @group parseU
*/
public function testParseUHandlesVideoNoSrc() {
$input = '<div class="h-entry"><video class="u-video">no video support</video></div>';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayHasKey('video', $output['items'][0]['properties']);
$this->assertEquals('no video support', $output['items'][0]['properties']['video'][0]);
}
/** /**
* @group parseU * @group parseU
...@@ -175,4 +222,30 @@ class ParseUTest extends PHPUnit_Framework_TestCase { ...@@ -175,4 +222,30 @@ class ParseUTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('http://example.com/video.ogg', $output['items'][0]['properties']['video'][1]); $this->assertEquals('http://example.com/video.ogg', $output['items'][0]['properties']['video'][1]);
} }
/**
* @group parseU
*/
public function testParseUHandlesVideoPoster() {
$input = '<div class="h-entry"><video class="u-photo" poster="http://example.com/posterimage.jpg"><source class="u-video" src="http://example.com/video.mp4" type="video/mp4"></video></div>';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayHasKey('video', $output['items'][0]['properties']);
$this->assertEquals('http://example.com/video.mp4', $output['items'][0]['properties']['video'][0]);
$this->assertEquals('http://example.com/posterimage.jpg', $output['items'][0]['properties']['photo'][0]);
}
/**
* @group parseU
*/
public function testParseUWithSpaces() {
$input = '<div class="h-card"><a class="u-url" href=" http://example.com ">Awesome example website</a></div>';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayHasKey('url', $output['items'][0]['properties']);
$this->assertEquals('http://example.com', $output['items'][0]['properties']['url'][0]);
}
} }
This diff is collapsed.
<?php
/**
* Tests of the parsing methods within mf2\Parser
*/
namespace Mf2\Parser\Test;
use Mf2;
use Mf2\Parser;
use PHPUnit_Framework_TestCase;
class RelTest extends PHPUnit_Framework_TestCase {
public function setUp() {
date_default_timezone_set('Europe/London');
}
public function testRelValueOnLinkTag() {
$input = '<link rel="webmention" href="http://example.com/webmention">';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayHasKey('webmention', $output['rels']);
$this->assertEquals('http://example.com/webmention', $output['rels']['webmention'][0]);
}
public function testRelValueOnATag() {
$input = '<a rel="webmention" href="http://example.com/webmention">webmention me</a>';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayHasKey('webmention', $output['rels']);
$this->assertEquals('http://example.com/webmention', $output['rels']['webmention'][0]);
}
public function testRelValueOnAreaTag() {
$input = '<map><area rel="webmention" href="http://example.com/webmention"/></map>';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayHasKey('webmention', $output['rels']);
$this->assertEquals('http://example.com/webmention', $output['rels']['webmention'][0]);
}
public function testRelValueOrder() {
$input = '<map><area rel="webmention" href="http://example.com/area"/></map>
<a rel="webmention" href="http://example.com/a">webmention me</a>
<link rel="webmention" href="http://example.com/link">';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayHasKey('webmention', $output['rels']);
$this->assertEquals('http://example.com/area', $output['rels']['webmention'][0]);
$this->assertEquals('http://example.com/a', $output['rels']['webmention'][1]);
$this->assertEquals('http://example.com/link', $output['rels']['webmention'][2]);
}
public function testRelValueOrder2() {
$input = '<map><area rel="webmention" href="http://example.com/area"/></map>
<link rel="webmention" href="http://example.com/link">
<a rel="webmention" href="http://example.com/a">webmention me</a>';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayHasKey('webmention', $output['rels']);
$this->assertEquals('http://example.com/area', $output['rels']['webmention'][0]);
$this->assertEquals('http://example.com/link', $output['rels']['webmention'][1]);
$this->assertEquals('http://example.com/a', $output['rels']['webmention'][2]);
}
public function testRelValueOrder3() {
$input = '<html>
<head>
<link rel="webmention" href="http://example.com/link">
</head>
<body>
<a rel="webmention" href="http://example.com/a">webmention me</a>
<map><area rel="webmention" href="http://example.com/area"/></map>
</body>
</html>';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayHasKey('webmention', $output['rels']);
$this->assertEquals('http://example.com/link', $output['rels']['webmention'][0]);
$this->assertEquals('http://example.com/a', $output['rels']['webmention'][1]);
$this->assertEquals('http://example.com/area', $output['rels']['webmention'][2]);
}
public function testRelValueOnBTag() {
$input = '<b rel="webmention" href="http://example.com/webmention">this makes no sense</b>';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayNotHasKey('webmention', $output['rels']);
}
}
...@@ -212,9 +212,6 @@ class UrlTest extends PHPUnit_Framework_TestCase { ...@@ -212,9 +212,6 @@ class UrlTest extends PHPUnit_Framework_TestCase {
array('relative add host from base', array('relative add host from base',
'http://www.example.com', 'server.php', 'http://www.example.com/server.php'), 'http://www.example.com', 'server.php', 'http://www.example.com/server.php'),
array('relative add scheme host user from base',
'http://user:@www.example.com', 'server.php', 'http://user:@www.example.com/server.php'),
array('relative add scheme host pass from base', array('relative add scheme host pass from base',
'http://:pass@www.example.com', 'server.php', 'http://:pass@www.example.com/server.php'), 'http://:pass@www.example.com', 'server.php', 'http://:pass@www.example.com/server.php'),
...@@ -256,6 +253,15 @@ class UrlTest extends PHPUnit_Framework_TestCase { ...@@ -256,6 +253,15 @@ class UrlTest extends PHPUnit_Framework_TestCase {
); );
// PHP 5.4 and before returns a different result, but either are acceptable
if(PHP_MAJOR_VERSION <= 5 && PHP_MINOR_VERSION <= 4) {
$cases[] = array('relative add scheme host user from base',
'http://user:@www.example.com', 'server.php', 'http://user@www.example.com/server.php');
} else {
$cases[] = array('relative add scheme host user from base',
'http://user:@www.example.com', 'server.php', 'http://user:@www.example.com/server.php');
}
// Test cases from RFC // Test cases from RFC
// http://tools.ietf.org/html/rfc3986#section-5.4 // http://tools.ietf.org/html/rfc3986#section-5.4
......
<?php <?php
/** /**
* php-mf2 test suite * microformats test suite for php-mf2
* CLI usage from the tests/test-suite/ directory: php test-suite.php *
* @see https://github.com/tobiastom/tests * Before running this test suite, ensure that you run composer install
* to install the microformats/tests repository of tests.
* @see https://github.com/microformats/tests
* *
* This will look through the specified directory for suite.json files * CLI usage from library root directory: php ./tests/test-suite/test-suite.php
* that represent a suite of tests. Then, for each suite the sub-directories
* will be parsed for input.html, output.json, and test.json files. Each
* test will then be executed. If a test fails, a message is displayed along
* with the parsed output (array format) and the expected output (array format).
* *
* Individual test suites may be run by calling TestSuite->runSuite($path) * This will look through the test directories for .html files that
* where $path is the file path to the suite.json file. * represent a test and the corresponding .json file that represent
* the expected output. If a test fails, a message is displayed along
* with the parsed output and the expected output, both in array format.
*
* Individual test suites may be run by specifying the relative path within the repo.
* For example, to run only the 'microformats-v2' tests:
* php ./tests/test-suite/test-suite.php microformats-v2
*/ */
namespace Mf2\Parser\TestSuite; namespace Mf2\Parser\TestSuite;
...@@ -20,6 +24,7 @@ namespace Mf2\Parser\TestSuite; ...@@ -20,6 +24,7 @@ namespace Mf2\Parser\TestSuite;
use Mf2\Parser; use Mf2\Parser;
use Mf2; use Mf2;
error_reporting(E_ALL);
require dirname(__DIR__) . '/../vendor/autoload.php'; require dirname(__DIR__) . '/../vendor/autoload.php';
class TestSuite class TestSuite
...@@ -39,8 +44,16 @@ class TestSuite ...@@ -39,8 +44,16 @@ class TestSuite
* @param string $path: path to test-suite-data * @param string $path: path to test-suite-data
* @access public * @access public
*/ */
public function __construct($path = './test-suite-data/') public function __construct($path = '')
{ {
$path = './vendor/microformats/test/tests/' . $path;
if ( !file_exists($path) )
{
echo sprintf('Specified path was not found: %s', $path), "\n";
exit;
}
$this->path = $path; $this->path = $path;
} # end method __construct() } # end method __construct()
...@@ -53,14 +66,13 @@ class TestSuite ...@@ -53,14 +66,13 @@ class TestSuite
*/ */
public function start() public function start()
{ {
$directory = new \RecursiveDirectoryIterator($this->path); $directory = new \RecursiveDirectoryIterator($this->path, \RecursiveDirectoryIterator::SKIP_DOTS);