mirror of
https://github.com/j0k3r/php-readability.git
synced 2026-09-27 06:26:17 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b47e2f1de | ||
|
|
c756ec067e | ||
|
|
8ab7d76cd5 | ||
|
|
149a333b40 | ||
|
|
209c404d7b | ||
|
|
6e3f2e8c0b | ||
|
|
8cbecd7e99 | ||
|
|
438699ab15 | ||
|
|
ea7a62d352 | ||
|
|
9181fd1a2c | ||
|
|
2951936e00 | ||
|
|
92965f76cf | ||
|
|
850ade16b6 | ||
|
|
dc590542f0 | ||
|
|
41d7440c6e | ||
|
|
252bb4ef42 | ||
|
|
7c30d76b6e | ||
|
|
111cb08034 | ||
|
|
74fbf6f009 | ||
|
|
1565a6819a | ||
|
|
f71c3a4196 | ||
|
|
255a2fc7bc | ||
|
|
b77876b30a | ||
|
|
1830dc45d4 | ||
|
|
6be1f9b984 | ||
|
|
175196d6c2 | ||
|
|
2b5af601d5 | ||
|
|
d01eb2ac1e | ||
|
|
c5a4a490e1 | ||
|
|
908a49824f | ||
|
|
c67189248e | ||
|
|
91b80b70e2 | ||
|
|
8667dae74b | ||
|
|
eecae93161 | ||
|
|
814c6e4730 |
@@ -0,0 +1,8 @@
|
|||||||
|
/.editorconfig export-ignore
|
||||||
|
/.gitattributes export-ignore
|
||||||
|
/.gitignore export-ignore
|
||||||
|
/.scrutinizer.yml export-ignore
|
||||||
|
/.travis.yml export-ignore
|
||||||
|
/README.md export-ignore
|
||||||
|
/phpunit.xml.dist export-ignore
|
||||||
|
/tests export-ignore
|
||||||
+1
-2
@@ -1,3 +1,2 @@
|
|||||||
tools:
|
tools:
|
||||||
external_code_coverage:
|
external_code_coverage: false
|
||||||
timeout: 600
|
|
||||||
|
|||||||
+19
-9
@@ -1,32 +1,42 @@
|
|||||||
language: php
|
language: php
|
||||||
|
|
||||||
php:
|
php:
|
||||||
|
- 5.3.3
|
||||||
|
- 5.3
|
||||||
- 5.4
|
- 5.4
|
||||||
- 5.5
|
- 5.5
|
||||||
- 5.6
|
- 5.6
|
||||||
- nightly
|
- 7.0
|
||||||
- hhvm-nightly
|
- hhvm
|
||||||
|
|
||||||
# run build against nightly but allow them to fail
|
|
||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- php: nightly
|
- php: hhvm
|
||||||
- php: hhvm-nightly
|
|
||||||
|
|
||||||
# faster builds on new travis setup not using sudo
|
# faster builds on new travis setup not using sudo
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|
||||||
|
# cache vendor dirs
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- vendor
|
||||||
|
- $HOME/.composer/cache
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- composer self-update
|
- composer self-update
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
|
- if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi;
|
||||||
|
# disable TLS for composer because openssl is disabled for PHP 5.3.3 on travis
|
||||||
|
# see: https://blog.travis-ci.com/upcoming_ubuntu_11_10_migration/
|
||||||
|
- if [[ $TRAVIS_PHP_VERSION = 5.3.3 ]]; then composer config -g -- disable-tls true; fi;
|
||||||
|
- if [[ $TRAVIS_PHP_VERSION = 5.3.3 ]]; then composer config -g -- secure-http false; fi;
|
||||||
- composer install --prefer-dist --no-interaction
|
- composer install --prefer-dist --no-interaction
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- phpunit --coverage-clover=coverage.clover
|
- mkdir -p build/logs
|
||||||
|
- phpunit -v --coverage-clover build/logs/clover.xml
|
||||||
|
|
||||||
after_script:
|
after_script:
|
||||||
- |
|
- php vendor/bin/coveralls -v
|
||||||
wget https://scrutinizer-ci.com/ocular.phar
|
|
||||||
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
# Readability
|
# Readability
|
||||||
|
|
||||||
[](https://travis-ci.org/j0k3r/php-readability)
|
[](https://travis-ci.org/j0k3r/php-readability)
|
||||||
[](https://scrutinizer-ci.com/g/j0k3r/php-readability/?branch=master)
|
[](https://coveralls.io/github/j0k3r/php-readability/?branch=master)
|
||||||
|
|
||||||
This is an extract of the Readability class from the [full-text-rss](https://github.com/Dither/full-text-rss) fork. It kind be defined as a better version of the original [php-readability](http://code.fivefilters.org/php-readability).
|
This is an extract of the Readability class from this [full-text-rss](https://github.com/Dither/full-text-rss) fork. It can be defined as a better version of the original [php-readability](https://bitbucket.org/fivefilters/php-readability/overview).
|
||||||
|
|
||||||
## Differences
|
## Differences
|
||||||
|
|
||||||
The default php-readability lib is really old and needs to be improved. I found a great fork of [full-text-rss](http://fivefilters.org/content-only/) from @Dither which improve the Readability class.
|
The default php-readability lib is really old and needs to be improved. I found a great fork of full-text-rss from [@Dither](https://github.com/Dither/full-text-rss) which improve the Readability class.
|
||||||
|
|
||||||
- I've extracted the class from its fork to be able to use it out of the box
|
- I've extracted the class from its fork to be able to use it out of the box
|
||||||
- I've added some simple tests
|
- I've added some simple tests
|
||||||
@@ -15,6 +15,12 @@ The default php-readability lib is really old and needs to be improved. I found
|
|||||||
|
|
||||||
**But** the code is still really hard to understand / read ...
|
**But** the code is still really hard to understand / read ...
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
By default, this lib will use the [Tidy extension](https://github.com/htacg/tidy-html5) if it's available. Tidy is only used to cleanup the given HTML and avoid problems with bad HTML structure, etc ..
|
||||||
|
|
||||||
|
Since Composer doesn't support suggestion on PHP extension, I write this suggestion here.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```php
|
```php
|
||||||
@@ -26,6 +32,8 @@ $url = 'http://www.medialens.org/index.php/alerts/alert-archive/alerts-2013/729-
|
|||||||
$html = file_get_contents($url);
|
$html = file_get_contents($url);
|
||||||
|
|
||||||
$readability = new Readability($html, $url);
|
$readability = new Readability($html, $url);
|
||||||
|
// or without Tidy
|
||||||
|
// $readability = new Readability($html, $url, 'libxml', false);
|
||||||
$result = $readability->init();
|
$result = $readability->init();
|
||||||
|
|
||||||
if ($result) {
|
if ($result) {
|
||||||
@@ -37,3 +45,20 @@ if ($result) {
|
|||||||
echo 'Looks like we couldn\'t find the content. :(';
|
echo 'Looks like we couldn\'t find the content. :(';
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you want to debug it, or check what's going on, you can inject a logger (which must follow `Psr\Log\LoggerInterface`, Monolog for example):
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Readability\Readability;
|
||||||
|
use Monolog\Logger;
|
||||||
|
use Monolog\Handler\StreamHandler;
|
||||||
|
|
||||||
|
$url = 'http://www.medialens.org/index.php/alerts/alert-archive/alerts-2013/729-thatcher.html';
|
||||||
|
$html = file_get_contents($url);
|
||||||
|
|
||||||
|
$logger = new Logger('readability');
|
||||||
|
$logger->pushHandler(new StreamHandler('path/to/your.log', Logger::DEBUG));
|
||||||
|
|
||||||
|
$readability = new Readability($html, $url);
|
||||||
|
$readability->setLogger($logger);
|
||||||
|
```
|
||||||
|
|||||||
+5
-2
@@ -24,8 +24,11 @@
|
|||||||
"role": "Developer (original JS version)"
|
"role": "Developer (original JS version)"
|
||||||
}],
|
}],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.4",
|
"php": ">=5.3.3",
|
||||||
"ext-tidy": ">=1.2"
|
"monolog/monolog": "^1.13.1"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"satooshi/php-coveralls": "~0.6"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "Readability\\": "src/" }
|
"psr-4": { "Readability\\": "src/" }
|
||||||
|
|||||||
+3
-3
@@ -26,7 +26,7 @@
|
|||||||
</whitelist>
|
</whitelist>
|
||||||
</filter>
|
</filter>
|
||||||
|
|
||||||
<logging>
|
<!-- <logging>
|
||||||
<log type="coverage-html" target="coverage" title="FullText" charset="UTF-8" yui="true" highlight="true" lowUpperBound="35" highLowerBound="70"/>
|
<log type="coverage-html" target="coverage" title="Readability" charset="UTF-8" yui="true" highlight="true" lowUpperBound="35" highLowerBound="70"/>
|
||||||
</logging>
|
</logging> -->
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|||||||
@@ -47,14 +47,17 @@ class JSLikeHTMLElement extends \DOMElement
|
|||||||
{
|
{
|
||||||
if ($name == 'innerHTML') {
|
if ($name == 'innerHTML') {
|
||||||
// first, empty the element
|
// first, empty the element
|
||||||
for ($x = $this->childNodes->length - 1; $x >= 0; $x--) {
|
for ($x = $this->childNodes->length - 1; $x >= 0; --$x) {
|
||||||
$this->removeChild($this->childNodes->item($x));
|
$this->removeChild($this->childNodes->item($x));
|
||||||
}
|
}
|
||||||
|
|
||||||
// $value holds our new inner HTML
|
// $value holds our new inner HTML
|
||||||
if ($value != '') {
|
if ($value != '') {
|
||||||
$f = $this->ownerDocument->createDocumentFragment();
|
$f = $this->ownerDocument->createDocumentFragment();
|
||||||
|
|
||||||
// appendXML() expects well-formed markup (XHTML)
|
// appendXML() expects well-formed markup (XHTML)
|
||||||
$result = @$f->appendXML($value); // @ to suppress PHP warnings
|
// @ to suppress PHP warnings
|
||||||
|
$result = @$f->appendXML($value);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
if ($f->hasChildNodes()) {
|
if ($f->hasChildNodes()) {
|
||||||
$this->appendChild($f);
|
$this->appendChild($f);
|
||||||
@@ -63,14 +66,17 @@ class JSLikeHTMLElement extends \DOMElement
|
|||||||
// $value is probably ill-formed
|
// $value is probably ill-formed
|
||||||
$f = new \DOMDocument();
|
$f = new \DOMDocument();
|
||||||
$value = mb_convert_encoding($value, 'HTML-ENTITIES', 'UTF-8');
|
$value = mb_convert_encoding($value, 'HTML-ENTITIES', 'UTF-8');
|
||||||
|
|
||||||
// Using <htmlfragment> will generate a warning, but so will bad HTML
|
// Using <htmlfragment> will generate a warning, but so will bad HTML
|
||||||
// (and by this point, bad HTML is what we've got).
|
// (and by this point, bad HTML is what we've got).
|
||||||
// We use it (and suppress the warning) because an HTML fragment will
|
// We use it (and suppress the warning) because an HTML fragment will
|
||||||
// be wrapped around <html><body> tags which we don't really want to keep.
|
// be wrapped around <html><body> tags which we don't really want to keep.
|
||||||
// Note: despite the warning, if loadHTML succeeds it will return true.
|
// Note: despite the warning, if loadHTML succeeds it will return true.
|
||||||
$result = @$f->loadHTML('<htmlfragment>'.$value.'</htmlfragment>');
|
$result = @$f->loadHTML('<htmlfragment>'.$value.'</htmlfragment>');
|
||||||
|
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$import = $f->getElementsByTagName('htmlfragment')->item(0);
|
$import = $f->getElementsByTagName('htmlfragment')->item(0);
|
||||||
|
|
||||||
foreach ($import->childNodes as $child) {
|
foreach ($import->childNodes as $child) {
|
||||||
$importedNode = $this->ownerDocument->importNode($child, true);
|
$importedNode = $this->ownerDocument->importNode($child, true);
|
||||||
$this->appendChild($importedNode);
|
$this->appendChild($importedNode);
|
||||||
@@ -98,6 +104,7 @@ class JSLikeHTMLElement extends \DOMElement
|
|||||||
{
|
{
|
||||||
if ($name == 'innerHTML') {
|
if ($name == 'innerHTML') {
|
||||||
$inner = '';
|
$inner = '';
|
||||||
|
|
||||||
foreach ($this->childNodes as $child) {
|
foreach ($this->childNodes as $child) {
|
||||||
$inner .= $this->ownerDocument->saveXML($child);
|
$inner .= $this->ownerDocument->saveXML($child);
|
||||||
}
|
}
|
||||||
|
|||||||
+488
-300
File diff suppressed because it is too large
Load Diff
+289
-50
@@ -3,98 +3,127 @@
|
|||||||
namespace Tests\Readability;
|
namespace Tests\Readability;
|
||||||
|
|
||||||
use Readability\Readability;
|
use Readability\Readability;
|
||||||
|
use Monolog\Logger;
|
||||||
class ReadabilityTested extends Readability
|
use Monolog\Handler\TestHandler;
|
||||||
{
|
|
||||||
public function getDebugText()
|
|
||||||
{
|
|
||||||
return $this->debugText;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDomainRegexp()
|
|
||||||
{
|
|
||||||
return $this->domainRegExp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ReadabilityTest extends \PHPUnit_Framework_TestCase
|
class ReadabilityTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testConstructDefault()
|
public $logHandler;
|
||||||
{
|
public $logger;
|
||||||
$readability = new ReadabilityTested('');
|
|
||||||
|
|
||||||
$this->assertNull($readability->url);
|
private function getReadability($html, $url = null, $parser = 'libxml', $useTidy = true)
|
||||||
$this->assertContains('Parsing URL', $readability->getDebugText());
|
{
|
||||||
$this->assertContains('Tidying document', $readability->getDebugText());
|
$readability = new Readability($html, $url, $parser, $useTidy);
|
||||||
$this->assertNull($readability->getDomainRegexp());
|
|
||||||
$this->assertInstanceOf('DomDocument', $readability->dom);
|
$this->logHandler = new TestHandler();
|
||||||
|
$this->logger = new Logger('test', array($this->logHandler));
|
||||||
|
$readability->setLogger($this->logger);
|
||||||
|
|
||||||
|
return $readability;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testConstructSimple()
|
public function testConstructSimple()
|
||||||
{
|
{
|
||||||
$readability = new ReadabilityTested('<html/>', 'http://0.0.0.0');
|
$readability = $this->getReadability('<html/>', 'http://0.0.0.0');
|
||||||
|
$readability->init();
|
||||||
|
|
||||||
$this->assertEquals('http://0.0.0.0', $readability->url);
|
$this->assertEquals('http://0.0.0.0', $readability->url);
|
||||||
$this->assertContains('Parsing URL', $readability->getDebugText());
|
$this->assertEquals('<html/>', $readability->original_html);
|
||||||
$this->assertContains('Tidying document', $readability->getDebugText());
|
$this->assertTrue($readability->tidied);
|
||||||
$this->assertEquals('/0\.0\.0\.0/', $readability->getDomainRegexp());
|
|
||||||
$this->assertInstanceOf('DomDocument', $readability->dom);
|
$this->assertTrue($this->logHandler->hasDebugThatContains('Parsing URL: http://0.0.0.0'));
|
||||||
|
$this->assertTrue($this->logHandler->hasDebugThatContains('Tidying document'));
|
||||||
|
$this->assertTrue($this->logHandler->hasDebugThatContains('Light clean enabled.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConstructDefaultWithoutTidy()
|
||||||
|
{
|
||||||
|
$readability = $this->getReadability('', null, 'libxml', false);
|
||||||
|
$readability->init();
|
||||||
|
|
||||||
|
$this->assertNull($readability->url);
|
||||||
|
$this->assertEquals('', $readability->original_html);
|
||||||
|
$this->assertFalse($readability->tidied);
|
||||||
|
|
||||||
|
$this->assertTrue($this->logHandler->hasDebugThatContains('Parsing URL: '));
|
||||||
|
$this->assertFalse($this->logHandler->hasDebugThatContains('Tidying document'));
|
||||||
|
$this->assertTrue($this->logHandler->hasDebugThatContains('Light clean enabled.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConstructSimpleWithoutTidy()
|
||||||
|
{
|
||||||
|
$readability = $this->getReadability('<html/>', 'http://0.0.0.0', 'libxml', false);
|
||||||
|
$readability->init();
|
||||||
|
|
||||||
|
$this->assertEquals('http://0.0.0.0', $readability->url);
|
||||||
|
$this->assertEquals('<html/>', $readability->original_html);
|
||||||
|
$this->assertFalse($readability->tidied);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInitNoContent()
|
public function testInitNoContent()
|
||||||
{
|
{
|
||||||
$readability = new ReadabilityTested('<html/>', 'http://0.0.0.0');
|
$readability = $this->getReadability('<html/>', 'http://0.0.0.0');
|
||||||
$res = $readability->init();
|
$res = $readability->init();
|
||||||
|
|
||||||
$this->assertFalse($res);
|
$this->assertFalse($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
||||||
$this->assertContains('Sorry, Readability was unable to parse this page for content.', $readability->getContent()->innerHTML);
|
$this->assertContains('Sorry, Readability was unable to parse this page for content.', $readability->getContent()->innerHTML);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInitP()
|
public function testInitP()
|
||||||
{
|
{
|
||||||
$readability = new ReadabilityTested(str_repeat('<p>This is the awesome content :)</p>', 7), 'http://0.0.0.0');
|
$readability = $this->getReadability(str_repeat('<p>This is the awesome content :)</p>', 7), 'http://0.0.0.0');
|
||||||
$res = $readability->init();
|
$res = $readability->init();
|
||||||
|
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
||||||
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
||||||
$this->assertContains('This is the awesome content :)', $readability->getContent()->innerHTML);
|
$this->assertContains('This is the awesome content :)', $readability->getContent()->innerHTML);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInitDivP()
|
public function testInitDivP()
|
||||||
{
|
{
|
||||||
$readability = new ReadabilityTested('<div>'.str_repeat('<p>This is the awesome content :)</p>', 7).'</div>', 'http://0.0.0.0');
|
$readability = $this->getReadability('<div>'.str_repeat('<p>This is the awesome content :)</p>', 7).'</div>', 'http://0.0.0.0');
|
||||||
$res = $readability->init();
|
$res = $readability->init();
|
||||||
|
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
||||||
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
||||||
$this->assertContains('This is the awesome content :)', $readability->getContent()->innerHTML);
|
$this->assertContains('This is the awesome content :)', $readability->getContent()->innerHTML);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInitDiv()
|
public function testInitDiv()
|
||||||
{
|
{
|
||||||
$readability = new ReadabilityTested('<div>'.str_repeat('This is the awesome content :)', 7).'</div>', 'http://0.0.0.0');
|
$readability = $this->getReadability('<div>'.str_repeat('This is the awesome content :)', 7).'</div>', 'http://0.0.0.0');
|
||||||
$readability->debug = true;
|
$readability->debug = true;
|
||||||
$res = $readability->init();
|
$res = $readability->init();
|
||||||
|
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
||||||
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
||||||
$this->assertContains('This is the awesome content :)', $readability->getContent()->innerHTML);
|
$this->assertContains('This is the awesome content :)', $readability->getContent()->innerHTML);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithFootnotes()
|
public function testWithFootnotes()
|
||||||
{
|
{
|
||||||
$readability = new ReadabilityTested('<div>'.str_repeat('<p>This is an awesome text with some links, here there are: <a href="http://0.0.0.0/test.html">the awesome</a></p>', 7).'</div>', 'http://0.0.0.0');
|
$readability = $this->getReadability('<div>'.str_repeat('<p>This is an awesome text with some links, here there are: <a href="http://0.0.0.0/test.html">the awesome</a></p>', 7).'</div>', 'http://0.0.0.0');
|
||||||
$readability->debug = true;
|
$readability->debug = true;
|
||||||
$readability->convertLinksToFootnotes = true;
|
$readability->convertLinksToFootnotes = true;
|
||||||
$res = $readability->init();
|
$res = $readability->init();
|
||||||
|
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
||||||
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
||||||
$this->assertContains('readabilityFootnoteLink', $readability->getContent()->innerHTML);
|
$this->assertContains('readabilityFootnoteLink', $readability->getContent()->innerHTML);
|
||||||
$this->assertContains('readabilityLink-3', $readability->getContent()->innerHTML);
|
$this->assertContains('readabilityLink-3', $readability->getContent()->innerHTML);
|
||||||
@@ -102,118 +131,328 @@ class ReadabilityTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testStandardClean()
|
public function testStandardClean()
|
||||||
{
|
{
|
||||||
$readability = new ReadabilityTested('<div><h2>Title</h2>'.str_repeat('<p>This is an awesome text with some links, here there are: <a href="http://0.0.0.0/test.html">the awesome</a></p>', 7).'<a href="#nofollow" rel="nofollow">will be removed</a></div>', 'http://0.0.0.0');
|
$readability = $this->getReadability('<div><h2>Title</h2>'.str_repeat('<p>This is an awesome text with some links, here there are: <a href="http://0.0.0.0/test.html">the awesome</a></p>', 7).'<a href="#nofollow" rel="nofollow">will NOT be removed</a></div>', 'http://0.0.0.0');
|
||||||
$readability->debug = true;
|
$readability->debug = true;
|
||||||
$readability->lightClean = false;
|
$readability->lightClean = false;
|
||||||
$res = $readability->init();
|
$res = $readability->init();
|
||||||
|
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
||||||
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
||||||
$this->assertNotContains('will be removed', $readability->getContent()->innerHTML);
|
$this->assertContains('will NOT be removed', $readability->getContent()->innerHTML);
|
||||||
$this->assertNotContains('<h2>', $readability->getContent()->innerHTML);
|
$this->assertNotContains('<h2>', $readability->getContent()->innerHTML);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithIframe()
|
public function testWithIframe()
|
||||||
{
|
{
|
||||||
$readability = new ReadabilityTested('<div><h2>Title</h2>'.str_repeat('<p>This is an awesome text with some links, here there are: <a href="http://0.0.0.0/test.html">the awesome</a></p>', 7).'<p>This is an awesome text with some links, here there are <iframe src="http://youtube.com/test" href="#nofollow" rel="nofollow"></iframe><iframe>http://soundcloud.com/test</iframe></p></div>', 'http://0.0.0.0');
|
$readability = $this->getReadability('<div><h2>Title</h2>'.str_repeat('<p>This is an awesome text with some links, here there are: <a href="http://0.0.0.0/test.html">the awesome</a></p>', 7).'<p>This is an awesome text with some links, here there are <iframe src="http://youtube.com/test" href="#nofollow" rel="nofollow"></iframe><iframe>http://soundcloud.com/test</iframe></p></div>', 'http://0.0.0.0');
|
||||||
$readability->debug = true;
|
$readability->debug = true;
|
||||||
$res = $readability->init();
|
$res = $readability->init();
|
||||||
|
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
$this->assertContains('<div readability=', $readability->getContent()->innerHTML);
|
||||||
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
||||||
$this->assertContains('nofollow', $readability->getContent()->innerHTML);
|
$this->assertContains('nofollow', $readability->getContent()->innerHTML);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithArticle()
|
public function testWithArticle()
|
||||||
{
|
{
|
||||||
$readability = new ReadabilityTested('<article><p>'.str_repeat('This is an awesome text with some links, here there are: the awesome', 20).'</p><p>This is an awesome text with some links, here there are <iframe src="http://youtube.com/test" href="#nofollow" rel="nofollow"></iframe></p></article>', 'http://0.0.0.0');
|
$readability = $this->getReadability('<article><p>'.str_repeat('This is an awesome text with some links, here there are: the awesome', 20).'</p><p>This is an awesome text with some links, here there are <iframe src="http://youtube.com/test" href="#nofollow" rel="nofollow"></iframe></p></article>', 'http://0.0.0.0');
|
||||||
$readability->debug = true;
|
$readability->debug = true;
|
||||||
$res = $readability->init();
|
$res = $readability->init();
|
||||||
|
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertContains('alt="article"', $readability->getContent()->innerHTML);
|
$this->assertContains('alt="article"', $readability->getContent()->innerHTML);
|
||||||
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
||||||
$this->assertContains('nofollow', $readability->getContent()->innerHTML);
|
$this->assertContains('nofollow', $readability->getContent()->innerHTML);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithAside()
|
public function testWithAside()
|
||||||
{
|
{
|
||||||
$readability = new ReadabilityTested('<article>'.str_repeat('<p>This is an awesome text with some links, here there are: <a href="http://0.0.0.0/test.html">the awesome</a></p>', 7).'<footer><aside>'.str_repeat('<p>This is an awesome text with some links, here there are</p>', 8).'</aside></footer></article>', 'http://0.0.0.0');
|
$readability = $this->getReadability('<article>'.str_repeat('<p>This is an awesome text with some links, here there are: <a href="http://0.0.0.0/test.html">the awesome</a></p>', 7).'<footer><aside>'.str_repeat('<p>This is an awesome text with some links, here there are</p>', 8).'</aside></footer></article>', 'http://0.0.0.0');
|
||||||
$readability->debug = true;
|
$readability->debug = true;
|
||||||
$res = $readability->init();
|
$res = $readability->init();
|
||||||
|
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertContains('alt="article"', $readability->getContent()->innerHTML);
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
||||||
$this->assertNotContains('<aside>', $readability->getContent()->innerHTML);
|
$this->assertNotContains('<aside>', $readability->getContent()->innerHTML);
|
||||||
$this->assertContains('<footer/>', $readability->getContent()->innerHTML);
|
$this->assertContains('<footer readability="4"/>', $readability->getContent()->innerHTML);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithClasses()
|
public function testWithClasses()
|
||||||
{
|
{
|
||||||
$readability = new ReadabilityTested('<article>'.str_repeat('<p>This is an awesome text with some links, here there are: <a href="http://0.0.0.0/test.html">the awesome</a></p>', 7).'<div style="display:none">'.str_repeat('<p class="clock">This text should be removed</p>', 10).'</div></article>', 'http://0.0.0.0');
|
$readability = $this->getReadability('<article>'.str_repeat('<p>This is an awesome text with some links, here there are: <a href="http://0.0.0.0/test.html">the awesome</a></p>', 7).'<div style="display:none">'.str_repeat('<p class="clock">This text should be removed</p>', 10).'</div></article>', 'http://0.0.0.0');
|
||||||
$readability->debug = true;
|
$readability->debug = true;
|
||||||
$res = $readability->init();
|
$res = $readability->init();
|
||||||
|
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
$this->assertContains('alt="article"', $readability->getContent()->innerHTML);
|
$this->assertContains('alt="article"', $readability->getContent()->innerHTML);
|
||||||
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
||||||
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
||||||
|
$this->assertNotContains('This text should be removed', $readability->getContent()->innerHTML);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testWithClassesWithoutLightClean()
|
||||||
|
{
|
||||||
|
$readability = $this->getReadability('<article>'.str_repeat('<p>This is an awesome text with some links, here there are: <a href="http://0.0.0.0/test.html">the awesome</a></p>', 7).'<div style="display:none">'.str_repeat('<p class="clock">This text should be removed</p>', 10).'</div></article>', 'http://0.0.0.0');
|
||||||
|
$readability->debug = true;
|
||||||
|
$readability->lightClean = false;
|
||||||
|
$res = $readability->init();
|
||||||
|
|
||||||
|
$this->assertTrue($res);
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
|
$this->assertContains('alt="article"', $readability->getContent()->innerHTML);
|
||||||
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
||||||
$this->assertNotContains('This text should be removed', $readability->getContent()->innerHTML);
|
$this->assertNotContains('This text should be removed', $readability->getContent()->innerHTML);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithTd()
|
public function testWithTd()
|
||||||
{
|
{
|
||||||
$readability = new ReadabilityTested('<table><tr>'.str_repeat('<td><p>This is an awesome text with some links, here there are the awesome</td>', 7).'</tr></table>', 'http://0.0.0.0');
|
$readability = $this->getReadability('<table><tr>'.str_repeat('<td><p>This is an awesome text with some links, here there are the awesome</td>', 7).'</tr></table>', 'http://0.0.0.0');
|
||||||
$readability->debug = true;
|
$readability->debug = true;
|
||||||
$res = $readability->init();
|
$res = $readability->init();
|
||||||
|
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertContains('alt="tr"', $readability->getContent()->innerHTML);
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithSameClasses()
|
public function testWithSameClasses()
|
||||||
{
|
{
|
||||||
$readability = new ReadabilityTested('<article class="awesomecontent">'.str_repeat('<p>This is an awesome text with some links, here there are the awesome</p>', 7).'<div class="awesomecontent">This text is also an awesome text and you should know that !</div></article>', 'http://0.0.0.0');
|
$readability = $this->getReadability('<article class="awesomecontent">'.str_repeat('<p>This is an awesome text with some links, here there are the awesome</p>', 7).'<div class="awesomecontent">This text is also an awesome text and you should know that !</div></article>', 'http://0.0.0.0');
|
||||||
$readability->debug = true;
|
$readability->debug = true;
|
||||||
$res = $readability->init();
|
$res = $readability->init();
|
||||||
|
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertContains('alt="article"', $readability->getContent()->innerHTML);
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
||||||
$this->assertContains('This text is also an awesome text and you should know that', $readability->getContent()->innerHTML);
|
$this->assertContains('This text is also an awesome text and you should know that', $readability->getContent()->innerHTML);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithScript()
|
public function testWithScript()
|
||||||
{
|
{
|
||||||
$readability = new ReadabilityTested('<article class="awesomecontent">'.str_repeat('<p>This is an awesome text with some links, here there are the awesome</p>', 7).'<p><script>This text is also an awesome text and you should know that !</script></p></article>', 'http://0.0.0.0');
|
$readability = $this->getReadability('<article class="awesomecontent">'.str_repeat('<p>This is an awesome text with some links, here there are the awesome</p>', 7).'<p><script>This text is also an awesome text and you should know that !</script></p></article>', 'http://0.0.0.0');
|
||||||
$readability->debug = true;
|
$readability->debug = true;
|
||||||
$res = $readability->init();
|
$res = $readability->init();
|
||||||
|
|
||||||
$this->assertTrue($res);
|
$this->assertTrue($res);
|
||||||
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
$this->assertContains('alt="article"', $readability->getContent()->innerHTML);
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
|
$this->assertEmpty($readability->getTitle()->innerHTML);
|
||||||
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
||||||
|
$this->assertNotContains('This text is also an awesome text and you should know that', $readability->getContent()->innerHTML);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTitle()
|
||||||
|
{
|
||||||
|
$readability = $this->getReadability('<title>this is my title</title><article class="awesomecontent">'.str_repeat('<p>This is an awesome text with some links, here there are the awesome</p>', 7).'<p></p></article>', 'http://0.0.0.0');
|
||||||
|
$readability->debug = true;
|
||||||
|
$res = $readability->init();
|
||||||
|
|
||||||
|
$this->assertTrue($res);
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
|
$this->assertEquals('this is my title', $readability->getTitle()->innerHTML);
|
||||||
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
||||||
|
$this->assertNotContains('This text is also an awesome text and you should know that', $readability->getContent()->innerHTML);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTitleWithDash()
|
||||||
|
{
|
||||||
|
$readability = $this->getReadability('<title> title2 - title3 </title><article class="awesomecontent">'.str_repeat('<p>This is an awesome text with some links, here there are the awesome</p>', 7).'<p></p></article>', 'http://0.0.0.0');
|
||||||
|
$readability->debug = true;
|
||||||
|
$res = $readability->init();
|
||||||
|
|
||||||
|
$this->assertTrue($res);
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
|
$this->assertEquals('title2 - title3', $readability->getTitle()->innerHTML);
|
||||||
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
||||||
|
$this->assertNotContains('This text is also an awesome text and you should know that', $readability->getContent()->innerHTML);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTitleWithDoubleDot()
|
||||||
|
{
|
||||||
|
$readability = $this->getReadability('<title> title2 : title3 </title><article class="awesomecontent">'.str_repeat('<p>This is an awesome text with some links, here there are the awesome</p>', 7).'<p></p></article>', 'http://0.0.0.0');
|
||||||
|
$readability->debug = true;
|
||||||
|
$res = $readability->init();
|
||||||
|
|
||||||
|
$this->assertTrue($res);
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
|
$this->assertEquals('title2 : title3', $readability->getTitle()->innerHTML);
|
||||||
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
||||||
|
$this->assertNotContains('This text is also an awesome text and you should know that', $readability->getContent()->innerHTML);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTitleTooShortUseH1()
|
||||||
|
{
|
||||||
|
$readability = $this->getReadability('<title>too short</title><h1>this is my h1 title !</h1><article class="awesomecontent">'.str_repeat('<p>This is an awesome text with some links, here there are the awesome</p>', 7).'<p></p></article>', 'http://0.0.0.0');
|
||||||
|
$readability->debug = true;
|
||||||
|
$res = $readability->init();
|
||||||
|
|
||||||
|
$this->assertTrue($res);
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
|
$this->assertEquals('this is my h1 title !', $readability->getTitle()->innerHTML);
|
||||||
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->innerHTML);
|
||||||
$this->assertNotContains('This text is also an awesome text and you should know that', $readability->getContent()->innerHTML);
|
$this->assertNotContains('This text is also an awesome text and you should know that', $readability->getContent()->innerHTML);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public function testConstructParser()
|
// public function testConstructParser()
|
||||||
// {
|
// {
|
||||||
// $readability = new ReadabilityTested('<html/>', 'http://0.0.0.0', 'html5lib');
|
// $readability = $this->getReadability('<html/>', 'http://0.0.0.0', 'html5lib');
|
||||||
|
|
||||||
// $this->assertEquals('http://0.0.0.0', $readability->url);
|
// $this->assertEquals('http://0.0.0.0', $readability->url);
|
||||||
// $this->assertContains('Parsing URL', $readability->getDebugText());
|
|
||||||
// $this->assertContains('Tidying document', $readability->getDebugText());
|
|
||||||
// $this->assertEquals('/0\.0\.0\.0/', $readability->getDomainRegexp());
|
|
||||||
// $this->assertInstanceOf('DomDocument', $readability->dom);
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// dummy function to be used to the next test
|
||||||
|
public function error2Exception($code, $string, $file, $line, $context)
|
||||||
|
{
|
||||||
|
throw new \Exception($string, $code);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAutoClosingIframeNotThrowingException()
|
||||||
|
{
|
||||||
|
error_reporting(E_ALL | E_STRICT);
|
||||||
|
ini_set('display_errors', true);
|
||||||
|
set_error_handler(array($this, 'error2Exception'), E_ALL | E_STRICT);
|
||||||
|
|
||||||
|
$data = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="ru-RU" prefix="og: http://ogp.me/ns#">
|
||||||
|
|
||||||
|
<head profile="http://gmpg.org/xfn/11">
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body class="single single-post postid-22030 single-format-standard">
|
||||||
|
<div id="wrapper">
|
||||||
|
<div id="content">
|
||||||
|
<div class="post-22030 post type-post status-publish format-standard has-post-thumbnail hentry category-video category-reviews tag-193" id="post-22030">
|
||||||
|
<h1>3D Touch — будущее мобильных игр</h1>
|
||||||
|
<div class="postdate">Автор: <strong>Сергей Пак</strong> | Просмотров: 1363 | Опубликовано: 14 сентября 2015 </div>
|
||||||
|
<div class="entry">
|
||||||
|
<p>Компания Apple представила новую технологию 3D Touch, которая является прямым потомком более ранней версии Force Touch — последняя, напомним, используется сейчас в трекпадах Macbook Pro и Macbook 2015. Теперь управлять устройством стало в разы проще, и Force Touch открывает перед пользователями новые возможности, но при этом 3D Touch — это про другое. Дело в том, что теперь и на мобильных устройствах интерфейс будет постепенно меняться, кардинальные перемены ждут мобильный гейминг, потому что здесь разработчики действительно могут разгуляться.<span id="more-22030"></span></p>
|
||||||
|
<p><iframe src="https://www.youtube.com/embed/PUep6xNeKjA" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen"></iframe></p>
|
||||||
|
<p>Итак, просто представьте себе, что iPhone 6S — это, по большому счету, отличная игровая приставка, которую вы носите с собой, а еще она может выдавать невероятной красоты картинку. Но проблема заключается, пожалуй, в том, что управлять персонажем в играх довольно трудно — он неповоротлив, обладает заторможенной реакцией, а игровой клиент зачастую требует перегруза интерфейса для того, чтобы обеспечить максимально большое количество возможностей. Благодаря трехуровневому нажатию можно избавиться от лишних кнопок и обеспечить более качественный обзор местности, и при этом пользователь будет закрывать пальцами минимальное пространство.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>';
|
||||||
|
|
||||||
|
$readability = $this->getReadability($data, 'http://iosgames.ru/?p=22030');
|
||||||
|
$readability->debug = true;
|
||||||
|
|
||||||
|
$res = $readability->init();
|
||||||
|
|
||||||
|
$this->assertTrue($res);
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
|
$this->assertContains('<iframe src="https://www.youtube.com/embed/PUep6xNeKjA" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen"> </iframe>', $readability->getContent()->innerHTML);
|
||||||
|
$this->assertContains('3D Touch', $readability->getTitle()->innerHTML);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This should generate an Exception "DOMElement::setAttribute(): ID post-60 already defined"
|
||||||
|
*/
|
||||||
|
public function testAppendIdAlreadyHere()
|
||||||
|
{
|
||||||
|
$data = '<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<header class="header sml-text-center med-text-left" role="banner">
|
||||||
|
<h1 class="no-margin"><a class="maintitle" href="https://0.0.0.0" title="Bloc-notes">Bloc-notes</a></h1>
|
||||||
|
<h2 class="h5 no-margin"></h2>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<nav class="nav" role="navigation">
|
||||||
|
<div class="responsive-menu">
|
||||||
|
<label for="menu">Menu</label>
|
||||||
|
<input type="checkbox" id="menu">
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<article class="article" role="article" id="post-60">
|
||||||
|
<section>
|
||||||
|
This is an awesome text with some links, here there are<br/>
|
||||||
|
This is an awesome text with some links, here there are<br/>
|
||||||
|
This is an awesome text with some links, here there are<br/>
|
||||||
|
This is an awesome text with some links, here there are<br/>
|
||||||
|
This is an awesome text with some links, here there are<br/>
|
||||||
|
This is an awesome text with some links, here there are<br/>
|
||||||
|
This is an awesome text with some links, here there are<br/>
|
||||||
|
This is an awesome text with some links, here there are<br/>
|
||||||
|
This is an awesome text with some links, here there are<br/>
|
||||||
|
This is an awesome text with some links, here there are<br/>
|
||||||
|
This is an awesome text with some links, here there are
|
||||||
|
</section>
|
||||||
|
<footer>
|
||||||
|
<small>
|
||||||
|
Classé dans : <a class="noactive" title="Services réseaux">Services réseaux</a>
|
||||||
|
</small>
|
||||||
|
</footer>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>';
|
||||||
|
|
||||||
|
$readability = $this->getReadability($data, 'http://0.0.0.0');
|
||||||
|
$readability->debug = true;
|
||||||
|
|
||||||
|
$res = $readability->init();
|
||||||
|
|
||||||
|
$this->assertTrue($res);
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getContent());
|
||||||
|
$this->assertInstanceOf('Readability\JSLikeHTMLElement', $readability->getTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPostFilters()
|
||||||
|
{
|
||||||
|
$readability = $this->getReadability('<div>'.str_repeat('<p>This <b>is</b> the awesome content :)</p>', 7).'</div>', 'http://0.0.0.0');
|
||||||
|
$readability->addPostFilter('!<strong[^>]*>(.*?)</strong>!is', '');
|
||||||
|
|
||||||
|
$res = $readability->init();
|
||||||
|
|
||||||
|
$this->assertTrue($res);
|
||||||
|
$this->assertContains('This the awesome content :)', $readability->getContent()->innerHTML);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPreFilters()
|
||||||
|
{
|
||||||
|
$readability = $this->getReadability('<div>'.str_repeat('<p>This <b>is</b> the awesome and WONDERFUL content :)</p>', 7).'</div>', 'http://0.0.0.0');
|
||||||
|
$readability->addPreFilter('!<b[^>]*>(.*?)</b>!is', '');
|
||||||
|
|
||||||
|
$res = $readability->init();
|
||||||
|
|
||||||
|
$this->assertTrue($res);
|
||||||
|
$this->assertContains('This the awesome and WONDERFUL content :)', $readability->getContent()->innerHTML);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user