/** * When an order fails to be submitted - e.g. transaction fails, quote * should be kept active, */ public function testSubmitOrderFailure() { // Stub out dependencies to get through the basic flow of submitOrder. $this->_stubForBasicOrderSubmitCompletion(); // Create the exception expected to be thrown while saving the // order submit transaction. $failureMessage = 'Failure exception from unit test.'; $failureException = new Exception($failureMessage); // Side-effect tests: // Ensure the transaction is saved. In the failure case, saving the // transaction should throw an exception to prevent the order from being // created. $this->_transaction->expects($this->once())->method('save')->will($this->throwException($failureException)); // Ensure proper events are dispatched while failing to submit an order. // Defer to the checkout dispatcher for ensuring the proper Magento // events happen, but still need to ensure the correct ones would be // triggered when failing to create an order. $this->_checkoutDispatcher->expects($this->once())->method('dispatchBeforeOrderSubmit')->with($this->identicalTo($this->_quote), $this->identicalTo($this->_order))->will($this->returnSelf()); $this->_checkoutDispatcher->expects($this->once())->method('dispatchOrderSubmitFailure')->with($this->identicalTo($this->_quote), $this->identicalTo($this->_order))->will($this->returnSelf()); $this->_checkoutDispatcher->expects($this->never())->method('dispatchAfterOrderSubmit'); $this->_checkoutDispatcher->expects($this->never())->method('dispatchOrderSubmitSuccess'); // Ensure that failed order cleanup is triggered. More thorough testing // of this cleanup handled in a more specific test. This should just // make sure that at least some of it has been triggered. $this->_order->expects($this->once())->method('setId')->with($this->isNull())->will($this->returnSelf()); $this->setExpectedException(get_class($failureException), $failureMessage); $this->_serviceQuote->submitOrder(); }
public function testSaveDelete() { $first = Mage::getModel('Mage_Core_Model_Store_Group'); $first->setData(array('website_id' => 1, 'name' => 'test 1', 'root_category_id' => 1, 'default_store_id' => 1)); $second = Mage::getModel('Mage_Core_Model_Store_Group'); $second->setData(array('website_id' => 1, 'name' => 'test 2', 'root_category_id' => 1, 'default_store_id' => 1)); $first->save(); $this->_model->addObject($first)->addObject($second, 'second'); $this->_model->save(); $this->assertNotEmpty($first->getId()); $this->assertNotEmpty($second->getId()); Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID); $this->_model->delete(); $test = Mage::getModel('Mage_Core_Model_Store_Group'); $test->load($first->getId()); $this->assertEmpty($test->getId()); }
/** * Process group data * * @param string $groupId * @param array $groupData * @param array $groups * @param string $sectionPath * @param array $extraOldGroups * @param array $oldConfig * @param Mage_Core_Model_Resource_Transaction $saveTransaction * @param Mage_Core_Model_Resource_Transaction $deleteTransaction */ protected function _processGroup($groupId, array $groupData, array $groups, $sectionPath, array &$extraOldGroups, array &$oldConfig, Mage_Core_Model_Resource_Transaction $saveTransaction, Mage_Core_Model_Resource_Transaction $deleteTransaction) { $groupPath = $sectionPath . '/' . $groupId; $website = $this->getWebsite(); $store = $this->getStore(); $scope = $this->getScope(); $scopeId = $this->getScopeId(); /** * * Map field names if they were cloned */ /** @var $group Mage_Backend_Model_Config_Structure_Element_Group */ $group = $this->_configStructure->getElement($groupPath); // set value for group field entry by fieldname // use extra memory $fieldsetData = array(); if (isset($groupData['fields'])) { if ($group->shouldCloneFields()) { $cloneModel = $group->getCloneModel(); $mappedFields = array(); /** @var $field Mage_Backend_Model_Config_Structure_Element_Field */ foreach ($group->getChildren() as $field) { foreach ($cloneModel->getPrefixes() as $prefix) { $mappedFields[$prefix['field'] . $field->getId()] = $field->getId(); } } } foreach ($groupData['fields'] as $fieldId => $fieldData) { $fieldsetData[$fieldId] = is_array($fieldData) && isset($fieldData['value']) ? $fieldData['value'] : null; } foreach ($groupData['fields'] as $fieldId => $fieldData) { $originalFieldId = $fieldId; if ($group->shouldCloneFields() && isset($mappedFields[$fieldId])) { $originalFieldId = $mappedFields[$fieldId]; } /** @var $field Mage_Backend_Model_Config_Structure_Element_Field */ $field = $this->_configStructure->getElement($groupPath . '/' . $originalFieldId); /** @var Mage_Core_Model_Config_Data $backendModel */ $backendModel = $field->hasBackendModel() ? $field->getBackendModel() : $this->_configDataFactory->create(); $data = array('field' => $fieldId, 'groups' => $groups, 'group_id' => $group->getId(), 'store_code' => $store, 'website_code' => $website, 'scope' => $scope, 'scope_id' => $scopeId, 'field_config' => $field->getData(), 'fieldset_data' => $fieldsetData); $backendModel->addData($data); $this->_checkSingleStoreMode($field, $backendModel); if (false == isset($fieldData['value'])) { $fieldData['value'] = null; } $path = $field->getGroupPath() . '/' . $fieldId; /** * Look for custom defined field path */ if ($field && $field->getConfigPath()) { $configPath = $field->getConfigPath(); if (!empty($configPath) && strrpos($configPath, '/') > 0) { // Extend old data with specified section group $configGroupPath = substr($configPath, 0, strrpos($configPath, '/')); if (!isset($extraOldGroups[$configGroupPath])) { $oldConfig = $this->extendConfig($configGroupPath, true, $oldConfig); $extraOldGroups[$configGroupPath] = true; } $path = $configPath; } } $inherit = !empty($fieldData['inherit']); $backendModel->setPath($path)->setValue($fieldData['value']); if (isset($oldConfig[$path])) { $backendModel->setConfigId($oldConfig[$path]['config_id']); /** * Delete config data if inherit */ if (!$inherit) { $saveTransaction->addObject($backendModel); } else { $deleteTransaction->addObject($backendModel); } } elseif (!$inherit) { $backendModel->unsConfigId(); $saveTransaction->addObject($backendModel); } } } if (isset($groupData['groups'])) { foreach ($groupData['groups'] as $subGroupId => $subGroupData) { $this->_processGroup($subGroupId, $subGroupData, $groups, $groupPath, $extraOldGroups, $oldConfig, $saveTransaction, $deleteTransaction); } } }