public function testGenerateFrom() { foreach ($this->stringForSlugGeneratorArray as $string) { $slug = $this->slugGenerator->generateFrom($string); $result = (bool) preg_match('/^[a-zA-Z0-9_]+$/', $slug); $this->assertTrue($result); } }
/** * @param NiceUrlInterface $object * * @return NiceUrl */ public function generate(NiceUrlInterface $object) { $collection = new Collection(); /** @var Language $lang */ foreach ($this->languages as $lang) { $field = $object->getFieldForNiceUrl(); if ($object instanceof AbstractMultiLangModel) { if (in_array($field, $object->getMultiLangFields())) { $field = $field . '__' . $lang->symbol; } } if ($object->isAttributeChanged($field) == false || $object->{$field} == '') { continue; } $niceUrl = new NiceURL(); $niceUrl->object_class = get_class($object); $niceUrl->object_id = $object->getId(); $niceUrl->language_id = $lang->id; $slugGenerator = new SlugGenerator(); $niceUrl->slug = $slugGenerator->generateFrom($object->{$field}); $sameSlugCount = $this->slugCounter->run($niceUrl->slug); $sameSlugCount = $sameSlugCount != -1 ? '_' . ($sameSlugCount + 1) : ''; $url = $niceUrl->slug . $sameSlugCount; $niceUrl->url = $url; $collection->append($niceUrl); } return $collection; }