Ejemplo n.º 1
0
 /**
  * Convert \SimpleXMLElement to array
  *
  * @param \SimpleXMLElement $element
  * @return array|string
  */
 private function convert(\SimpleXMLElement $element)
 {
     $result = [];
     // add children values
     $xmlConverter = new XmlConverter();
     if ($xmlConverter->hasChildren($element)) {
         foreach ($element->children() as $childName => $child) {
             if ($childName === 'suiteRule') {
                 $result['suiteRule'] = $this->convert($child);
             } elseif ($childName === 'objectRule') {
                 $class = (string) $child['for'];
                 $result['objectRules'][$class] = $this->convert($child);
             } elseif ($childName === 'allow') {
                 $result[$childName] = $this->convert($child);
             } elseif ($childName === 'deny') {
                 $result[$childName] = $this->convert($child);
             } else {
                 $result[$childName] = $this->convert($child);
             }
         }
     } else {
         if (empty($result)) {
             // return as string, if nothing was found
             $result = (string) $element;
         } else {
             // value has zero key element
             $result[0] = (string) $element;
         }
     }
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * Read entity files and merge them into one array
  *
  * @param string $entityName
  * @param string $scope
  * @return array
  */
 public function read($entityName, $scope = 'etc')
 {
     $result = [];
     $files = $this->fileResolver->get($entityName . '.xml', $scope);
     foreach ($files as $file) {
         $presetXml = simplexml_load_string($file);
         if ($presetXml instanceof \SimpleXMLElement) {
             $array = $this->xmlConverter->convert($presetXml);
             if (is_array($array)) {
                 $result = array_replace($result, $array);
             }
         }
     }
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * Get all tabs on the form
  *
  * @return array
  */
 protected function getTabs()
 {
     $result = [];
     $paths = glob(MTF_TESTS_PATH . preg_replace('/Magento\\/\\w+/', '*/*', str_replace('\\', '/', get_class($this))) . '.xml');
     $files = new File($paths);
     foreach ($files as $file) {
         $presetXml = simplexml_load_string($file);
         if ($presetXml instanceof \SimpleXMLElement) {
             $array = $this->xmlConverter->convert($presetXml);
             if (is_array($array)) {
                 $result = array_replace_recursive($result, $array);
             }
         }
     }
     return $result;
 }
Ejemplo n.º 4
0
 /**
  * Merge xml pages
  *
  * @param array $pages
  * @return array
  */
 protected function mergePagesXml(array $pages)
 {
     $result = [];
     foreach ($pages as $key => $page) {
         $file = reset($page);
         $pageConfig = ['file_name' => $file['file_name'], 'area' => $file['area']];
         foreach ($page as $file) {
             $content = file_get_contents($file['real_path']);
             $configXml = simplexml_load_string($content);
             if ($configXml instanceof \SimpleXMLElement) {
                 $pageConfig = array_replace_recursive($pageConfig, $this->xmlConverter->convert($configXml));
             }
         }
         $result[$key] = $pageConfig;
     }
     return $result;
 }
Ejemplo n.º 5
0
 /**
  * Read .xml file and convert it into array
  *
  * @param string $xmlFilePath
  * @return array
  */
 public function read($xmlFilePath)
 {
     $contentXml = simplexml_load_file($xmlFilePath);
     return $this->xmlConverter->convert($contentXml);
 }
Ejemplo n.º 6
0
 /**
  * Generate fixture classes from XML sources
  *
  * @param array $item
  * @return void
  */
 protected function generateClass(array $item)
 {
     $className = $item['file_name'];
     $modulePath = $item['module_path'];
     $folderPath = $item['folder_path'];
     $realPath = $item['real_path'];
     $namespace = $item['namespace'];
     $module = $item['module'];
     $contentXml = simplexml_load_file($realPath);
     $mTime = filemtime($realPath);
     $fields = [];
     $fieldsXml = $contentXml->xpath('fields');
     if ($fieldsXml) {
         foreach ($fieldsXml[0] as $fieldXml) {
             $name = $fieldXml->getName();
             $fields[$name] = (array) $fieldXml;
         }
     }
     $relativeFilePath = str_replace($modulePath . '/', '', $folderPath);
     $ns = $namespace . '\\' . $module . '\\' . str_replace('/', '\\', $relativeFilePath);
     $content = "<?php\n";
     $content .= "/**\n";
     $content .= " * {license_notice}\n";
     $content .= " *\n";
     $content .= " * @copyright   {copyright}\n";
     $content .= " * @license     {license_link}\n";
     $content .= " */\n\n";
     $content .= "namespace {$ns};\n\n";
     $content .= "use Mtf\\Fixture\\InjectableFixture;\n\n";
     $content .= "/**\n";
     $content .= " * Class {$className}\n";
     $content .= " */\n";
     $content .= "class {$className} extends InjectableFixture\n";
     $content .= "{\n";
     if (isset($contentXml->{'repository_class'})) {
         $content .= "    /**\n";
         $content .= "     * @var string\n";
         $content .= "     */\n";
         $content .= "    protected \$repositoryClass = '{$contentXml->{'repository_class'}}';\n\n";
     }
     if (isset($contentXml->{'handler_interface'})) {
         $content .= "    /**\n";
         $content .= "     * @var string\n";
         $content .= "     */\n";
         $content .= "    protected \$handlerInterface = '{$contentXml->{'handler_interface'}}';\n\n";
     }
     if (isset($contentXml->{'data_config'})) {
         $dataConfig = $this->xmlConverter->convert($contentXml->{'data_config'}[0]);
         if (is_array($dataConfig)) {
             $content .= "    protected \$dataConfig = ";
             $content .= $this->toArrayDefinition($dataConfig, '    ');
             $content .= ";\n\n";
         }
     }
     $content .= "    protected \$defaultDataSet = [\n";
     foreach ($fields as $name => $field) {
         if (empty($field['default_value'])) {
             continue;
         }
         $content .= "        '{$name}' => null,\n";
     }
     $content .= "    ];\n";
     foreach ($fields as $name => $field) {
         $content .= "\n    protected \${$name} = [\n";
         foreach ($field as $key => $value) {
             $content .= "        '{$key}' => '{$value}',\n";
         }
         $content .= "    ];\n";
     }
     foreach ($fields as $name => $field) {
         $content .= "\n" . '    public function get' . $this->toCamelCase($name) . '()' . "\n";
         $content .= "    {\n";
         $content .= "        return \$this->getData('" . $name . "');" . "\n";
         $content .= "    }\n";
     }
     $content .= "}\n";
     $newFilename = $className . '.php';
     if (file_exists($folderPath . '/' . $newFilename)) {
         $mmTime = filemtime($folderPath . '/' . $newFilename);
         if ($mTime > $mmTime) {
             return;
             // in order to not overwrite old fixtures
             unlink($folderPath . '/' . $newFilename);
         } else {
             return;
         }
     }
     if (!is_dir($folderPath)) {
         mkdir($folderPath, 0777, true);
     }
     file_put_contents($folderPath . '/' . $newFilename, $content);
     touch($folderPath . '/' . $newFilename, $mTime);
     $this->cnt++;
 }