This repository has been archived by the owner on Sep 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added node-name-slugifier to centralice additional node name replacer
- Loading branch information
1 parent
f51fc4c
commit af07068
Showing
7 changed files
with
129 additions
and
34 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
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,50 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) MASSIVE ART WebServices GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Component\DocumentManager\Slugifier; | ||
|
||
use Symfony\Cmf\Api\Slugifier\SlugifierInterface; | ||
|
||
/** | ||
* Wraps default slugifier and add some additional node-name stuff. | ||
*/ | ||
class NodeNameSlugifier implements SlugifierInterface | ||
{ | ||
/** | ||
* @var SlugifierInterface | ||
*/ | ||
private $slugifier; | ||
|
||
/** | ||
* @param SlugifierInterface $slugifier | ||
*/ | ||
public function __construct(SlugifierInterface $slugifier) | ||
{ | ||
$this->slugifier = $slugifier; | ||
} | ||
|
||
/** | ||
* Slugifies given string to a valid node-name. | ||
* | ||
* @param string $text | ||
* | ||
* @return string | ||
*/ | ||
public function slugify($text) | ||
{ | ||
$text = $this->slugifier->slugify($text); | ||
|
||
// jackrabbit can not handle node-names which contains a number followed by "e" e.g. 10e | ||
$text = preg_replace('((\d+)([eE]))', '$1-$2', $text); | ||
|
||
return $text; | ||
} | ||
} |
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
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
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
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,70 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) MASSIVE ART WebServices GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Component\DocumentManager\tests\Unit\Slugifier; | ||
|
||
use Sulu\Component\DocumentManager\Slugifier\NodeNameSlugifier; | ||
use Symfony\Cmf\Api\Slugifier\SlugifierInterface; | ||
|
||
class NodeNameSlugifierTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var SlugifierInterface | ||
*/ | ||
private $slugifier; | ||
|
||
/** | ||
* @var NodeNameSlugifier | ||
*/ | ||
private $nodeNameSlugifier; | ||
|
||
protected function setUp() | ||
{ | ||
$this->slugifier = $this->prophesize(SlugifierInterface::class); | ||
$this->nodeNameSlugifier = new NodeNameSlugifier($this->slugifier->reveal()); | ||
} | ||
|
||
public function testSlugify() | ||
{ | ||
$this->slugifier->slugify('Test article')->willReturn('test-article'); | ||
|
||
$this->assertEquals('test-article', $this->nodeNameSlugifier->slugify('Test article')); | ||
} | ||
|
||
public function provide10eData() | ||
{ | ||
return [ | ||
['10e', '10-e'], | ||
['.10e', '.10-e'], | ||
['-10e', '-10-e'], | ||
['%10e', '%10-e'], | ||
['test-10e-name', 'test-10-e-name'], | ||
['test.10e-name', 'test.10-e-name'], | ||
['test%10e-name', 'test%10-e-name'], | ||
['test-10E-name', 'test-10-E-name'], | ||
['test.10E-name', 'test.10-E-name'], | ||
['test%10E-name', 'test%10-E-name'], | ||
['test10E-name', 'test10-E-name'], | ||
['test-9e-name', 'test-9-e-name'], | ||
['test-500e-name', 'test-500-e-name'], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider provide10eData | ||
*/ | ||
public function testSlugify10e($actual, $expected) | ||
{ | ||
$this->slugifier->slugify($actual)->willReturn($actual); | ||
|
||
$this->assertEquals($expected, $this->nodeNameSlugifier->slugify($actual)); | ||
} | ||
} |
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