public function testFilterConfigured() { $config = $this->getMockBuilder('Magento\\Framework\\App\\Config\\ScopeConfigInterface')->disableOriginalConstructor()->setMethods(array('getValue', 'setValue', 'isSetFlag'))->getMock(); $config->expects($this->once())->method('getValue')->with('url/convert', 'default')->will($this->returnValue(array('char8482' => array('from' => '™', 'to' => 'TM')))); $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $this->model = $objectManager->getObject('Magento\\Framework\\Filter\\Translit', array('config' => $config)); $this->assertEquals('TM', $this->model->filter('™')); }
/** * Processing object before save data * * @return $this */ public function beforeSave() { if (!$this->getAttributeGroupCode()) { $groupName = $this->getAttributeGroupName(); if ($groupName) { $attributeGroupCode = trim(preg_replace('/[^a-z0-9]+/', '-', $this->translitFilter->filter(strtolower($groupName))), '-'); if (empty($attributeGroupCode)) { // in the following code md5 is not used for security purposes $attributeGroupCode = md5($groupName); } $this->setAttributeGroupCode($attributeGroupCode); } } return parent::beforeSave(); }
/** * Calculate group code based on group name. * * TODO: This logic is copy-pasted from \Magento\Eav\Model\Entity\Attribute\Group::beforeSave * TODO: and should be moved to a separate service, which will allow two-way conversion groupName <=> groupCode * TODO: Remove after MAGETWO-48290 is complete * * @param AttributeGroupInterface $group * @return string */ private function calculateGroupCode(AttributeGroupInterface $group) { $groupName = $group->getAttributeGroupName(); $attributeGroupCode = trim(preg_replace('/[^a-z0-9]+/', '-', $this->translitFilter->filter(strtolower($groupName))), '-'); if ($attributeGroupCode == 'images') { $attributeGroupCode = 'image-management'; } if (empty($attributeGroupCode)) { // in the following code md5 is not used for security purposes $attributeGroupCode = md5($groupName); } return $attributeGroupCode; }