Skip to content

Commit

Permalink
fix: do not indent textarea content
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilien Escalle committed May 17, 2020
1 parent f02f14e commit a7f128a
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 96 deletions.
181 changes: 91 additions & 90 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
25 changes: 20 additions & 5 deletions src/TwbsHelper/View/Helper/HtmlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('/<textarea[^>]*>/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
Expand Down
2 changes: 1 addition & 1 deletion tests/TestSuite/TwbsHelper/View/Helper/CarouselTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CarouselTest extends \TestSuite\TwbsHelper\AbstractViewHelperTestCase

public function testShouldRenderAUniqueIdIfNoneDefined()
{
$this->assertRegExp(
$this->assertMatchesRegularExpression(
// Expected
'/<div class="carousel&#x20;slide" data-ride="carousel" id="twbs-carousel-[a-z0-9]{13}"><\/div>/',
// Rendering
Expand Down
28 changes: 28 additions & 0 deletions tests/TestSuite/TwbsHelper/View/Helper/HtmlTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace TestSuite\TwbsHelper\View\Helper;

class HtmlTraitTest extends \PHPUnit\Framework\TestCase
{

/**
* @var \TwbsHelper\View\Helper\HtmlTrait
*/
protected $trait;

public function setUp(): void
{
$this->trait = $this->getObjectForTrait('\TwbsHelper\View\Helper\HtmlTrait');
}

public function testAddProperIndentationDoesNotIndentTextarea()
{
$sContent = '<textarea>test content' . PHP_EOL . 'test content</textarea>';
$sResult = $this->trait->addProperIndentation($sContent, true);

$this->assertSame(
PHP_EOL . ' <textarea>test content' . PHP_EOL . 'test content</textarea>' . PHP_EOL,
$sResult
);
}
}

0 comments on commit a7f128a

Please sign in to comment.