Browse Source

strict type checking on properties

pull/39/head
Aaron Parecki 7 years ago
parent
commit
62697ee46b
3 changed files with 38 additions and 3 deletions
  1. +3
    -3
      lib/Formats/Mf2.php
  2. +13
    -0
      tests/AuthorTest.php
  3. +22
    -0
      tests/data/author.example.com/author-name-is-0

+ 3
- 3
lib/Formats/Mf2.php View File

@ -110,7 +110,7 @@ class Mf2 {
// Single plaintext values // Single plaintext values
$properties = ['url','published','summary','rsvp']; $properties = ['url','published','summary','rsvp'];
foreach($properties as $p) { foreach($properties as $p) {
if($v = self::getPlaintext($item, $p)) {
if(($v = self::getPlaintext($item, $p)) !== null) {
if($p == 'url') { if($p == 'url') {
if(self::isURL($v)) if(self::isURL($v))
$data[$p] = $v; $data[$p] = $v;
@ -235,7 +235,7 @@ class Mf2 {
// Single plaintext values // Single plaintext values
$properties = ['name','summary','url','published','start','end','duration']; $properties = ['name','summary','url','published','start','end','duration'];
foreach($properties as $p) { foreach($properties as $p) {
if($v = self::getPlaintext($item, $p)) {
if(($v = self::getPlaintext($item, $p)) !== null) {
if($p == 'url') { if($p == 'url') {
if(self::isURL($v)) if(self::isURL($v))
$data[$p] = $v; $data[$p] = $v;
@ -363,7 +363,7 @@ class Mf2 {
if(!$found && self::isURL($item['properties']['url'][0])) { if(!$found && self::isURL($item['properties']['url'][0])) {
$data['url'] = $item['properties']['url'][0]; $data['url'] = $item['properties']['url'][0];
} }
} else if($v = self::getPlaintext($item, $p)) {
} else if(($v = self::getPlaintext($item, $p)) !== null) {
// Make sure the URL property is actually a URL // Make sure the URL property is actually a URL
if($p == 'url' || $p == 'photo') { if($p == 'url' || $p == 'photo') {
if(self::isURL($v)) if(self::isURL($v))

+ 13
- 0
tests/AuthorTest.php View File

@ -138,6 +138,19 @@ class AuthorTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo); $this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo);
} }
public function testHEntryAuthorIs0() {
$url = 'http://author.example.com/author-name-is-0';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('card', $data->data->type);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo);
$this->assertEquals('0', $data->data->name);
}
/* /*
public function testHFeedHasHCardAuthor() { public function testHFeedHasHCardAuthor() {
$url = 'http://author.example.com/h-feed-has-h-card-author'; $url = 'http://author.example.com/h-feed-has-h-card-author';

+ 22
- 0
tests/data/author.example.com/author-name-is-0 View File

@ -0,0 +1,22 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Author</title>
</head>
<body>
<div class="h-card">
<a href="/author-name-is-0" class="u-url">
<img src="/photo.jpg" class="u-photo">
<span class="p-name">0</span>
</a>
</div>
</body>
</html>

Loading…
Cancel
Save