From a7f128a877e857078b3ebb4e741ff56def11befe Mon Sep 17 00:00:00 2001 From: Emilien Escalle Date: Sun, 17 May 2020 16:13:14 +0200 Subject: [PATCH] fix: do not indent textarea content --- composer.json | 181 +++++++++--------- src/TwbsHelper/View/Helper/HtmlTrait.php | 25 ++- .../TwbsHelper/View/Helper/CarouselTest.php | 2 +- .../TwbsHelper/View/Helper/HtmlTraitTest.php | 28 +++ 4 files changed, 140 insertions(+), 96 deletions(-) create mode 100644 tests/TestSuite/TwbsHelper/View/Helper/HtmlTraitTest.php diff --git a/composer.json b/composer.json index 33663819e..b8feed564 100644 --- a/composer.json +++ b/composer.json @@ -1,95 +1,96 @@ { - "name": "neilime/twbs-helper-module", - "type": "library", - "description": "Laminas (formerly Zend Framework) module for easy integration of Twitter Bootstrap", - "keywords": [ - "Laminas", - "Zend Framework", - "Twitter Bootstrap", - "module" - ], - "homepage": "http://neilime.github.io/twbs-helper-module/", - "license": "MIT", - "minimum-stability": "stable", - "authors": [ - { - "name": "Neilime", - "homepage": "https://github.com/neilime", - "role": "Developer" - }, - { - "name": "Rolando Isidoro", - "homepage": "https://github.com/rolando-isidoro", - "role": "Developer" - } - ], - "support": { - "issues": "https://github.com/neilime/twbs-helper-module/issues" + "name": "neilime/twbs-helper-module", + "type": "library", + "description": "Laminas (formerly Zend Framework) module for easy integration of Twitter Bootstrap", + "keywords": [ + "Laminas", + "Zend Framework", + "Twitter Bootstrap", + "module" + ], + "homepage": "http://neilime.github.io/twbs-helper-module/", + "license": "MIT", + "minimum-stability": "stable", + "authors": [ + { + "name": "Neilime", + "homepage": "https://github.com/neilime", + "role": "Developer" }, - "suggest": { - "neilime/zf2-assets-bundle": "Bundling & caching Twitter Bootstrap assets", - "twitter/bootstrap": "Twitter bootstrap assets" - }, - "require": { - "php": "^7.2", - "laminas/laminas-config": "^3.3.0", - "laminas/laminas-escaper": "^2.6", - "laminas/laminas-form": "^2.14", - "laminas/laminas-i18n": "^2.10", - "laminas/laminas-loader": "^2.6", - "laminas/laminas-log": "^2.9", - "laminas/laminas-modulemanager": "^2.8", - "laminas/laminas-mvc": "^3.1", - "laminas/laminas-navigation": "^2.9", - "laminas/laminas-paginator": "^2.8", - "laminas/laminas-progressbar": "^2.7", - "laminas/laminas-serializer": "^2.9", - "laminas/laminas-servicemanager": "^3.4", - "laminas/laminas-stdlib": "^3.2", - "laminas/laminas-view": "^2.11" - }, - "require-dev": { - "laminas/laminas-component-installer": "^2.1", - "pcov/clobber": "^2.0", - "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-phpunit": "^0.12", - "phpunit/phpunit": "^9.1.4", - "slam/phpstan-laminas-framework": "^0.12", - "squizlabs/php_codesniffer": "^3.5" - }, - "autoload": { - "psr-4": { - "TwbsHelper\\": "src/TwbsHelper" - } - }, - "autoload-dev": { - "psr-4": { - "TestSuite\\": "tests/TestSuite" - } - }, - "scripts": { - "test": "phpunit --colors --configuration tests/phpunit.xml", - "test:ci": "phpunit --colors --configuration tests/phpunit.xml -d pcov.enabled=1 -d max_execution_time=0 --coverage-text --coverage-clover ./build/logs/clover.xml --coverage-html ./build/coverage/", - "cs": "phpcs", - "cbf": "phpcbf", - "stan": "phpstan analyse --level 5 src", - "ci": [ - "@cs", - "@test:ci" - ] - }, - "config": { - "optimize-autoloader": true, - "sort-packages": true + { + "name": "Rolando Isidoro", + "homepage": "https://github.com/rolando-isidoro", + "role": "Developer" + } + ], + "support": { + "issues": "https://github.com/neilime/twbs-helper-module/issues" + }, + "suggest": { + "neilime/zf2-assets-bundle": "Bundling & caching Twitter Bootstrap assets", + "twitter/bootstrap": "Twitter bootstrap assets" + }, + "require": { + "php": "^7.2", + "laminas/laminas-config": "^3.3.0", + "laminas/laminas-escaper": "^2.6", + "laminas/laminas-form": "^2.14", + "laminas/laminas-i18n": "^2.10", + "laminas/laminas-loader": "^2.6", + "laminas/laminas-log": "^2.9", + "laminas/laminas-modulemanager": "^2.8", + "laminas/laminas-mvc": "^3.1", + "laminas/laminas-navigation": "^2.9", + "laminas/laminas-paginator": "^2.8", + "laminas/laminas-progressbar": "^2.7", + "laminas/laminas-serializer": "^2.9", + "laminas/laminas-servicemanager": "^3.4", + "laminas/laminas-stdlib": "^3.2", + "laminas/laminas-view": "^2.11" + }, + "require-dev": { + "laminas/laminas-component-installer": "^2.1", + "pcov/clobber": "^2.0", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^0.12", + "phpstan/phpstan-phpunit": "^0.12", + "phpunit/phpunit": "^9.1.4", + "slam/phpstan-laminas-framework": "^0.12", + "squizlabs/php_codesniffer": "^3.5" + }, + "autoload": { + "psr-4": { + "TwbsHelper\\": "src/TwbsHelper" + } + }, + "autoload-dev": { + "psr-4": { + "TestSuite\\": "tests/TestSuite" + } + }, + "scripts": { + "test": "phpunit --colors --configuration tests/phpunit.xml", + "test:ci": "phpunit --colors --configuration tests/phpunit.xml -d pcov.enabled=1 -d max_execution_time=0 --coverage-text --coverage-clover ./build/logs/clover.xml --coverage-html ./build/coverage/", + "cs": "phpcs", + "cbf": "phpcbf", + "stan": "phpstan analyse --level 5 src", + "ci": [ + "@cs", + "@stan", + "@test:ci" + ] + }, + "config": { + "optimize-autoloader": true, + "sort-packages": true + }, + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" }, - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - }, - "laminas": { - "module": "TwbsHelper", - "config-provider": "TwbsHelper\\ConfigProvider" - } + "laminas": { + "module": "TwbsHelper", + "config-provider": "TwbsHelper\\ConfigProvider" } + } } diff --git a/src/TwbsHelper/View/Helper/HtmlTrait.php b/src/TwbsHelper/View/Helper/HtmlTrait.php index 657e60854..e1f96cec5 100644 --- a/src/TwbsHelper/View/Helper/HtmlTrait.php +++ b/src/TwbsHelper/View/Helper/HtmlTrait.php @@ -68,12 +68,27 @@ public function addProperIndentation( $sIndentation = $this->indentation; } - // Add proper indentation - $sContent = join(PHP_EOL, array_map(function ($sValue) use ($sIndentation) { - return $sIndentation . $sValue; - }, $aLines)); + $sContent = ''; + $bShouldIndent = true; + foreach ($aLines as $sLine) { + if ($sLine && $bShouldIndent) { + $sLine = $sIndentation . $sLine; + } + + $bIsStartOfTextArea = !!preg_match('/]*>/i', $sLine); + if ($bIsStartOfTextArea) { + $bShouldIndent = false; + } + + $bIsEndOfTextArea = !!preg_match('/<\/textarea[^>]*>/i', $sLine); + if ($bIsEndOfTextArea) { + $bShouldIndent = true; + } + + $sContent .= $sLine . PHP_EOL; + } - return PHP_EOL . $sContent . PHP_EOL; + return PHP_EOL . $sContent; } public function removeIndentation(string $sContent): string diff --git a/tests/TestSuite/TwbsHelper/View/Helper/CarouselTest.php b/tests/TestSuite/TwbsHelper/View/Helper/CarouselTest.php index d0c826b76..475762799 100644 --- a/tests/TestSuite/TwbsHelper/View/Helper/CarouselTest.php +++ b/tests/TestSuite/TwbsHelper/View/Helper/CarouselTest.php @@ -12,7 +12,7 @@ class CarouselTest extends \TestSuite\TwbsHelper\AbstractViewHelperTestCase public function testShouldRenderAUniqueIdIfNoneDefined() { - $this->assertRegExp( + $this->assertMatchesRegularExpression( // Expected '/