Example #1
0
 /**
  * @covers Mage_DesignEditor_Model_Layout::sanitizeLayout
  * @expectedException Mage_Core_Exception
  * @expectedExceptionMessage Invalid block type: Namespace_Module_Block_NotSafe
  */
 public function testGenerateElements()
 {
     $layout = $this->_getLayoutWithTestUpdate();
     $layout->generateElements();
     $expectedXml = new Varien_Simplexml_Element(file_get_contents(__DIR__ . '/_files/expected_layout_update.xml'));
     $this->assertStringMatchesFormat($expectedXml->asNiceXml(), $layout->getNode()->asNiceXml());
     $layout = $this->_getLayoutWithTestUpdate(false);
     $layout->generateElements();
 }
Example #2
0
 /**
  * Returns a scalar representation of actual value,
  * Returns $other if internal acutal value is not set
  *
  * @param Varien_Simplexml_Element $other
  * @return scalar
  */
 protected function getActualValue($other = null)
 {
     if (!$this->_useActualValue && $other->hasChildren()) {
         return $other->asNiceXml();
     } elseif (!$this->_useActualValue) {
         return (string) $other;
     }
     return parent::getActualValue($other);
 }
Example #3
0
 /**
  * Install application using temporary directory and vendor-specific database settings
  *
  * @throws Magento_Exception
  */
 protected function _install()
 {
     $this->_ensureDirExists($this->_installDir);
     $this->_ensureDirExists($this->_installEtcDir);
     $this->_ensureDirExists($this->_installDir . DIRECTORY_SEPARATOR . 'media');
     $this->_ensureDirExists($this->_installDir . DIRECTORY_SEPARATOR . 'skin');
     /* Copy *.xml configuration files */
     $dirs = array($this->_installEtcDir => $this->_globalEtcFiles, $this->_installEtcDir . '/modules' => $this->_moduleEtcFiles);
     foreach ($dirs as $targetEtcDir => $sourceEtcFiles) {
         $this->_ensureDirExists($targetEtcDir);
         foreach ($sourceEtcFiles as $sourceEtcFile) {
             $targetEtcFile = $targetEtcDir . '/' . basename($sourceEtcFile);
             copy($sourceEtcFile, $targetEtcFile);
         }
     }
     /* Make sure that local.xml contains an invalid installation date */
     $installDate = (string) $this->_localXml->global->install->date;
     if ($installDate && strtotime($installDate)) {
         throw new Magento_Exception("Configuration file '{$this->_localXmlFile}' must contain an invalid installation date.");
     }
     /* Replace local.xml */
     $targetLocalXml = $this->_installEtcDir . '/local.xml';
     $this->_localXml->asNiceXml($targetLocalXml);
     /* Initialize an application in non-installed mode */
     $this->initialize();
     /* Run all install and data-install scripts */
     Mage_Core_Model_Resource_Setup::applyAllUpdates();
     Mage_Core_Model_Resource_Setup::applyAllDataUpdates();
     /* Enable configuration cache by default in order to improve tests performance */
     Mage::app()->getCacheInstance()->saveOptions(array('config' => 1));
     /* Fill installation date in local.xml to indicate that application is installed */
     $localXml = file_get_contents($targetLocalXml);
     $localXml = str_replace($installDate, date('r'), $localXml, $replacementCount);
     if ($replacementCount != 1) {
         throw new Magento_Exception("Unable to replace installation date properly in '{$targetLocalXml}' file.");
     }
     file_put_contents($targetLocalXml, $localXml, LOCK_EX);
     /* Add predefined admin user to the system */
     $this->_createAdminUser();
     /* Make a database backup to be able to restore it to initial state any time */
     $this->_db->createBackup(self::DB_BACKUP_NAME);
     /* Switch an application to installed mode */
     $this->initialize();
     /**
      * Initialization of front controller with all routers.
      * Should be here as needed only once after installation process.
      */
     Mage::app()->getFrontController();
 }
 /**
  * Convert attributes data to xml
  *
  * @param Enterprise_GiftRegistry_Model_Type $type
  * @return string
  */
 public function processData($type)
 {
     if ($data = $type->getAttributes()) {
         $xmlObj = new Varien_Simplexml_Element('<config></config>');
         $typeXml = $xmlObj->addChild(self::XML_PROTOTYPE_NODE);
         if (is_array($data)) {
             $groups = array();
             foreach ($data as $attributes) {
                 foreach ($attributes as $attribute) {
                     if ($attribute['group'] == self::XML_REGISTRANT_NODE) {
                         $group = self::XML_REGISTRANT_NODE;
                     } else {
                         $group = self::XML_REGISTRY_NODE;
                     }
                     $groups[$group][$attribute['code']] = $attribute;
                 }
             }
             foreach ($groups as $group => $attributes) {
                 $this->processDataType($typeXml, $group, $attributes);
             }
         }
         return $xmlObj->asNiceXml();
     }
 }
 public function savePackage()
 {
     if ($this->getData('file_name') != '') {
         $fileName = $this->getData('file_name');
         $this->unsetData('file_name');
     } else {
         $fileName = $this->getName();
     }
     if (!preg_match('/^[a-z0-9]+[a-z0-9\\-\\_\\.]*([\\/\\\\]{1}[a-z0-9]+[a-z0-9\\-\\_\\.]*)*$/i', $fileName)) {
         return false;
     }
     if (!$this->getPackageXml()) {
         $this->generatePackageXml();
     }
     if (!$this->getPackageXml()) {
         return false;
     }
     $pear = Varien_Pear::getInstance();
     $dir = Mage::getBaseDir('var') . DS . 'pear';
     if (!@file_put_contents($dir . DS . 'package.xml', $this->getPackageXml())) {
         return false;
     }
     $pkgver = $this->getName() . '-' . $this->getReleaseVersion();
     $this->unsPackageXml();
     $this->unsRoles();
     $xml = Mage::helper('core')->assocToXml($this->getData());
     $xml = new Varien_Simplexml_Element($xml->asXML());
     // prepare dir to save
     $parts = explode(DS, $fileName);
     array_pop($parts);
     $newDir = implode(DS, $parts);
     if (!empty($newDir) && !is_dir($dir . DS . $newDir)) {
         if (!@mkdir($dir . DS . $newDir, 0777, true)) {
             return false;
         }
     }
     if (!@file_put_contents($dir . DS . $fileName . '.xml', $xml->asNiceXml())) {
         return false;
     }
     return true;
 }
 /**
  * Save package file to var/connect.
  *
  * @return boolean
  */
 public function savePackage()
 {
     if ($this->getData('file_name') != '') {
         $fileName = $this->getData('file_name');
         $this->unsetData('file_name');
     } else {
         $fileName = $this->getName();
     }
     if (!preg_match('/^[a-z0-9]+[a-z0-9\\-\\_\\.]*([\\/\\\\]{1}[a-z0-9]+[a-z0-9\\-\\_\\.]*)*$/i', $fileName)) {
         return false;
     }
     if (!$this->getPackageXml()) {
         $this->generatePackageXml();
     }
     if (!$this->getPackageXml()) {
         return false;
     }
     $path = Mage::helper('connect')->getLocalPackagesPath();
     if (!@file_put_contents($path . 'package.xml', $this->getPackageXml())) {
         return false;
     }
     $this->unsPackageXml();
     $this->unsTargets();
     $xml = Mage::helper('core')->assocToXml($this->getData());
     $xml = new Varien_Simplexml_Element($xml->asXML());
     // prepare dir to save
     $parts = explode(DS, $fileName);
     array_pop($parts);
     $newDir = implode(DS, $parts);
     if (!empty($newDir) && !is_dir($path . $newDir)) {
         if (!@mkdir($path . $newDir, 0777, true)) {
             return false;
         }
     }
     if (!@file_put_contents($path . $fileName . '.xml', $xml->asNiceXml())) {
         return false;
     }
     return true;
 }
Example #7
0
 /**
  * Determine dependency type from XML node that defines module dependency
  *
  * @param Varien_Simplexml_Element $dependencyNode
  * @return string
  * @throws UnexpectedValueException
  */
 protected function _getDependencyType(Varien_Simplexml_Element $dependencyNode)
 {
     $result = $dependencyNode->getAttribute('type') ?: self::DEPENDENCY_TYPE_HARD;
     if (!in_array($result, array(self::DEPENDENCY_TYPE_HARD, self::DEPENDENCY_TYPE_SOFT))) {
         $dependencyNodeXml = trim($dependencyNode->asNiceXml());
         throw new UnexpectedValueException("Unknown module dependency type '{$result}' in declaration '{$dependencyNodeXml}'.");
     }
     return $result;
 }
Example #8
0
 public function getDeliveryDateAll($vendor, $address, $weight, $value, $shipDate)
 {
     $reqKey = implode('-', array($vendor->getId(), $address->getId(), $weight, $value, $shipDate));
     if (isset($this->_deliveryDatesCache[$reqKey])) {
         return $this->_deliveryDatesCache[$reqKey];
     }
     $this->setVendor($vendor);
     $currencyCode = $address->getQuote()->getBaseCurrencyCode();
     $request = new Varien_Simplexml_Element('<TimeInTransitRequest/>');
     $request->setNode('Request/TransactionReference/CustomerContext', '1');
     $request->setNode('Request/TransactionReference/XpciVersion', '1.0');
     $request->setNode('Request/RequestAction', 'TimeInTransit');
     $request->setNode('TransitFrom/AddressArtifactFormat/PoliticalDivision1', $vendor->getRegionCode());
     $request->setNode('TransitFrom/AddressArtifactFormat/PoliticalDivision2', $vendor->getCity());
     $request->setNode('TransitFrom/AddressArtifactFormat/PostcodePrimaryLow', $vendor->getZip());
     $request->setNode('TransitFrom/AddressArtifactFormat/CountryCode', $vendor->getCountryId());
     $request->setNode('TransitTo/AddressArtifactFormat/PoliticalDivision1', $address->getRegionCode());
     $request->setNode('TransitTo/AddressArtifactFormat/PoliticalDivision2', $address->getCity());
     $request->setNode('TransitTo/AddressArtifactFormat/PostcodePrimaryLow', $address->getPostcode());
     $request->setNode('TransitTo/AddressArtifactFormat/CountryCode', $address->getCountryId());
     $request->setNode('PickupDate', date('Ymd', strtotime($shipDate)));
     $request->setNode('InvoiceLineTotal/CurrencyCode', $currencyCode);
     $request->setNode('InvoiceLineTotal/MonetaryValue', round($value, 2));
     $request->setNode('ShipmentWeight/UnitOfMeasurement/Code', $address->getQuote()->getStore()->getConfig('carriers/ups/unit_of_measure'));
     $request->setNode('ShipmentWeight/Weight', $weight);
     $xmlRequest = '<?xml version="1.0"?>' . $request->asNiceXml();
     $this->setXMLAccessRequest();
     $xmlResponse = $this->_callShippingXml('TimeInTransit', $xmlRequest);
     $response = new Varien_Simplexml_Element($xmlResponse);
     $result = array();
     try {
         $this->_validateResponse($response, false);
         $arr = $response->xpath("//TimeInTransitResponse/TransitResponse/ServiceSummary");
         foreach ($arr as $a) {
             if (isset($a->Service->Code) && isset($a->EstimatedArrival->Date)) {
                 $result[(string) $a->Service->Code] = (string) $a->EstimatedArrival->Date;
             }
         }
     } catch (Exception $e) {
         $result = array();
     }
     $this->_deliveryDatesCache[$reqKey] = $result;
     return $result;
 }
Example #9
0
 public function savePackage()
 {
     if ($this->getData('file_name') != '') {
         $fileName = $this->getData('file_name');
         $this->unsetData('file_name');
     } else {
         $fileName = $this->getName();
     }
     if (!preg_match('/^[a-z0-9]+[a-z0-9\\-\\_\\.]*([\\/\\\\]{1}[a-z0-9]+[a-z0-9\\-\\_\\.]*)*$/i', $fileName)) {
         return false;
     }
     if (!$this->getPackageXml()) {
         $this->generatePackageXml();
     }
     if (!$this->getPackageXml()) {
         return false;
     }
     $pear = Varien_Pear::getInstance();
     $dir = Mage::getBaseDir('var') . DS . 'pear';
     try {
         $this->_filesystem->write($dir . DS . 'package.xml', $this->getPackageXml());
     } catch (Magento_Filesystem_Exception $e) {
         return false;
     }
     $pkgver = $this->getName() . '-' . $this->getReleaseVersion();
     $this->unsPackageXml();
     $this->unsRoles();
     $xml = Mage::helper('Mage_Core_Helper_Data')->assocToXml($this->getData());
     $xml = new Varien_Simplexml_Element($xml->asXML());
     try {
         $this->_filesystem->write($dir . DS . $fileName . '.xml', $xml->asNiceXml());
     } catch (Magento_Filesystem_Exception $e) {
         return false;
     }
     return true;
 }
Example #10
0
 /**
  * Save package file to var/connect.
  *
  * @return boolean
  */
 public function savePackage()
 {
     if ($this->getData('file_name') != '') {
         $fileName = $this->getData('file_name');
         $this->unsetData('file_name');
     } else {
         $fileName = $this->getName();
     }
     if (!preg_match('/^[a-z0-9]+[a-z0-9\\-\\_\\.]*([\\/\\\\]{1}[a-z0-9]+[a-z0-9\\-\\_\\.]*)*$/i', $fileName)) {
         return false;
     }
     if (!$this->getPackageXml()) {
         $this->generatePackageXml();
     }
     if (!$this->getPackageXml()) {
         return false;
     }
     try {
         $path = Mage::helper('Mage_Connect_Helper_Data')->getLocalPackagesPath();
         $this->_filesystem->write($path . 'package.xml', $this->getPackageXml());
         $this->unsPackageXml();
         $this->unsTargets();
         $xml = Mage::helper('Mage_Core_Helper_Data')->assocToXml($this->getData());
         $xml = new Varien_Simplexml_Element($xml->asXML());
         // prepare dir to save
         $parts = explode(DS, $fileName);
         array_pop($parts);
         $newDir = implode(DS, $parts);
         if (!empty($newDir) && !$this->_filesystem->isDirectory($path . $newDir)) {
             $this->_filesystem->ensureDirectoryExists($path, $newDir, 0777);
         }
         $this->_filesystem->write($path . $fileName . '.xml', $xml->asNiceXml());
     } catch (Magento_Filesystem_Exception $e) {
         return false;
     }
     return true;
 }
Example #11
0
 public function voidLabel($track)
 {
     if (!Mage::getStoreConfig('udropship/vendor/void_labels')) {
         return $this;
     }
     $request = new Varien_Simplexml_Element('<VoidShipmentRequest/>');
     $request->setNode('Request/TransactionReference/CustomerContext', $orderId);
     $request->setNode('Request/TransactionReference/XpciVersion', '1.0');
     $request->setNode('Request/RequestAction', '1');
     $request->setNode('Request/RequestOption', '1');
     $request->setNode('ShipmentIdentificationNumber', $track->getNumber());
     $xmlRequest = '<?xml version="1.0"?>' . $request->asNiceXml();
     $this->setXMLAccessRequest();
     $xmlResponse = $this->_callShippingXml('Void', $xmlRequest);
     $response = new Varien_Simplexml_Element($xmlResponse);
     $this->_validateResponse($response, false);
     return $this;
 }
Example #12
0
 /**
  * @param array $source
  * @param array $result
  * @param bool $isXml
  *
  * @dataProvider getLayoutUpdateActionDataProvider
  */
 public function testGetLayoutUpdateAction(array $source, array $result, $isXml = false)
 {
     $this->getRequest()->setPost($source);
     $this->dispatch('backend/admin/system_design_editor/getLayoutUpdate');
     $response = $this->_dataHelper->jsonDecode($this->getResponse()->getBody());
     // convert to XML string to the same format as in $result
     if ($isXml) {
         foreach ($response as $code => $data) {
             foreach ($data as $key => $value) {
                 $xml = new Varien_Simplexml_Element($value);
                 $response[$code][$key] = $xml->asNiceXml();
             }
         }
     }
     $this->assertEquals($result, $response);
 }
 /**
  * Changes extension suite internal tests status
  *
  * @param bool $status
  */
 protected function _changeBuiltInTestStatus($status)
 {
     if (!file_exists($this->getArg('project') . '/app/etc/modules/EcomDev_PHPUnitTest.xml')) {
         die('Cannot find EcomDev_PHPUnitTest.xml file in app/etc/modules directory');
     }
     $disableFile = $this->getArg('project') . '/app/etc/modules/ZDisable_EcomDev_PHPUnitTest.xml';
     if ($status && file_exists($disableFile)) {
         unlink($disableFile);
     } elseif (!$status && !file_exists($disableFile)) {
         $fileContent = new Varien_Simplexml_Element('<config />');
         $fileContent->addChild('modules')->addChild('EcomDev_PHPUnitTest')->addChild('active', 'false');
         $fileContent->asNiceXml($disableFile);
     }
 }