Skip to content

Commit

Permalink
Add direction tests
Browse files Browse the repository at this point in the history
  • Loading branch information
murdercode committed Mar 2, 2024
1 parent 1124688 commit bc17155
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/Readability.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function parse(string $content): self
$this->content->parse($content);
} catch (ParseException $e) {
$this->content = null;
error_log('Cannot parse: '.$e->getMessage());
throw new Exception('Cannot parse: '.$e->getMessage());
error_log('Cannot parse: ' . $e->getMessage());
throw new Exception('Cannot parse: ' . $e->getMessage());
}

return $this;
Expand Down Expand Up @@ -110,7 +110,6 @@ public function getContent(): string
public function getDirection(): string
{
$this->checkContent();

return $this->content->getDirection();
}

Expand Down
6 changes: 6 additions & 0 deletions tests/ReadabilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
->and($images)->toContain('/static/img/bitcoin/privacy.svg');
});

it('can parse and get the direction', function () {
$html = file_get_contents(__DIR__.'/fixtures/demo.html');
$direction = Readability::parse($html)->getDirection();
expect($direction)->toBe('ltr');
});

it('can parse and get the content', function () {
$html = file_get_contents(__DIR__.'/fixtures/demo.html');
$readability = Readability::parse($html);
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ <h4>October 31, 2008</h4>


</div>
<div id="CONTENT" class="doc-content"><h2 id="abstract"><a href="#abstract">Abstract</a></h2>
<div id="CONTENT" class="doc-content" dir="ltr"><h2 id="abstract"><a href="#abstract">Abstract</a></h2>

<p>A purely peer-to-peer version of electronic cash would allow online payments to be sent directly from one party to another without going through a financial institution.

Expand Down

0 comments on commit bc17155

Please sign in to comment.