Browse Source

Merge pull request #83 from sebsel/fix/card-with-entry

Fix h-entry with h-card before it
pull/87/head
Aaron Parecki 6 years ago
committed by GitHub
parent
commit
cd9706c3d1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 64 additions and 2 deletions
  1. +2
    -1
      .travis.yml
  2. +1
    -1
      lib/XRay/Formats/Mf2.php
  3. +24
    -0
      tests/ParseTest.php
  4. +18
    -0
      tests/data/source.example.com/h-entry-with-h-card-before-it
  5. +19
    -0
      tests/data/source.example.com/h-entry-with-two-h-cards-before-it

+ 2
- 1
.travis.yml View File

@ -10,9 +10,10 @@ before_script:
- composer self-update - composer self-update
- composer install --prefer-dist --no-interaction - composer install --prefer-dist --no-interaction
before_install: before_install:
- cp config.production.php config.php
before_deploy:
- openssl aes-256-cbc -K $encrypted_e44c58426490_key -iv $encrypted_e44c58426490_iv - openssl aes-256-cbc -K $encrypted_e44c58426490_key -iv $encrypted_e44c58426490_iv
-in XRay-67d8fdd0bba3.json.enc -out XRay-67d8fdd0bba3.json -d -in XRay-67d8fdd0bba3.json.enc -out XRay-67d8fdd0bba3.json -d
- cp config.production.php config.php
deploy: deploy:
skip_cleanup: true skip_cleanup: true
provider: gae provider: gae

+ 1
- 1
lib/XRay/Formats/Mf2.php View File

@ -42,7 +42,7 @@ class Mf2 extends Format {
// If there is only one item left on the page, it's a permalink, and just use that // If there is only one item left on the page, it's a permalink, and just use that
if(count($items) == 1) { if(count($items) == 1) {
$item = $mf2['items'][0];
$item = $items[0];
if(in_array('h-entry', $item['type']) || in_array('h-cite', $item['type'])) { if(in_array('h-entry', $item['type']) || in_array('h-cite', $item['type'])) {
#Parse::debug("mf2:0: Recognized $url as an h-entry it is the only item on the page"); #Parse::debug("mf2:0: Recognized $url as an h-entry it is the only item on the page");
return self::parseAsHEntry($mf2, $item, $http, $url); return self::parseAsHEntry($mf2, $item, $http, $url);

+ 24
- 0
tests/ParseTest.php View File

@ -436,6 +436,18 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('Primary Post', $data['data']['name']); $this->assertEquals('Primary Post', $data['data']['name']);
} }
public function testHEntryWithHCardBeforeIt() {
$url = 'http://source.example.com/h-entry-with-h-card-before-it';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('Hello World', $data['data']['content']['text']);
}
public function testHEntryWithHCardSibling() { public function testHEntryWithHCardSibling() {
$url = 'http://source.example.com/h-entry-with-h-card-sibling'; $url = 'http://source.example.com/h-entry-with-h-card-sibling';
$response = $this->parse(['url' => $url]); $response = $this->parse(['url' => $url]);
@ -448,6 +460,18 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('Hello World', $data['data']['content']['text']); $this->assertEquals('Hello World', $data['data']['content']['text']);
} }
public function testHEntryWithTwoHCardsBeforeIt() {
$url = 'http://source.example.com/h-entry-with-two-h-cards-before-it';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('Hello World', $data['data']['content']['text']);
}
public function testHEntryRedirectWithHCardSibling() { public function testHEntryRedirectWithHCardSibling() {
$url = 'http://source.example.com/h-entry-redirect-with-h-card-sibling'; $url = 'http://source.example.com/h-entry-redirect-with-h-card-sibling';
$response = $this->parse(['url' => $url]); $response = $this->parse(['url' => $url]);

+ 18
- 0
tests/data/source.example.com/h-entry-with-h-card-before-it View File

@ -0,0 +1,18 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
<html>
<head>
<title>Test</title>
</head>
<body>
<a href="/" class="h-card">Author Name</a>
<div class="h-entry">
<p class="p-content">Hello World</p>
<a href="/h-entry-with-h-card-before-it">permalink</a>
</div>
</body>
</html>

+ 19
- 0
tests/data/source.example.com/h-entry-with-two-h-cards-before-it View File

@ -0,0 +1,19 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
<html>
<head>
<title>Test</title>
</head>
<body>
<a href="/" class="h-card">Author Name</a>
<a href="http://example.com" class="h-card">Author Org</a>
<div class="h-entry">
<p class="p-content">Hello World</p>
<a href="/h-entry-with-two-h-cards-before-it">permalink</a>
</div>
</body>
</html>

Loading…
Cancel
Save