Exemple #1
0
 /**
  * Test getResourceDataMerged() functionality.
  * Expected result of method is placed in file fixture.
  */
 public function testGetResource()
 {
     $expectedResourceA = (include __DIR__ . '/../../../_files/config/resource_a_fixture.php');
     $this->assertEquals($expectedResourceA, $this->_config->getResourceDataMerged('namespaceAModuleA', 'v1'), 'Version 1 resource_a data does not match');
     $this->assertEquals(include __DIR__ . '/../../../_files/config/resource_a_fixture_v2.php', $this->_config->getResourceDataMerged('namespaceAModuleA', 'v2'), 'Version 2 resource_a data does not match.');
     $this->assertEquals(include __DIR__ . '/../../../_files/config/resource_a_subresource_b_fixture.php', $this->_config->getResourceDataMerged('namespaceAModuleASubresourceB', 'v1'), 'Version 1 resource_a_subresource_b data does no match.');
 }
Exemple #2
0
 /**
  * Generate WSDL content and save it to cache.
  *
  * @param array $requestedResources
  * @param string $endpointUrl
  * @return string
  * @throws Mage_Webapi_Exception
  */
 public function handle($requestedResources, $endpointUrl)
 {
     /** Sort requested resources by names to prevent caching of the same wsdl file more than once. */
     ksort($requestedResources);
     $cacheId = self::WSDL_CACHE_ID . hash('md5', serialize($requestedResources));
     if ($this->_cache->canUse(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_NAME)) {
         $cachedWsdlContent = $this->_cache->load($cacheId);
         if ($cachedWsdlContent !== false) {
             return $cachedWsdlContent;
         }
     }
     $resources = array();
     try {
         foreach ($requestedResources as $resourceName => $resourceVersion) {
             $resources[$resourceName] = $this->_apiConfig->getResourceDataMerged($resourceName, $resourceVersion);
         }
     } catch (Exception $e) {
         throw new Mage_Webapi_Exception($e->getMessage(), Mage_Webapi_Exception::HTTP_BAD_REQUEST);
     }
     $wsdlContent = $this->generate($resources, $endpointUrl);
     if ($this->_cache->canUse(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_NAME)) {
         $this->_cache->save($wsdlContent, $cacheId, array(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_TAG));
     }
     return $wsdlContent;
 }
Exemple #3
0
 /**
  * Set up config with fixture controllers directory scanner
  */
 protected function setUp()
 {
     $fixtureDir = __DIR__ . '/../../_files/Controller/AutoDiscover/';
     $directoryScanner = new \Zend\Code\Scanner\DirectoryScanner($fixtureDir);
     /** @var Mage_Core_Model_App $app */
     $app = $this->getMockBuilder('Mage_Core_Model_App')->disableOriginalConstructor()->getMock();
     $objectManager = new Magento_Test_ObjectManager();
     $this->_helper = $objectManager->get('Mage_Webapi_Helper_Config');
     $reader = $objectManager->get('Mage_Webapi_Model_Config_Reader_Soap');
     $reader->setDirectoryScanner($directoryScanner);
     $this->_config = new Mage_Webapi_Model_Config_Soap($reader, $this->_helper, $app);
     $objectManager->addSharedInstance($this->_config, 'Mage_Webapi_Model_Config_Soap');
     $wsdlFactory = new Mage_Webapi_Model_Soap_Wsdl_Factory($objectManager);
     $cache = $this->getMockBuilder('Mage_Core_Model_Cache')->disableOriginalConstructor()->getMock();
     $this->_autoDiscover = new Mage_Webapi_Model_Soap_AutoDiscover($this->_config, $wsdlFactory, $this->_helper, $cache);
     $this->_resourceName = 'vendorModuleB';
     $this->_resourceData = $this->_config->getResourceDataMerged($this->_resourceName, 'v1');
     $xml = $this->_autoDiscover->generate(array($this->_resourceName => $this->_resourceData), 'http://magento.host/api/soap');
     $this->_dom = new DOMDocument('1.0', 'utf-8');
     $this->_dom->loadXML($xml);
     $this->_xpath = new DOMXPath($this->_dom);
     $this->_xpath->registerNamespace(Wsdl::WSDL_NS, Wsdl::WSDL_NS_URI);
     parent::setUp();
 }