1212/**
1313 * @todo some of these can be made into single tests with dataProviders
1414 */
15- class ParseImpliedTest extends PHPUnit_Framework_TestCase {
15+ class ParseImpliedTest extends PHPUnit_Framework_TestCase {
1616 public function setUp () {
1717 date_default_timezone_set ('Europe/London ' );
1818 }
19-
20-
19+
20+
2121 public function testParsesImpliedPNameFromNodeValue () {
2222 $ input = '<span class="h-card">The Name</span> ' ;
2323 $ parser = new Parser ($ input );
2424 $ output = $ parser ->parse ();
25-
25+
2626 $ this ->assertArrayHasKey ('name ' , $ output ['items ' ][0 ]['properties ' ]);
2727 $ this ->assertEquals ('The Name ' , $ output ['items ' ][0 ]['properties ' ]['name ' ][0 ]);
2828 }
29-
29+
3030 public function testParsesImpliedPNameFromImgAlt () {
3131 $ input = '<img class="h-card" src="" alt="The Name" /> ' ;
3232 $ parser = new Parser ($ input );
3333 $ output = $ parser ->parse ();
34-
34+
3535 $ this ->assertArrayHasKey ('name ' , $ output ['items ' ][0 ]['properties ' ]);
3636 $ this ->assertEquals ('The Name ' , $ output ['items ' ][0 ]['properties ' ]['name ' ][0 ]);
3737 }
38-
38+
3939 public function testParsesImpliedPNameFromNestedImgAlt () {
4040 $ input = '<div class="h-card"><img src="" alt="The Name" /></div> ' ;
4141 $ parser = new Parser ($ input );
4242 $ output = $ parser ->parse ();
43-
43+
4444 $ this ->assertArrayHasKey ('name ' , $ output ['items ' ][0 ]['properties ' ]);
4545 $ this ->assertEquals ('The Name ' , $ output ['items ' ][0 ]['properties ' ]['name ' ][0 ]);
4646 }
47-
47+
4848 public function testParsesImpliedPNameFromDoublyNestedImgAlt () {
4949 $ input = '<div class="h-card"><span><img src="" alt="The Name" /></span></div> ' ;
5050 $ parser = new Parser ($ input );
5151 $ output = $ parser ->parse ();
52-
52+
5353 $ this ->assertArrayHasKey ('name ' , $ output ['items ' ][0 ]['properties ' ]);
5454 $ this ->assertEquals ('The Name ' , $ output ['items ' ][0 ]['properties ' ]['name ' ][0 ]);
5555 }
56-
56+
5757 public function testParsesImpliedUPhotoFromImgSrc () {
5858 $ input = '<img class="h-card" src="http://example.com/img.png" alt="" /> ' ;
5959 $ parser = new Parser ($ input );
6060 $ output = $ parser ->parse ();
61-
61+
6262 $ this ->assertArrayHasKey ('photo ' , $ output ['items ' ][0 ]['properties ' ]);
6363 $ this ->assertEquals ('http://example.com/img.png ' , $ output ['items ' ][0 ]['properties ' ]['photo ' ][0 ]);
6464 }
65-
65+
6666 public function testParsesImpliedUPhotoFromNestedImgSrc () {
6767 $ input = '<div class="h-card"><img src="http://example.com/img.png" alt="" /></div> ' ;
6868 $ parser = new Parser ($ input );
6969 $ output = $ parser ->parse ();
70-
70+
7171 $ this ->assertArrayHasKey ('photo ' , $ output ['items ' ][0 ]['properties ' ]);
7272 $ this ->assertEquals ('http://example.com/img.png ' , $ output ['items ' ][0 ]['properties ' ]['photo ' ][0 ]);
7373 }
74-
74+
7575 public function testParsesImpliedUPhotoFromDoublyNestedImgSrc () {
7676 $ input = '<div class="h-card"><span><img src="http://example.com/img.png" alt="" /></span></div> ' ;
7777 $ parser = new Parser ($ input );
7878 $ output = $ parser ->parse ();
79-
79+
8080 $ this ->assertArrayHasKey ('photo ' , $ output ['items ' ][0 ]['properties ' ]);
8181 $ this ->assertEquals ('http://example.com/img.png ' , $ output ['items ' ][0 ]['properties ' ]['photo ' ][0 ]);
8282 }
83-
83+
8484 /*
8585 * see testImpliedPhotoFromNestedObject() and testImpliedPhotoFromNestedObject()
8686 public function testIgnoresImgIfNotOnlyChild() {
8787 $input = '<div class="h-card"><img src="http://example.com/img.png" /> <p>Moar text</p></div>';
8888 $parser = new Parser($input);
8989 $output = $parser->parse();
90-
90+
9191 $this->assertArrayNotHasKey('photo', $output['items'][0]['properties']);
9292 }
9393
9494 public function testIgnoresDoublyNestedImgIfNotOnlyDoublyNestedChild() {
9595 $input = '<div class="h-card"><span><img src="http://example.com/img.png" /> <p>Moar text</p></span></div>';
9696 $parser = new Parser($input);
9797 $output = $parser->parse();
98-
98+
9999 $this->assertArrayNotHasKey('photo', $output['items'][0]['properties']);
100100 }
101101 */
102-
102+
103103 public function testParsesImpliedUUrlFromAHref () {
104104 $ input = '<a class="h-card" href="http://example.com/">Some Name</a> ' ;
105105 $ parser = new Parser ($ input );
106106 $ output = $ parser ->parse ();
107-
107+
108108 $ this ->assertArrayHasKey ('url ' , $ output ['items ' ][0 ]['properties ' ]);
109109 $ this ->assertEquals ('http://example.com/ ' , $ output ['items ' ][0 ]['properties ' ]['url ' ][0 ]);
110110 }
111-
112-
111+
112+
113113 public function testParsesImpliedUUrlFromNestedAHref () {
114114 $ input = '<span class="h-card"><a href="http://example.com/">Some Name</a></span> ' ;
115115 $ parser = new Parser ($ input );
116116 $ output = $ parser ->parse ();
117-
117+
118118 $ this ->assertArrayHasKey ('url ' , $ output ['items ' ][0 ]['properties ' ]);
119119 $ this ->assertEquals ('http://example.com/ ' , $ output ['items ' ][0 ]['properties ' ]['url ' ][0 ]);
120120 }
121-
121+
122+ public function testParsesImpliedUUrlWithExplicitName () {
123+ $ input = '<span class="h-card"><a href="http://example.com/" class="p-name">Some Name</a></span> ' ;
124+ $ parser = new Parser ($ input );
125+ $ output = $ parser ->parse ();
126+
127+ $ this ->assertArrayHasKey ('url ' , $ output ['items ' ][0 ]['properties ' ]);
128+ $ this ->assertEquals ('http://example.com/ ' , $ output ['items ' ][0 ]['properties ' ]['url ' ][0 ]);
129+ }
130+
131+ public function testParsesImpliedNameWithExplicitURL () {
132+ $ input = '<span class="h-card"><a href="http://example.com/" class="u-url">Some Name</a></span> ' ;
133+ $ parser = new Parser ($ input );
134+ $ output = $ parser ->parse ();
135+
136+ $ this ->assertArrayHasKey ('url ' , $ output ['items ' ][0 ]['properties ' ]);
137+ $ this ->assertEquals ('http://example.com/ ' , $ output ['items ' ][0 ]['properties ' ]['url ' ][0 ]);
138+ $ this ->assertEquals ('Some Name ' , $ output ['items ' ][0 ]['properties ' ]['name ' ][0 ]);
139+ }
140+
122141 public function testMultipleImpliedHCards () {
123142 $ input = '<span class="h-card">Frances Berriman</span>
124-
143+
125144<a class="h-card" href="http://benward.me">Ben Ward</a>
126-
127- <img class="h-card" alt="Sally Ride"
145+
146+ <img class="h-card" alt="Sally Ride"
128147 src="http://upload.wikimedia.org/wikipedia/commons/a/a4/Ride-s.jpg"/>
129-
148+
130149<a class="h-card" href="http://tantek.com">
131150 <img alt="Tantek Çelik" src="http://ttk.me/logo.jpg"/>
132151</a> ' ;
@@ -162,13 +181,13 @@ public function testMultipleImpliedHCards() {
162181 }
163182 }]
164183} ' ;
165-
184+
166185 $ parser = new Parser ($ input , '' , true );
167186 $ output = $ parser ->parse ();
168-
187+
169188 $ this ->assertJsonStringEqualsJsonString (json_encode ($ output ), $ expected );
170189 }
171-
190+
172191 /** as per https://github.com/indieweb/php-mf2/issues/37 */
173192 public function testParsesImpliedNameConsistentWithPName () {
174193 $ inner = "Name \nand more " ;
@@ -177,8 +196,8 @@ public function testParsesImpliedNameConsistentWithPName() {
177196 $ this ->assertEquals ($ inner , $ result ['items ' ][0 ]['properties ' ]['name ' ][0 ]);
178197 $ this ->assertEquals ($ inner , $ result ['items ' ][1 ]['properties ' ]['name ' ][0 ]);
179198 }
180-
181-
199+
200+
182201 /** @see https://github.com/indieweb/php-mf2/issues/6 */
183202 public function testParsesImpliedNameFromAbbrTitle () {
184203 $ input = '<abbr class="h-card" title="Barnaby Walters">BJW</abbr> ' ;
0 commit comments