forked from sonata-project/SonataAdminBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thomas Rabaix
committed
Nov 14, 2011
1 parent
e1c73e8
commit 425f4bf
Showing
7 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sonata package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace Sonata\AdminBundle\Tests\Translator; | ||
|
||
use Sonata\AdminBundle\Translator\NativeLabelTranslatorStrategy; | ||
|
||
class NativeTranslatorStrategyTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testLabel() | ||
{ | ||
$strategy = new NativeLabelTranslatorStrategy; | ||
|
||
$this->assertEquals('Is Valid', $strategy->getLabel('isValid')); | ||
$this->assertEquals('Is Valid', $strategy->getLabel('is_Valid')); | ||
$this->assertEquals('Is0 Valid', $strategy->getLabel('is0Valid')); | ||
$this->assertEquals('Is Valid Super Cool', $strategy->getLabel('isValid_SuperCool')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sonata package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace Sonata\AdminBundle\Tests\Translator; | ||
|
||
use Sonata\AdminBundle\Translator\NoopLabelTranslatorStrategy; | ||
|
||
class NoopLabelTranslatorStrategyTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testLabel() | ||
{ | ||
$strategy = new NoopLabelTranslatorStrategy; | ||
|
||
$this->assertEquals('isValid', $strategy->getLabel('isValid')); | ||
$this->assertEquals('isValid_SuperCool', $strategy->getLabel('isValid_SuperCool')); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Tests/Translator/UnderscoreLabelTranslatorStrategyTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sonata package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace Sonata\AdminBundle\Tests\Translator; | ||
|
||
use Sonata\AdminBundle\Translator\UnderscoreLabelTranslatorStrategy; | ||
|
||
class UnderscoreLabelTranslatorStrategyTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testLabel() | ||
{ | ||
$strategy = new UnderscoreLabelTranslatorStrategy; | ||
|
||
$this->assertEquals('label_is_valid', $strategy->getLabel('isValid')); | ||
$this->assertEquals('label_is0_valid', $strategy->getLabel('is0Valid')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of sonata-project. | ||
* | ||
* (c) 2010 Thomas Rabaix | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\Translator; | ||
|
||
interface LabelTranslatorStrategyInterface | ||
{ | ||
/** | ||
* @abstract | ||
* @param $label | ||
*/ | ||
function getLabel($label); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of sonata-project. | ||
* | ||
* (c) 2010 Thomas Rabaix | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\Translator; | ||
|
||
class NativeLabelTranslatorStrategy implements LabelTranslatorStrategyInterface | ||
{ | ||
/** | ||
* @param string $label | ||
* @return string | ||
*/ | ||
public function getLabel($label) | ||
{ | ||
$label = str_replace('_', ' ', $label); | ||
$label = strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $label)); | ||
|
||
return ucwords(str_replace('_', ' ', $label)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of sonata-project. | ||
* | ||
* (c) 2010 Thomas Rabaix | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\Translator; | ||
|
||
class NoopLabelTranslatorStrategy implements LabelTranslatorStrategyInterface | ||
{ | ||
/** | ||
* @param string $label | ||
* @return string | ||
*/ | ||
public function getLabel($label) | ||
{ | ||
return $label; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of sonata-project. | ||
* | ||
* (c) 2010 Thomas Rabaix | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\Translator; | ||
|
||
class UnderscoreLabelTranslatorStrategy implements LabelTranslatorStrategyInterface | ||
{ | ||
/** | ||
* @param string $label | ||
* @return string | ||
*/ | ||
public function getLabel($label) | ||
{ | ||
return sprintf('label_%s', strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $label))); | ||
} | ||
} |