diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..53ba5da --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +name: CI Tests +on: [push, pull_request] + +jobs: + PHPUnit: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + php: + - 5.4 + - 5.5 + - 5.6 + - 7.0 + - 7.1 + - 7.2 + - 7.3 + - 7.4 + - 8.0 + - 8.1 + - 8.2 + - 8.3 + - 8.4 + + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + + - name: Install dependencies + run: composer install + + - name: Run PHPUnit + run: vendor/bin/phpunit diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e908791..0000000 --- a/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -language: php - -matrix: - include: - - php: 5.3 - dist: precise - - php: 5.4 - dist: trusty - - php: 5.5 - dist: trusty - - php: 5.6 - - php: 7.0 - - php: 7.1 - - php: 7.2 - - php: 7.3 - -before_script: - - composer install diff --git a/README.md b/README.md index e66da7b..cb619b3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A PHP library for converting HTML to formatted plain text. -[![Build Status](https://travis-ci.org/mtibben/html2text.png?branch=master)](https://travis-ci.org/mtibben/html2text) +[![Build status](https://github.com/mtibben/html2text/actions/workflows/ci.yml/badge.svg)](https://github.com/mtibben/html2text/actions/workflows/ci.yml) ## Installing diff --git a/composer.json b/composer.json index ab76efe..7cfb7fe 100644 --- a/composer.json +++ b/composer.json @@ -4,13 +4,20 @@ "type": "library", "license": "GPL-2.0-or-later", "autoload": { - "psr-4": { "Html2Text\\": ["src/", "test/"] } + "psr-4": { + "Html2Text\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Html2Text\\": "test/" + } }, "require-dev": { - "phpunit/phpunit": "~4" + "phpunit/phpunit": "~4|^9.0" }, "suggest": { "ext-mbstring": "For best performance", "symfony/polyfill-mbstring": "If you can't install ext-mbstring" } -} +} \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 17beeca..363c9e2 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,7 +6,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="test/bootstrap.php" > diff --git a/src/Html2Text.php b/src/Html2Text.php index 9fd9123..6e0f9e5 100644 --- a/src/Html2Text.php +++ b/src/Html2Text.php @@ -236,16 +236,19 @@ private function legacyConstruct($html = '', $fromFile = false, array $options = */ public function __construct($html = '', $options = array()) { + $this->htmlFuncFlags = (PHP_VERSION_ID < 50400) + ? ENT_QUOTES + : ENT_QUOTES | ENT_HTML5; + // for backwards compatibility if (!is_array($options)) { - return call_user_func_array(array($this, 'legacyConstruct'), func_get_args()); + // phpcs:ignore (PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection + call_user_func_array(array($this, 'legacyConstruct'), func_get_args()); + return; } $this->html = $html; $this->options = array_merge($this->options, $options); - $this->htmlFuncFlags = (PHP_VERSION_ID < 50400) - ? ENT_COMPAT - : ENT_COMPAT | ENT_HTML5; } /** @@ -351,7 +354,11 @@ protected function doConvert() { $this->linkList = array(); - $text = trim($this->html); + if ($this->html === null) { + $text = ''; + } else { + $text = trim($this->html); + } $this->converter($text); @@ -389,6 +396,9 @@ protected function converter(&$text) $text = preg_replace("/[\n]{3,}/", "\n\n", $text); // remove leading empty lines (can be produced by eg. P tag on the beginning) + if ($text === null) { + $text = ''; + } $text = ltrim($text, "\n"); if ($this->options['width'] > 0) { @@ -417,7 +427,7 @@ protected function buildlinkList($link, $display, $linkOverride = null) } // Ignored link types - if (preg_match('!^(javascript:|mailto:|#)!i', html_entity_decode($link))) { + if (preg_match('!^(javascript:|mailto:|#)!i', html_entity_decode($link, $this->htmlFuncFlags, self::ENCODING))) { return $display; } diff --git a/test/BasicTest.php b/test/BasicTest.php index 19c5d18..a03a91d 100644 --- a/test/BasicTest.php +++ b/test/BasicTest.php @@ -2,7 +2,9 @@ namespace Html2Text; -class BasicTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class BasicTest extends TestCase { public function basicDataProvider() { return array( diff --git a/test/BlockquoteTest.php b/test/BlockquoteTest.php index cd3b793..07c1fcc 100644 --- a/test/BlockquoteTest.php +++ b/test/BlockquoteTest.php @@ -2,7 +2,9 @@ namespace Html2Text; -class BlockquoteTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class BlockquoteTest extends TestCase { public function blockquoteDataProvider() { diff --git a/test/ConstructorTest.php b/test/ConstructorTest.php index 3cf310e..ffd1473 100644 --- a/test/ConstructorTest.php +++ b/test/ConstructorTest.php @@ -2,7 +2,9 @@ namespace Html2Text; -class ConstructorTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class ConstructorTest extends TestCase { public function testConstructor() { @@ -29,7 +31,10 @@ public function testLegacyConstructorThrowsExceptionWhenFromFileIsTrue() $html = 'Foo'; $options = array('do_links' => 'none'); - $this->setExpectedException('InvalidArgumentException'); + method_exists($this, 'expectException') + ? $this->expectException('InvalidArgumentException') + : $this->setExpectedException('InvalidArgumentException'); + $html2text = new Html2Text($html, true, $options); } } diff --git a/test/DefinitionListTest.php b/test/DefinitionListTest.php index 2d5856d..82acae1 100644 --- a/test/DefinitionListTest.php +++ b/test/DefinitionListTest.php @@ -2,7 +2,9 @@ namespace Html2Text; -class DefinitionListTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class DefinitionListTest extends TestCase { public function testDefinitionList() { diff --git a/test/DelTest.php b/test/DelTest.php index 3b2c26c..65a1549 100644 --- a/test/DelTest.php +++ b/test/DelTest.php @@ -2,7 +2,9 @@ namespace Html2Text; -class DelTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class DelTest extends TestCase { public function testDel() { diff --git a/test/HtmlCharsTest.php b/test/HtmlCharsTest.php index e426ffa..788662b 100644 --- a/test/HtmlCharsTest.php +++ b/test/HtmlCharsTest.php @@ -2,7 +2,9 @@ namespace Html2Text; -class HtmlCharsTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class HtmlCharsTest extends TestCase { public function testLaquoAndRaquo() { @@ -55,4 +57,13 @@ public function testSymbol($entity, $symbol) $html2text = new Html2Text($html); $this->assertEquals($expected, $html2text->getText()); } + + public function testSingleQuote() + { + $html = "Single quote's preservation"; + $expected = "Single quote's preservation"; + + $html2text = new Html2Text($html); + $this->assertEquals($expected, $html2text->getText()); + } } diff --git a/test/ImageTest.php b/test/ImageTest.php index 7aa306c..afe439a 100644 --- a/test/ImageTest.php +++ b/test/ImageTest.php @@ -2,9 +2,11 @@ namespace Html2Text; -class ImageTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class ImageTest extends TestCase { - public function testImageDataProvider() { + public function imageDataProvider() { return array( 'Without alt tag' => array( 'html' => '', @@ -34,7 +36,7 @@ public function testImageDataProvider() { } /** - * @dataProvider testImageDataProvider + * @dataProvider imageDataProvider */ public function testImages($html, $expected) { diff --git a/test/InsTest.php b/test/InsTest.php index 5723762..0832b1f 100644 --- a/test/InsTest.php +++ b/test/InsTest.php @@ -2,7 +2,9 @@ namespace Html2Text; -class InsTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class InsTest extends TestCase { public function testIns() { diff --git a/test/LinkTest.php b/test/LinkTest.php index d621c18..51ab635 100644 --- a/test/LinkTest.php +++ b/test/LinkTest.php @@ -2,7 +2,9 @@ namespace Html2Text; -class LinkTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class LinkTest extends TestCase { const TEST_HTML = 'Link text'; diff --git a/test/ListTest.php b/test/ListTest.php index 4fc4de0..fb503d8 100644 --- a/test/ListTest.php +++ b/test/ListTest.php @@ -2,7 +2,9 @@ namespace Html2Text; -class ListTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class ListTest extends TestCase { public function testList() { diff --git a/test/PreTest.php b/test/PreTest.php index c8a5726..d1d464a 100644 --- a/test/PreTest.php +++ b/test/PreTest.php @@ -2,7 +2,9 @@ namespace Html2Text; -class PreTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class PreTest extends TestCase { public function preDataProvider() { diff --git a/test/PrintTest.php b/test/PrintTest.php index 0d35111..9a9fd80 100644 --- a/test/PrintTest.php +++ b/test/PrintTest.php @@ -2,23 +2,24 @@ namespace Html2Text; -class PrintTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class PrintTest extends TestCase { const TEST_HTML = 'Hello, "world"'; const EXPECTED = 'Hello, "WORLD"'; - public function setUp() { - $this->html = new Html2Text(self::TEST_HTML); - $this->expectOutputString(self::EXPECTED); - } - public function testP() { - $this->html->p(); + $html = new Html2Text(self::TEST_HTML); + $html->p(); + $this->expectOutputString(self::EXPECTED); } public function testPrint_text() { - $this->html->print_text(); + $html = new Html2Text(self::TEST_HTML); + $html->print_text(); + $this->expectOutputString(self::EXPECTED); } } diff --git a/test/SearchReplaceTest.php b/test/SearchReplaceTest.php index 66de882..aa0393f 100644 --- a/test/SearchReplaceTest.php +++ b/test/SearchReplaceTest.php @@ -2,7 +2,9 @@ namespace Html2Text; -class SearchReplaceTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class SearchReplaceTest extends TestCase { public function searchReplaceDataProvider() { return array( diff --git a/test/SpanTest.php b/test/SpanTest.php index 34a1ab1..c0ac66d 100644 --- a/test/SpanTest.php +++ b/test/SpanTest.php @@ -2,7 +2,9 @@ namespace Html2Text; -class SpanTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class SpanTest extends TestCase { public function testIgnoreSpans() diff --git a/test/StrToUpperTest.php b/test/StrToUpperTest.php index 0878160..01d6ff2 100644 --- a/test/StrToUpperTest.php +++ b/test/StrToUpperTest.php @@ -2,7 +2,9 @@ namespace Html2Text; -class StrToUpperTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class StrToUpperTest extends TestCase { public function testToUpper() { diff --git a/test/TableTest.php b/test/TableTest.php index 70f2199..3b4e3e1 100644 --- a/test/TableTest.php +++ b/test/TableTest.php @@ -2,7 +2,9 @@ namespace Html2Text; -class TableTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class TableTest extends TestCase { public function testTable() { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy