Esempio n. 1
0
 /**
  * Test get method.
  */
 public function testGet()
 {
     /** Mock front controller mock to return Soap api type. */
     $this->_apiFrontController->expects($this->once())->method('determineApiType')->will($this->returnValue(Mage_Webapi_Controller_Front::API_TYPE_SOAP));
     /** Assert object manager get method will be executed once with Mage_Webapi_Controller_Response parameter. */
     $this->_objectManager->expects($this->once())->method('get')->with('Mage_Webapi_Controller_Response');
     $this->_factory->get();
 }
Esempio n. 2
0
 /**
  * Test action controller method with exception.
  */
 public function testCreateActionControllerWithException()
 {
     /** Create object of class which is not instance of Mage_Webapi_Controller_ActionAbstract. */
     $wrongController = new Varien_Object();
     /** Create request object. */
     $request = new Mage_Webapi_Controller_Request('SOAP');
     /** Mock object manager create method to return wrong controller */
     $this->_objectManagerMock->expects($this->any())->method('create')->will($this->returnValue($wrongController));
     $this->setExpectedException('InvalidArgumentException', 'The specified class is not a valid API action controller.');
     $this->_factory->createActionController('ClassName', $request);
 }
Esempio n. 3
0
 /**
  * Test getValidatorConfig created correct validator config. Check that validator translator was initialized.
  */
 public function testGetValidatorConfig()
 {
     $this->_objectManager->expects($this->at(2))->method('create')->with('Mage_Core_Model_Translate_Expr')->will($this->returnValue(new Mage_Core_Model_Translate_Expr()));
     $factory = new Mage_Core_Model_Validator_Factory($this->_objectManager, $this->_config, $this->_translateAdapter);
     $actualConfig = $factory->getValidatorConfig();
     $this->assertInstanceOf('Magento_Validator_Config', $actualConfig, 'Object of incorrect type was created');
     // Check that validator translator was correctly instantiated
     $validatorTranslator = Magento_Validator_ValidatorAbstract::getDefaultTranslator();
     $this->assertInstanceOf('Magento_Translate_Adapter', $validatorTranslator, 'Default validator translate adapter was not set correctly');
     // Dive into callback
     /** @var Mage_Core_Model_Translate $translateAdapter */
     $this->assertEquals('Test message', $validatorTranslator->translate('Test message'), 'Translator callback function was not initialized');
 }
Esempio n. 4
0
 /**
  * Test get method with wrong Renderer class.
  */
 public function testGetWithWrongRendererClass()
 {
     $acceptTypes = array('application/json');
     $availableRenders = $this->_createConfigElementForRenders();
     /** Mock application config getNode method to return the list of renders. */
     $this->_applicationMock->expects($this->once())->method('getNode')->will($this->returnValue($availableRenders));
     /** Mock request getAcceptTypes method to return specified value. */
     $this->_requestMock->expects($this->once())->method('getAcceptTypes')->will($this->returnValue($acceptTypes));
     /** Mock object to return Varien_Object */
     $this->_objectManagerMock->expects($this->once())->method('get')->with('Mage_Webapi_Controller_Response_Rest_Renderer_Json')->will($this->returnValue(new Varien_Object()));
     $this->setExpectedException('LogicException', 'The renderer must implement "Mage_Webapi_Controller_Response_Rest_RendererInterface".');
     $this->_factory->get();
 }
Esempio n. 5
0
 public function testCreateLayoutGetSharedInstance()
 {
     $this->_arguments = array('area' => 'TestArea');
     $this->_objectManager->expects($this->once())->method('hasSharedInstance')->with(self::CLASS_NAME)->will($this->returnValue(true));
     $modelLayout = $this->getMock(self::CLASS_NAME, array('getArea'), array(), '', false);
     $this->_objectManager->expects($this->at(1))->method('get')->with(self::CLASS_NAME)->will($this->returnValue($modelLayout));
     $modelLayout->expects($this->any())->method('getArea')->will($this->returnValue('TestArea'));
     $this->_objectManager->expects($this->never())->method('removeSharedInstance');
     $this->_objectManager->expects($this->never())->method('create');
     $this->_objectManager->expects($this->never())->method('addSharedInstance');
     $this->_objectManager->expects($this->at(2))->method('get')->with(self::CLASS_NAME)->will($this->returnValue($modelLayout));
     $this->assertEquals($modelLayout, $this->_model->createLayout($this->_arguments));
 }
 /**
  * Test for Mage_Adminhtml_Catalog_ProductController::quickCreateAction
  */
 public function testQuickCreateActionWithDangerRequest()
 {
     $data = array('entity_id' => 234);
     $this->_request->expects($this->any())->method('getParam')->will($this->returnValue($data));
     $typeInstance = $this->getMockBuilder('Mage_Catalog_Model_Product_Type')->setMethods(array('getConfigurableAttributes', 'getEditableAttributes'))->getMock();
     $typeInstance->expects($this->any())->method('getEditableAttributes')->will($this->returnValue(array()));
     $typeInstance->expects($this->any())->method('getConfigurableAttributes')->will($this->returnValue(array()));
     $productMock = $this->getMockBuilder('Mage_Catalog_Model_Product')->setMethods(array('getIdFieldName', 'save', 'getSku', 'isConfigurable', 'setStoreId', 'load', 'setTypeId', 'setAttributeSetId', 'getAttributeSetId', 'getTypeInstance', 'getWebsiteIds'))->disableOriginalConstructor()->getMock();
     $productMock->expects($this->any())->method('getIdFieldName')->will($this->returnValue('entity_id'));
     $productMock->expects($this->any())->method('isConfigurable')->will($this->returnValue(true));
     $productMock->expects($this->any())->method('setStoreId')->will($this->returnSelf());
     $productMock->expects($this->any())->method('load')->will($this->returnSelf());
     $productMock->expects($this->any())->method('setTypeId')->will($this->returnSelf());
     $productMock->expects($this->any())->method('setAttributeSetId')->will($this->returnSelf());
     $productMock->expects($this->any())->method('getTypeInstance')->will($this->returnValue($typeInstance));
     $productMock->expects($this->never())->method('save');
     $this->_response->expects($this->once())->method('setBody')->with('{"attributes":[],"error":{"message":"Unable to create product"}}');
     $helper = $this->getMockBuilder('Mage_Core_Helper_Data')->setMethods(array('jsonEncode'))->getMock();
     $helper->expects($this->once())->method('jsonEncode')->with(array('attributes' => array(), 'error' => array('message' => 'Unable to create product', 'fields' => array('sku' => ''))))->will($this->returnValue('{"attributes":[],"error":{"message":"Unable to create product"}}'));
     $this->_objectManager->expects($this->any())->method('create')->with('Mage_Catalog_Model_Product', array(), true)->will($this->returnValue($productMock));
     $this->_objectManager->expects($this->any())->method('get')->with('Mage_Core_Helper_Data', array())->will($this->returnValue($helper));
     $this->_controller->quickCreateAction();
 }
Esempio n. 7
0
 /**
  * Test create method
  */
 public function testCreate()
 {
     $arguments = array('property' => 'value');
     $this->_objectManager->expects($this->once())->method('create')->with('Mage_Webapi_Model_Acl_User', $arguments)->will($this->returnValue($this->_expectedObject));
     $this->assertEquals($this->_expectedObject, $this->_model->create($arguments));
 }
Esempio n. 8
0
 public function testCreateRole()
 {
     $arguments = array('5', '6');
     $this->_objectManager->expects($this->once())->method('create')->with('Mage_Webapi_Model_Authorization_Role', $arguments, false)->will($this->returnValue($this->_expectedObject));
     $this->assertEquals($this->_expectedObject, $this->_model->createRole($arguments));
 }
Esempio n. 9
0
 public function testCreateFromArray()
 {
     $this->_objectManager->expects($this->once())->method('create')->with('Mage_Core_Model_Url', array(), false)->will($this->returnValue('ModelInstance'));
     $this->assertEquals('ModelInstance', $this->_model->createFromArray());
 }
Esempio n. 10
0
 public function testGetLayout()
 {
     $this->_objectManager->expects($this->once())->method('get')->with('Mage_Core_Model_Layout')->will($this->returnValue(self::LAYOUT_INSTANCE));
     $this->assertEquals(self::LAYOUT_INSTANCE, $this->_model->getLayout());
 }
Esempio n. 11
0
 public function testCreateResource()
 {
     $arguments = array('5', '6');
     $this->_objectManager->expects($this->once())->method('create')->with('Magento_Acl_Resource', $arguments, false)->will($this->returnValue($this->_expectedObject));
     $this->assertEquals($this->_expectedObject, $this->_model->createResource($arguments));
 }