public function setUp() { parent::setUp(); $this->_model = Application_Model_Factory::getModel($this->_targetServer); $this->_adapter = new Zend_Http_Client_Adapter_Test(); $this->_model->getHttpClient()->setAdapter($this->_adapter); }
/** * Zakladni akce vyhledavani v obchode */ public function basicAction() { $isTest = Zend_Registry::get('config')->mtgim->isTest; $cardname = trim($this->_request->getParam('cardname')); $adapterName = $this->_request->getParam('adapter'); $foilType = $this->_request->getParam('foil'); if (!empty($cardname) && !empty($adapterName)) { //get adapter $adapter = Application_Model_Factory::getModel($adapterName, $foilType, $isTest); } try { if (isset($adapter) && $adapter->doCardRequest($cardname)) { $data = $adapter->getData(); $this->view->success = TRUE; $this->view->total = count($data); $this->view->results = $data; } else { $this->view->success = FALSE; $this->view->reason = 'NO_VALID_DATA'; } } catch (Exception $e) { $this->view->success = FALSE; $this->view->reason = 'PARSE_ERROR'; if (1 == $isTest) { $this->view->message = $e->getMessage(); $this->view->trace = $e->getTraceAsString(); } } }
/** * Akce pro nalezeni ceny karty - odpovida vyhledavani karty na webu */ public function findPriceAction() { // --- nacteni vstupnich parametru --- $accKey = $this->_request_data['AccessKey']; $acc = $this->_getAccData($accKey); // overim, ze shop je validni i kdyz pouziju fake if (array_key_exists('Shop', $this->_request_data)) { if (!array_key_exists($this->_request_data['Shop'], Application_Model_Factory::getAvailableModels())) { return $this->_invalidResponse('Invalid Shop specified'); } // pokud je ucet testovaci, pouzivam fake adapter nezavisle na tom, co specifikoval if ($acc['isTest']) { $shop = 'fake'; $isTest = 1; } else { $shop = $this->_request_data['Shop']; $isTest = Zend_Registry::get('config')->mtgim->isTest; } } else { return $this->_invalidResponse('Missing Shop'); } if (array_key_exists('FoilType', $this->_request_data)) { $foil = $this->_request_data['FoilType']; if (!in_array($foil, array('A', 'R', 'F'))) { return $this->_invalidResponse('Invalid FoilType specified'); } } else { return $this->_invalidResponse('Missing FoilType'); } if (array_key_exists('CardName', $this->_request_data)) { $name = $this->_request_data['CardName']; } else { return $this->_invalidResponse('Missing CardName'); } // --- overeni podpisu --- // zde opravdu musi byt request data shop, protoze podpis se overuje z toho, co zaslal uzivatel // ne z toho co mu podstrcim ja if (!array_key_exists('Signature', $this->_request_data) || $this->_getFindPriceSignature($acc, $name, $this->_request_data['Shop'], $foil) != $this->_request_data['Signature']) { return $this->_invalidResponse('Invalid Signature', 401); } // --- inicializace a pouziti adapteru --- $adapter = Application_Model_Factory::getModel($shop, $foil, $isTest); try { $adapter->doCardRequest($name); $data = array('data' => $adapter->getData()); } catch (Exception $e) { return $this->_invalidResponse('Error communicating with shop', 500); } // --- odpoved --- $this->_response_data = $data; }
/** * Test vraceni adapteru pro CR * @dataProvider basicProvider */ public function testAdapterBasic($adapterClass, $adapterName) { $this->assertInstanceOf($adapterClass, Application_Model_Factory::getModel($adapterName)); }