Ejemplo n.º 1
0
 public function testAttributeEmptyDataModelClass()
 {
     $this->_attributeMetadata->expects($this->once())->method('getDataModel')->will($this->returnValue(''));
     $this->_attributeMetadata->expects($this->once())->method('getFrontendInput')->will($this->returnValue('text'));
     $dataModel = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form\\Text', array(), array(), '', false);
     $params = array('entityTypeCode' => $this->_entityTypeCode, 'value' => 'Some Text', 'isAjax' => false, 'attribute' => $this->_attributeMetadata);
     $this->_objectManager->expects($this->once())->method('create')->with('Magento\\Customer\\Model\\Metadata\\Form\\Text', $params)->will($this->returnValue($dataModel));
     $actual = $this->_elementFactory->create($this->_attributeMetadata, 'Some Text', $this->_entityTypeCode);
     $this->assertSame($dataModel, $actual);
 }
Ejemplo n.º 2
0
 /**
  * @covers Xoops\Form\ElementFactory::create
  * @covers Xoops\Form\ElementFactory::setContainer
  * @covers Xoops\Form\ElementFactory::validateSpec
  */
 public function testSetContainer()
 {
     $container = new ElementTray([]);
     $this->object->setContainer($container);
     $spec = new \ArrayObject([ElementFactory::CLASS_KEY => 'Raw', 'value' => 'myvalue']);
     $actual = $this->object->create($spec);
     $this->assertInstanceOf('\\Xoops\\Form\\Raw', $actual);
     $this->assertArrayHasKey(ElementFactory::FORM_KEY, $spec);
     $this->assertSame($container, $spec[ElementFactory::FORM_KEY]);
 }
Ejemplo n.º 3
0
 /**
  * Deletes current element
  */
 public function delete()
 {
     // Deletes element by factory
     ElementFactory::deleteElement($this);
 }
 /**
  * Translates the string in correct language
  * @param string $string The string to translate
  * @param array $paramList The param list to be replaced in the string
  * @param int $quantity The quantity to pluralize the string
  * @param string $category The translation's category
  * @return string The translated string
  */
 public function translate($string, $paramList = NULL, $quantity = NULL, $category = NULL)
 {
     // Checks if string has to be pluralized
     if ($quantity !== NULL && $quantity !== 1) {
         $string .= '_PLURAL';
     }
     // Set silent mode to avoid every translation log
     LogTool::getInstance()->setSilentMode();
     return $string;
     // Gets string from database
     try {
         if ($category !== NULL) {
             $category = ' AND translation_category = \'' . $category . '\'';
         } else {
             $category = '';
         }
         $translation = ElementFactory::getElement('Translation', NULL, 'translation_language = \'' . $this->getLocale() . '\' AND translation_text = \'' . $string . '\'' . $category);
         LogTool::getInstance()->unsetSilentMode();
         if ($paramList === NULL) {
             return $translation->value;
         }
         // String has params "%1" to be replaced
         if (!is_array($paramList)) {
             $paramList = array($paramList);
         }
         // Sets pattern to be replaced
         $patternList = array();
         for ($paramNumber = 1; $paramNumber <= count($paramList); ++$paramNumber) {
             $patternList[] = '/%' . $paramNumber . '(?![0-9])/';
         }
         return preg_replace($patternList, $paramList, $translation->value);
     } catch (ElementNoResultException $e) {
         // String is not localized
         try {
             $warningTracking = new WarningTracking();
             $warningTracking->addTracking("Missing " . $this->getLocale() . " translation on " . $string);
             // TODO : Get template.
             DatabaseFactory::commit();
         } catch (Exception $e) {
         }
         LogTool::getInstance()->unsetSilentMode();
         return 'TO_BE_LOCALIZED(' . $string . ')';
     }
 }
Ejemplo n.º 5
0
 /**
  * Return attribute data model by attribute
  *
  * @param \Magento\Customer\Service\V1\Data\Eav\AttributeMetadata $attribute
  * @return \Magento\Eav\Model\Attribute\Data\AbstractData
  */
 protected function _getAttributeDataModel($attribute)
 {
     $dataModel = $this->_elementFactory->create($attribute, isset($this->_attributeValues[$attribute->getAttributeCode()]) ? $this->_attributeValues[$attribute->getAttributeCode()] : null, $this->_entityType, $this->_isAjax);
     return $dataModel;
 }
 /**
  * Undefined methods interceptor
  * Adds method :
  * - getParentXxx($conditions, $orderBy)
  * @param string $methodName The called method name
  * @param string $params The called method parameters
  */
 public function __call($methodName, $params)
 {
     $regs = NULL;
     // getXXXList method type
     if (mb_ereg('^get([a-zA-Z0-9_]+)List$', $methodName, $regs)) {
         $elementClass = $regs[1];
         $conditions = count($params) >= 1 ? $params[0] : NULL;
         $orderBy = count($params) >= 2 ? $params[1] : NULL;
         return ElementFactory::getElementList($elementClass, $conditions, $orderBy);
     }
     throw new ElementException('Invalid method called: "' . $methodName . '"');
 }