public function onStart(EnvironmentEvent $event) { $renderizer = $event->getRenderizer(); $renderizer->addTwigFilter('slugify', function ($text) { $string = new StringWrapper($text); return $string->slug(); }); }
public function testSlug() { $str = new StringWrapper('Welcome to Spress'); $this->assertEquals('welcome-to-spress', $str->slug()); $this->assertEquals('bienvenido-a-espana', $str->setString('Bienvenido a España')->slug()); $this->assertEquals('hello-spress', $str->setString('hello spress')->slug()); $this->assertEquals('hello-spress', $str->setString('-hello-spress-')->slug()); $this->assertEquals('12-cheese', $str->setString('1\\2 cheese')->slug()); $this->assertEquals('2-step', $str->setString('.,;{}+¨¿?=()/&%$·#@|!ºª2 step ^[]')->slug()); }