SlugifyServiceTest.php 1.9 KB

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