Skip to content

Commit c503c47

Browse files
authored
Merge pull request #210 from gRegorLove/issue198
Reduce instances where photo is implied
2 parents 14e8c5e + f0c9a91 commit c503c47

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ php:
66
- 7.0
77
- 7.1
88
- 7.2
9+
- 7.3
910
- nightly
1011
env:
1112
- COMPOSER_REQUIRE=""
1213
- COMPOSER_REQUIRE="composer require masterminds/html5"
14+
matrix:
15+
fast_finish: true
16+
allow_failures:
17+
- php: nightly
1318
install:
1419
- $COMPOSER_REQUIRE
1520
before_script: composer install

Mf2/Parser.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -1090,14 +1090,11 @@ public function parseH(\DOMElement $e, $is_backcompat = false, $has_nested_mf =
10901090
}
10911091

10921092
// Check for u-photo
1093-
if (!array_key_exists('photo', $return) && !$is_backcompat) {
1094-
1093+
if (!array_key_exists('photo', $return) && !in_array('u-', $prefixes) && !$has_nested_mf && !$is_backcompat) {
10951094
$photo = $this->parseImpliedPhoto($e);
1096-
10971095
if ($photo !== false) {
10981096
$return['photo'][] = $photo;
10991097
}
1100-
11011098
}
11021099

11031100
// Do we need to imply a url property?

tests/Mf2/ParseImpliedTest.php

+22
Original file line numberDiff line numberDiff line change
@@ -375,5 +375,27 @@ public function testNoImgSrcImpliedName() {
375375
$this->assertArrayHasKey('name', $result['items'][0]['properties']);
376376
$this->assertEquals('My Name', $result['items'][0]['properties']['name'][0]);
377377
}
378+
379+
/**
380+
* @see https://github.com/microformats/php-mf2/issues/198
381+
*/
382+
public function testNoImpliedPhotoWhenExplicitUProperty() {
383+
$input = '<div class="h-card"> <span class="p-org">Organization Name</span> <img src="/logo.png" class="u-logo" alt=""> </div>';
384+
$result = Mf2\parse($input);
385+
386+
$this->assertArrayNotHasKey('photo', $result['items'][0]['properties']);
387+
}
388+
389+
/**
390+
* @see https://github.com/microformats/php-mf2/issues/198
391+
*/
392+
public function testNoImpliedPhotoWhenNestedMicroformat() {
393+
$input = '<div class="h-entry"> <img src="/photo.jpg" alt=""> <div class="p-author h-card"> <span class="p-name">Alice</span> <span class="p-org">Organization Name</span> <img src="/logo.png" class="u-logo" alt=""> </div> </div>';
394+
$result = Mf2\parse($input);
395+
396+
$this->assertArrayNotHasKey('photo', $result['items'][0]['properties']);
397+
$this->assertArrayHasKey('author', $result['items'][0]['properties']);
398+
$this->assertArrayNotHasKey('photo', $result['items'][0]['properties']['author'][0]['properties']);
399+
}
378400
}
379401

0 commit comments

Comments
 (0)