SlugifyServiceTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace Cocur\Slugify\Bridge\ZF2;
  3. use Zend\ServiceManager\ServiceManager;
  4. /**
  5. * Class SlugifyServiceTest
  6. * @package cocur/slugify
  7. * @subpackage bridge
  8. * @license http://www.opensource.org/licenses/MIT The MIT License
  9. */
  10. class SlugifyServiceTest extends \PHPUnit_Framework_TestCase
  11. {
  12. /**
  13. * @var SlugifyService
  14. */
  15. private $slugifyService;
  16. public function setUp()
  17. {
  18. $this->slugifyService = new SlugifyService();
  19. }
  20. /**
  21. * @test
  22. * @covers Cocur\Slugify\Bridge\ZF2\SlugifyService::__invoke()
  23. */
  24. public function invokeWithoutCustomConfig()
  25. {
  26. $sm = $this->createServiceManagerMock();
  27. $slugify = call_user_func($this->slugifyService, $sm);
  28. $this->assertInstanceOf('Cocur\Slugify\Slugify', $slugify);
  29. // Make sure reg exp is default one
  30. $actual = 'Hello My Friend.zip';
  31. $expected = 'hello-my-friend-zip';
  32. $this->assertEquals($expected, $slugify->slugify($actual));
  33. }
  34. /**
  35. * @test
  36. * @covers Cocur\Slugify\Bridge\ZF2\SlugifyService::__invoke()
  37. */
  38. public function invokeWithCustomConfig()
  39. {
  40. $sm = $this->createServiceManagerMock(array(
  41. Module::CONFIG_KEY => array(
  42. 'reg_exp' => '/([^a-z0-9.]|-)+/'
  43. )
  44. ));
  45. $slugify = call_user_func($this->slugifyService, $sm);
  46. $this->assertInstanceOf('Cocur\Slugify\Slugify', $slugify);
  47. // Make sure reg exp is the one provided and dots are kept
  48. $actual = 'Hello My Friend.zip';
  49. $expected = 'hello-my-friend.zip';
  50. $this->assertEquals($expected, $slugify->slugify($actual));
  51. }
  52. protected function createServiceManagerMock(array $config = array())
  53. {
  54. $sm = new ServiceManager();
  55. $sm->setService('Config', $config);
  56. return $sm;
  57. }
  58. }