/** * @dataProvider dataProvideForSaveAction * @param $redirectBack * @param $isAuthorized */ public function testSaveAction($redirectBack, $isAuthorized) { $response = new Varien_Object(); $channelId = mt_rand(1000, 9999); $channelData = array('channel_data' => 'test'); $mrequest = new Mage_Core_Controller_Request_Http(); $mrequest->setParam('back', $redirectBack); $mrequest->setParam('channel_id', $channelId); $mrequest->setPost($channelData); $mockController = $this->_getControllerMock($mrequest, $response, array('_getSession', '_redirect', '_redirectToGrid', 'setChannelData')); $accountMock = new Varien_Object(array('user_id' => $isAuthorized)); $channel = $this->mockModel('xcom_ebay/channel', array('addData', 'getAccount', 'validate', 'save', 'load')); $channel->expects($this->once())->method('addData')->with($channelData); $channel->expects($this->once())->method('getAccount')->will($this->returnValue($accountMock)); $channel->expects($this->once())->method('load')->with($channelId)->will($this->returnSelf()); $sessionMock = $this->mockModel('adminhtml/session', array('addSuccess', 'setXcomEbayData', 'addError')); $sessionMock->expects($this->any())->method('setXcomEbayData'); $sessionMock->expects($this->any())->method('addError')->will($this->returnValue($mockController)); $mockController->expects($this->any())->method('_getSession')->will($this->returnValue($sessionMock)); if ($isAuthorized) { $channel->expects($this->once())->method('validate'); $channel->expects($this->once())->method('save'); } if ($redirectBack && false !== $isAuthorized) { $mockController->expects($this->once())->method('_redirect'); } elseif (false !== $isAuthorized) { $mockController->expects($this->once())->method('_redirectToGrid'); } $mockController->saveAction(); }
public function testSetPost() { $post = $_POST; $this->_model->setPost(array('test' => 'test')); $post['test'] = 'test'; $this->assertEquals($post, $this->_model->getPost()); $this->_model->setPost('key', 'value'); $post['key'] = 'value'; $this->assertEquals($post, $this->_model->getPost()); }
public function decode($encodedParameters, $version) { // The !empty() ensures that rows without a version number can be // executed (not without any risk). if (!empty($version) && $this->_getVersion() != $version) { throw new Exception(sprintf("Can't decode the Action encoded with %s Tracker v %s; current System Config Tracker is v %s ", $this->_code, $version, $this->_getVersion())); } $parameters = $this->_decodeParams($encodedParameters); $request = new Mage_Core_Controller_Request_Http(); $request->setPost($parameters); $request->setQuery($parameters); // @todo $_FILE? return $request; }
public function decode($encodedParameters, $version) { // The !empty() ensures that rows without a version number can be // executed (not without any risk). if (!empty($version) && $this->_getVersion() != $version) { throw new Exception(sprintf("Can't decode the Action encoded with %s Tracker v %s; current Website Tracker is v %s ", $this->_code, $version, $this->_getVersion())); } $params = $this->_decodeParams($encodedParameters); switch ($params['store_action']) { // // Handle saving of existing Website // case 'edit': // Convert Default Group UUID $defaultGroupUuid = $params['website']['default_group_id']; $defaultGroup = Mage::getModel('core/store_group')->load($defaultGroupUuid, 'name'); if ($defaultGroup->getId()) { $params['website']['default_group_id'] = $defaultGroup->getId(); } else { throw new Exception('Group \'' . $defaultGroupUuid . '\' not found!'); } // Convert Website UUID $websiteUuid = $params['website']['website_id']; $website = Mage::getModel('core/website')->load($websiteUuid, 'code'); if ($website->getId()) { $params['website']['website_id'] = $website->getId(); } else { throw new Exception('Website \'' . $websiteUuid . '\' not found!'); } // break intentionally omitted // // Handle adding new Website // // break intentionally omitted // // Handle adding new Website // case 'add': // Nothing to convert break; // // Handle deleting existing Website // store_action parameter is undefined in case of delete // // // Handle deleting existing Website // store_action parameter is undefined in case of delete // default: //Convert Item UUID $itemUuid = $params['item_id']; $website = Mage::getModel('core/website')->load($itemUuid, 'code'); if ($website->getId()) { $params['item_id'] = $website->getId(); } else { throw new Exception('Website \'' . $itemUuid . '\' not found!'); } break; } $request = new Mage_Core_Controller_Request_Http(); $request->setPost($params); $_SERVER['REQUEST_METHOD'] = 'POST'; // needed by StoreController $request->setQuery($params); return $request; }
public function decode($encodedParameters, $version) { // The !empty() ensures that rows without a version number can be // executed (not without any risk). if (!empty($version) && $this->_getVersion() != $version) { throw new Exception(sprintf("Can't decode the Action encoded with %s Tracker v %s; current Attribute Tracker is v %s ", $this->_code, $version, $this->_getVersion())); } $parameters = $this->_decodeParams($encodedParameters); #$attributeCode = $parameters['mageploy_uuid']; if (isset($parameters['attribute_code'])) { $attributeCode = $parameters['attribute_code']; } else { $attributeCode = $parameters['attribute_id']; } // Prepare the Attribute Option Structure that will be used to // decode parameters and try to guess if an existing option has been // changed or added. // Note: we are assuming we never change admin's value $attribute = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($attributeCode)->getFirstItem(); if ($attribute->getSourceModel()) { $attributeOptions = $attribute->getSource()->getAllOptions(false); $attributeOptionsByValue = array(); foreach ($attributeOptions as $order => $valuelabel) { $optionId = $valuelabel['value']; $adminVal = $valuelabel['label']; $attributeOptionsByValue[$adminVal] = array('order' => $order, 'id' => $optionId); } } $entityTypeId = Mage::helper('pugmore_mageploy')->getEntityTypeIdFromCode(Mage_Catalog_Model_Product::ENTITY); if ($attributeId = Mage::helper('pugmore_mageploy')->getAttributeIdFromCode($attributeCode, $entityTypeId)) { $parameters['attribute_id'] = $attributeId; } // Decode Attribute Options if (isset($parameters['option'])) { $option = $parameters['option']; // Used to store new options $newOptions = array(); // Value $newValues = array(); foreach ($option['value'] as $optionUuid => $optionValues) { $optionId = $this->_getOptionIdByUuid($optionUuid, $attributeOptionsByValue, $newOptions); $newValues[$optionId] = array(); foreach ($optionValues as $storeCode => $value) { $storeId = Mage::getModel('core/store')->load($storeCode)->getId(); $newValues[$optionId][$storeId] = $value; } } $parameters['option']['value'] = $newValues; // Order $newOrders = array(); foreach ($option['order'] as $optionUuid => $optionOrder) { $optionId = $this->_getOptionIdByUuid($optionUuid, $attributeOptionsByValue, $newOptions); $newOrders[$optionId] = $optionOrder; } $parameters['option']['order'] = $newOrders; // Delete $newDeletes = array(); foreach ($option['delete'] as $optionUuid => $optionDelete) { $optionId = $this->_getOptionIdByUuid($optionUuid, $attributeOptionsByValue, $newOptions); $newDeletes[$optionId] = $optionDelete; } $parameters['option']['delete'] = $newDeletes; } // Decode Default Option if (isset($attributeOptionsByValue)) { $optionUuid = $parameters['default'][0]; $parameters['default'][0] = $this->_getOptionIdByUuid($optionUuid, $attributeOptionsByValue, $newOptions); } // Decode Frontend Label $newFrontendLabel = array(); foreach ($parameters['frontend_label'] as $storeCode => $label) { $storeId = Mage::getModel('core/store')->load($storeCode)->getId(); $newFrontendLabel[$storeId] = $label; } $parameters['frontend_label'] = $newFrontendLabel; $request = new Mage_Core_Controller_Request_Http(); $request->setPost($parameters); $request->setQuery($parameters); return $request; }
public function testSaveActionProcessDifferentListings() { $productIds = array(1, 2, 3); $channel = new Varien_Object(array('id' => 'test_channel_id', 'channeltype_code' => 'test_ebay')); $this->_mockChannel($channel); $policyMock = $this->mockModel('xcom_ebay/policy'); $policyMock->expects($this->any())->method('load')->will($this->returnValue($policyMock)); $session = $this->mockModel('adminhtml/session'); $session->expects($this->once())->method('addSuccess'); $request = new Mage_Core_Controller_Request_Http(); $request->setParam('channel_id', 111); $storeId = 12; $request->setParam('store', $storeId); $request->setParam('product_ids', $productIds); $request->setPost(array('channel_id' => $channel->getId(), 'policy_id' => 0)); $objectMock = $this->getMock(get_class($this->_object), array('_redirect'), array($request, new Varien_Object())); $objectMock->expects($this->once())->method('_redirect')->with($this->equalTo('*/channel_product/'), $this->equalTo(array('type' => $channel->getChanneltypeCode(), 'store' => $storeId))); $channelProductMock = $this->mockModel('xcom_listing/channel_product', array('isProductsInChannel', 'addData', 'getPublishedListingIds', 'saveProducts')); $channelProductMock->expects($this->once())->method('isProductsInChannel')->with($this->equalTo($channel->getId()), $this->equalTo($productIds))->will($this->returnValue(true)); $channelProductMock->expects($this->once())->method('getPublishedListingIds')->with($this->equalTo($productIds), $this->equalTo($channel->getId()))->will($this->returnValue(array(3 => array('product_ids' => array(1, 2), 'channel_id' => $channel->getId())))); $listingMock = $this->mockModel('xcom_listing/listing', array('load', 'addData', 'save', 'prepareProducts', 'send', 'saveProducts', '_isChanged')); $listingMock->expects($this->any())->method('_isChanged')->will($this->returnValue(true)); $listingMock->expects($this->any())->method('addData')->with($this->equalTo($request->getPost())); $listingMock->expects($this->any())->method('prepareProducts')->with($this->equalTo(array(1, 2))); $listingMock->expects($this->any())->method('send')->with($this->equalTo(array('policy' => $policyMock, 'channel' => $channel))); $listingMock->expects($this->any())->method('saveProducts'); $validatorMock = $this->mockHelper('xcom_listing/validator', array('validateOptionalFields', 'validateProducts', 'isPriceChanged', 'isQtyChanged')); $validatorMock->expects($this->once())->method('validateOptionalFields'); $validatorMock->expects($this->once())->method('validateProducts'); $validatorMock->expects($this->once())->method('isPriceChanged'); $validatorMock->expects($this->once())->method('isQtyChanged'); $validatorMock->setListing($listingMock); $this->assertNull($objectMock->saveAction()); }
public function decode($encodedParameters, $version) { // The !empty() ensures that rows without a version number can be // executed (not without any risk). if (!empty($version) && $this->_getVersion() != $version) { throw new Exception(sprintf("Can't decode the Action encoded with %s Tracker v %s; current Attribute Set Tracker is v %s ", $this->_code, $version, $this->_getVersion())); } $helper = Mage::helper('pugmore_mageploy'); $parameters = $this->_decodeParams($encodedParameters); $attributeSetName = $parameters['mageploy_uuid']; $entityTypeId = $this->_getEntityTypeId(); $entityTypeCode = $this->_getEntityTypeCode(); if ($attributeSetId = $helper->getAttributeSetIdFromName($attributeSetName)) { $parameters['id'] = $attributeSetId; } $skeletonSetName = $parameters['skeleton_set']; if ($skeletonSetId = $helper->getAttributeSetIdFromName($skeletonSetName)) { $parameters['skeleton_set'] = $skeletonSetId; } $data = $parameters['data']; foreach ($data['attributes'] as $i => $attribute) { $attributeUuid = $attribute[0]; $attributeId = $helper->getAttributeIdFromCode($attributeUuid, $entityTypeId); if ($attributeId == 208) { $break = $here; } $attributeGroupUuid = $attribute[1]; // Is new Group? if (!strncmp($attributeGroupUuid, 'ynode', strlen('ynode'))) { $attributeGroupId = $attributeGroupUuid; $eavAttributeId = null; } else { // $attributeSetUuid is not used; we still have to explode the // string in order to mantain compatibility with encoding list($attributeGroupName, $attributeSetUuid) = explode(self::UUID_SEPARATOR, $attributeGroupUuid); $attributeGroupId = $helper->getAttributeGroupId($attributeSetId, $attributeGroupName); $eavAttributeId = $helper->getEavEntityAttributeId($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId); } $data['attributes'][$i][0] = $attributeId; $data['attributes'][$i][1] = $attributeGroupId; if ($eavAttributeId) { $data['attributes'][$i][3] = $eavAttributeId; } else { $data['attributes'][$i][3] = ''; } } foreach ($data['groups'] as $i => $group) { $attributeGroupUuid = $group[0]; if (!strncmp($attributeGroupUuid, 'ynode', strlen('ynode'))) { continue; } list($attributeGroupName, $attributeSetUuid) = explode(self::UUID_SEPARATOR, $attributeGroupUuid, 2); $attributeSetName = $attributeSetUuid; $attributeSetId = $helper->getAttributeSetId($attributeSetName, $entityTypeCode); $attributeGroupId = $helper->getAttributeGroupId($attributeSetId, $attributeGroupName); $data['groups'][$i][0] = $attributeGroupId; } foreach ($data['not_attributes'] as $i => $eavAttributeUuid) { if (empty($eavAttributeUuid)) { continue; } list($attributeGroupName, $attributeSetName, $attributeCode) = explode(self::UUID_SEPARATOR, $eavAttributeUuid); $attributeSetId = $helper->getAttributeSetId($attributeSetName, $entityTypeCode); $attributeGroupId = $helper->getAttributeGroupId($attributeSetId, $attributeGroupName); $attributeId = $helper->getAttributeIdFromCode($attributeCode, $entityTypeId); $entityAttributeId = $helper->getEavEntityAttributeId($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId); $data['not_attributes'][$i] = $entityAttributeId; } foreach ($data['removeGroups'] as $i => $attributeGroupUuid) { if (empty($attributeGroupUuid)) { continue; } list($attributeGroupName, $attributeSetName) = explode(self::UUID_SEPARATOR, $attributeGroupUuid); $attributeSetId = $helper->getAttributeSetId($attributeSetName, $entityTypeCode); $attributeGroupId = $helper->getAttributeGroupId($attributeSetId, $attributeGroupName); $data['removeGroups'][$i] = $attributeGroupId; } // json encode data array $parameters['data'] = Zend_Json::encode($data); $request = new Mage_Core_Controller_Request_Http(); $request->setPost($parameters); $request->setQuery($parameters); return $request; }
public function decode($encodedParameters, $version) { // The !empty() ensures that rows without a version number can be // executed (not without any risk). if (!empty($version) && $this->_getVersion() != $version) { throw new Exception(sprintf("Can't decode the Action encoded with %s Tracker v %s; current Website Tracker is v %s ", $this->_code, $version, $this->_getVersion())); } $helper = Mage::helper('pugmore_mageploy'); $params = $this->_decodeParams($encodedParameters); switch ($params['store_action']) { // // Handle saving of existing Website // case 'edit': $websiteUuid = $params['group']['website_id']; $website = Mage::getModel('core/website')->load($websiteUuid, 'code'); if (!$website->getId()) { throw new Exception('Website \'' . $websiteUuid . '\' not found!'); } // Convert Default Store UUID $defaultStoreUuid = $params['group']['default_store_id']; $defaultStore = Mage::getModel('core/store')->load($defaultStoreUuid, 'code'); if (!$defaultStore->getId()) { throw new Exception('Store \'' . $defaultStoreUuid . '\' not found!'); } $params['group']['default_store_id'] = $defaultStore->getId(); // Convert Group UUID $groupUuid = $params['group']['group_id']; $group = Mage::getModel('core/store_group')->getCollection()->addWebsiteFilter($website->getId())->addFieldToFilter('name', $groupUuid)->getFirstItem(); if (!$group->getId()) { throw new Exception('Group \'' . $groupUuid . '\' not found!'); } $params['group']['group_id'] = $group->getId(); // break intentionally omitted // // Handle adding new Website // // break intentionally omitted // // Handle adding new Website // case 'add': $websiteUuid = $params['group']['website_id']; if (!isset($website)) { $website = Mage::getModel('core/website')->load($websiteUuid, 'code'); } if (!$website->getId()) { throw new Exception('Website \'' . $websiteUuid . '\' not found!'); } // Convert Website UUID $params['group']['website_id'] = $website->getId(); // Convert Root Category UUID $rootCategoryUuid = $params['group']['root_category_id']; $rootCategoryPath = $helper->getCategoryPathFromUuid($rootCategoryUuid, self::UUID_SEPARATOR); $rootCategoryId = $helper->getCategoryIdFromPath($rootCategoryPath); $params['group']['root_category_id'] = $rootCategoryId; break; // // Handle deleting existing Website // store_action parameter is undefined in case of delete // // // Handle deleting existing Website // store_action parameter is undefined in case of delete // default: //Convert Item UUID $itemUuid = $params['item_id']; list($websiteCode, $groupName) = explode(self::UUID_SEPARATOR, $itemUuid, 2); $website = Mage::getModel('core/website')->load($websiteCode, 'code'); if (!$website->getId()) { throw new Exception('Website \'' . $websiteCode . '\' not found!'); } $group = Mage::getModel('core/store_group')->getCollection()->addWebsiteFilter($website->getId())->addFieldToFilter('name', $groupName)->getFirstItem(); break; } $request = new Mage_Core_Controller_Request_Http(); $request->setPost($params); $_SERVER['REQUEST_METHOD'] = 'POST'; // needed by StoreController $request->setQuery($params); return $request; }
public function decode($encodedParameters, $version) { // The !empty() ensures that rows without a version number can be // executed (not without any risk). if (!empty($version) && $this->_getVersion() != $version) { throw new Exception(sprintf("Can't decode the Action encoded with %s Tracker v %s; current CMS Page Tracker is v %s ", $this->_code, $version, $this->_getVersion())); } $parameters = $this->_decodeParams($encodedParameters); // convert store IDs foreach ($parameters['stores'] as $i => $storeUuid) { $storeId = Mage::app()->getStore($storeUuid)->getId(); $parameters['stores'][$i] = $storeId; } // convert UUID, if page already exists if (isset($parameters['page_id'])) { list($identifier, $joinedStoreCodes) = explode(self::UUID_SEPARATOR, $parameters['page_id'], 2); $storeCodes = explode(self::UUID_SEPARATOR, $joinedStoreCodes); $storeId = Mage::app()->getStore($storeCodes[0])->getId(); $page = Mage::getModel('cms/page')->getCollection()->addStoreFilter($storeId, false)->addFieldToFilter('identifier', $identifier)->getFirstItem(); /** * On pages created out of the box by Magento, the addStoreFilter * doesn't seem to return the requested object. */ if (!$page->getId()) { $page = Mage::getModel('cms/page')->getCollection()->addFieldToFilter('identifier', $identifier)->getFirstItem(); } $parameters['page_id'] = $page->getId(); } $request = new Mage_Core_Controller_Request_Http(); $request->setPost($parameters); $request->setQuery($parameters); return $request; }
public function decode($encodedParameters, $version) { // The !empty() ensures that rows without a version number can be // executed (not without any risk). if (!empty($version) && $this->_getVersion() != $version) { throw new Exception(sprintf("Can't decode the Action encoded with %s Tracker v %s; current Category Tracker is v %s ", $this->_code, $version, $this->_getVersion())); } $parameters = $this->_decodeParams($encodedParameters); // Id if (isset($parameters['id'])) { $categoryUuid = $parameters['id']; $path = $this->_getCategoryPathFromUuid($categoryUuid); $categoryId = $this->_getCategoryIdFromPath($path); $parameters['id'] = $categoryId; } // Store $storeCode = $parameters['store']; if ($storeCode) { $storeId = Mage::app()->getStore($storeCode)->getId(); $parameters['store'] = $storeId; } // Parent $parentUuid = $parameters['parent']; if ($parentUuid) { $parentPath = $this->_getCategoryPathFromUuid($parentUuid); $parentId = $this->_getCategoryIdFromPath($parentPath); $parameters['parent'] = $parentId; } // Associated Products $associatedProductUuids = explode('&', $parameters['category_products']); $associatedProductIds = array(); foreach ($associatedProductUuids as $i => $association) { list($sku, $position) = explode('=', $association); $id = Mage::getModel('catalog/product')->getIdBySku($sku); $associatedProductIds[] = sprintf("%s=%d", $id, $position); } $parameters['category_products'] = implode('&', $associatedProductIds); // General if (isset($parameters['general']['id'])) { $parameters['general']['id'] = $parameters['id']; } if (isset($parameters['general']['path'])) { if (isset($parameters['id'])) { $category = Mage::getModel('catalog/category')->load($parameters['id']); $parameters['general']['path'] = $category->getPath(); } else { $parentUuid = $parameters['general']['path']; $parentPath = $this->_getCategoryPathFromUuid($parentUuid); $parameters['general']['path'] = $this->_getCategoryIdFromPath($parentPath); } } // pid, paid, aid (move action) $moveIds = array('pid', 'aid', 'paid'); foreach ($moveIds as $key) { if (isset($parameters[$key])) { $moveNodeUuid = $parameters[$key]; $moveNodeCategoryPath = $this->_getCategoryPathFromUuid($moveNodeUuid); $parameters[$key] = $this->_getCategoryIdFromPath($moveNodeCategoryPath); } } $request = new Mage_Core_Controller_Request_Http(); $request->setPost($parameters); #$request->setQuery($parameters); return $request; }