Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Word/CamelCaseToSeparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function filter($value)
$pattern = array('#(?<=(?:\p{Lu}))(\p{Lu}\p{Ll})#', '#(?<=(?:\p{Ll}|\p{Nd}))(\p{Lu})#');
$replacement = array($this->separator . '\1', $this->separator . '\1');
} else {
$pattern = array('#(?<=(?:[A-Z]))([A-Z]+)([A-Z][A-z])#', '#(?<=(?:[a-z0-9]))([A-Z])#');
$pattern = array('#(?<=(?:[A-Z]))([A-Z]+)([A-Z][a-z])#', '#(?<=(?:[a-z0-9]))([A-Z])#');
$replacement = array('\1' . $this->separator . '\2', $this->separator . '\1');
}

Expand Down
39 changes: 39 additions & 0 deletions test/Word/CamelCaseToSeparatorNoPcreUnicodeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Filter\Word;

use ReflectionProperty;
use Zend\Filter\Word\CamelCaseToSeparator as CamelCaseToSeparatorFilter;
use Zend\Stdlib\StringUtils;

/**
* Test class for Zend\Filter\Word\CamelCaseToSeparator which simulates the
* PCRE Unicode features disabled
*/
class CamelCaseToSeparatorNoPcreUnicodeTest extends CamelCaseToSeparatorTest
{
protected $reflection;

public function setUp()
{
if (!StringUtils::hasPcreUnicodeSupport()) {
return $this->markTestSkipped('PCRE is not compiled with Unicode support');
}

$this->reflection = new ReflectionProperty('Zend\Stdlib\StringUtils', 'hasPcreUnicodeSupport');
$this->reflection->setAccessible(true);
$this->reflection->setValue(false);
}

public function tearDown()
{
$this->reflection->setValue(true);
}
}
10 changes: 10 additions & 0 deletions test/Word/CamelCaseToSeparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,14 @@ public function testFilterSeparatesCamelCasedWordsWithProvidedSeparator()
$this->assertNotEquals($string, $filtered);
$this->assertEquals('Camel:-#Cased:-#Words', $filtered);
}

public function testFilterSeperatesMultipleUppercasedLettersAndUnderscores()
{
$string = 'TheseAre_SOME_CamelCASEDWords';
$filter = new CamelCaseToSeparatorFilter('_');
$filtered = $filter($string);

$this->assertNotEquals($string, $filtered);
$this->assertEquals('These_Are_SOME_Camel_CASED_Words', $filtered);
}
}

0 comments on commit e6d18f9

Please sign in to comment.