diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 10079683604ce..23939da93d8fd 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -1,3 +1,32 @@ +Update as of 9/13/2012 +====================== +* Implemented the option to enable the single store mode in the system configuration, which simplifies the back-end GUI: + * Hiding scope labels from the system configuration + * Hiding the scope switcher from the CMS management pages and the system configuration + * Hiding scope related fields from the system configuration + * Hiding scope related columns and fields from the sales pages (order, invoice, shipment pages) + * Hiding scope related fields from the promotions + * Hiding scope related fields from the catalog pages + * Hiding scope related columns and fields from the customers management page + * Hiding scope related columns and fields from the customer and customer address attributes management pages +* Implemented the history management for the Visual Design Editor +* Implemented the user interface for themes management, which allows to list existing themes and add new ones +* Replaced all usages of the old JavaScript translations mechanism with the new jQuery one +* Refactored methods with high cyclomatic complexity +* Converted some surrogate integration tests into functional Selenium tests +* Converted some surrogate integration tests into unit tests +* Fixes: + * Fixed inability to install application with a prefix defined for database tables + * Fixed displaying fields with model name in the payment methods settings + * Fixed performance degradation of the back-end menu rendering + * Fixed absence of the success message upon newsletter template creation/deletion/queueing + * Workaround for occasional segmentation fault in integration tests caused by `Mage_Core_Model_Resource_Setup_Migration` +* GitHub requests: + * [#51](https://github.com/magento/magento2/issues/51) -- fixed managing of scope-spefic values for Categories + * [#56](https://github.com/magento/magento2/pull/56) -- removed excessive semicolon in the CSS file + * [#60](https://github.com/magento/magento2/issues/60) -- fixed taking bind parameters into account in `Mage_Core_Model_Resource_Db_Collection_Abstract::getAllIds()` + * [#61](https://github.com/magento/magento2/pull/61) -- relocated declaration of the "Google Checkout" payment method into `Mage_GoogleCheckout` module from `Mage_Sales` + Update as of 9/05/2012 ====================== * Implemented encryption of the credit card name and expiration date for the payment method "Credit Card (saved)" diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price/Group/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price/Group/Abstract.php index 520c7140fdaa4..7d482e5736afa 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price/Group/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price/Group/Abstract.php @@ -190,7 +190,7 @@ public function getWebsiteCount() */ public function isMultiWebsites() { - return !Mage::app()->isSingleStoreMode(); + return !Mage::app()->hasSingleStore(); } /** diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Edit/Form.php index 144944b1bcaf4..d284df373a402 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Edit/Form.php @@ -86,7 +86,7 @@ protected function _prepareForm() 'required' => true, )); - if (!Mage::app()->isSingleStoreMode()) { + if (!Mage::app()->hasSingleStore()) { $field = $fieldset->addField('store_id', 'select', array( 'name' => 'store_id', 'label' => Mage::helper('Mage_Catalog_Helper_Data')->__('Store'), diff --git a/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement/Edit/Form.php index 04e804cad71ec..658432f17b7a4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement/Edit/Form.php @@ -98,7 +98,7 @@ protected function _prepareForm() ), )); - if (!Mage::app()->isSingleStoreMode()) { + if (!Mage::app()->hasSingleStore()) { $field = $fieldset->addField('store_id', 'multiselect', array( 'name' => 'stores[]', 'label' => Mage::helper('Mage_Checkout_Helper_Data')->__('Store View'), diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php index fa9066433738b..6024338e9f97c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php @@ -33,6 +33,12 @@ */ class Mage_Adminhtml_Block_Customer_Edit_Tab_Account extends Mage_Adminhtml_Block_Widget_Form { + + /* + * Disable Auto Group Change Attribute Name + */ + const DISABLE_ATTRIBUTE_NAME = 'disable_auto_group_change'; + /** * Initialize block */ @@ -52,79 +58,24 @@ public function initForm() $form->setHtmlIdPrefix('_account'); $form->setFieldNameSuffix('account'); - $customer = Mage::registry('current_customer'); - - /** @var $customerForm Mage_Customer_Model_Form */ - $customerForm = Mage::getModel('Mage_Customer_Model_Form'); - $customerForm->setEntity($customer) - ->setFormCode('adminhtml_customer') - ->initDefaultValues(); - $fieldset = $form->addFieldset('base_fieldset', array( 'legend' => Mage::helper('Mage_Customer_Helper_Data')->__('Account Information') )); - $attributes = $customerForm->getAttributes(); - foreach ($attributes as $attribute) { - /* @var $attribute Mage_Eav_Model_Entity_Attribute */ - $attribute->setFrontendLabel(Mage::helper('Mage_Customer_Helper_Data')->__($attribute->getFrontend()->getLabel())); - $attribute->unsIsVisible(); - } - - $disableAutoGroupChangeAttributeName = 'disable_auto_group_change'; - $this->_setFieldset($attributes, $fieldset, array($disableAutoGroupChangeAttributeName)); + $customer = Mage::registry('current_customer'); + /** @var $customerForm Mage_Customer_Model_Form */ + $customerForm = $this->_initCustomerForm($customer); + $attributes = $this->_initCustomerAttributes($customerForm); + $this->_setFieldset($attributes, $fieldset, array(self::DISABLE_ATTRIBUTE_NAME)); $form->getElement('group_id')->setRenderer($this->getLayout() ->createBlock('Mage_Adminhtml_Block_Customer_Edit_Renderer_Attribute_Group') - ->setDisableAutoGroupChangeAttribute($customerForm->getAttribute($disableAutoGroupChangeAttributeName)) - ->setDisableAutoGroupChangeAttributeValue($customer->getData($disableAutoGroupChangeAttributeName))); - - if ($customer->getId()) { - $form->getElement('website_id')->setDisabled('disabled'); - $form->getElement('created_in')->setDisabled('disabled'); - } else { - $fieldset->removeField('created_in'); - $form->getElement('website_id')->addClass('validate-website-has-store'); - - $websites = array(); - foreach (Mage::app()->getWebsites(true) as $website) { - $websites[$website->getId()] = !is_null($website->getDefaultStore()); - } - $prefix = $form->getHtmlIdPrefix(); - - $form->getElement('website_id')->setAfterElementHtml( - '' - ); - } - $renderer = $this->getLayout()->createBlock('Mage_Adminhtml_Block_Store_Switcher_Form_Renderer_Fieldset_Element'); - $form->getElement('website_id')->setRenderer($renderer); - -// if (Mage::app()->isSingleStoreMode()) { -// $fieldset->removeField('website_id'); -// $fieldset->addField('website_id', 'hidden', array( -// 'name' => 'website_id' -// )); -// $customer->setWebsiteId(Mage::app()->getStore(true)->getWebsiteId()); -// } + ->setDisableAutoGroupChangeAttribute($customerForm->getAttribute(self::DISABLE_ATTRIBUTE_NAME)) + ->setDisableAutoGroupChangeAttributeValue($customer->getData(self::DISABLE_ATTRIBUTE_NAME)) + ); - $customerStoreId = null; - if ($customer->getId()) { - $customerStoreId = Mage::app()->getWebsite($customer->getWebsiteId())->getDefaultStore()->getId(); - } + $this->_setCustomerWebsiteId($customer); + $customerStoreId = $this->_getCustomerStoreId($customer); $prefixElement = $form->getElement('prefix'); if ($prefixElement) { @@ -140,7 +91,6 @@ function(v, elem){ if ($customer->getId()) { $prefixField->addElementValues($customer->getPrefix()); } - } } @@ -162,80 +112,95 @@ function(v, elem){ } if ($customer->getId()) { - if (!$customer->isReadonly()) { - // Add password management fieldset - $newFieldset = $form->addFieldset( - 'password_fieldset', - array('legend' => Mage::helper('Mage_Customer_Helper_Data')->__('Password Management')) - ); - // New customer password - $field = $newFieldset->addField('new_password', 'text', - array( - 'label' => Mage::helper('Mage_Customer_Helper_Data')->__('New Password'), - 'name' => 'new_password', - 'class' => 'validate-new-password' - ) - ); - $field->setRenderer( - $this->getLayout()->createBlock('Mage_Adminhtml_Block_Customer_Edit_Renderer_Newpass') - ); - - // Prepare customer confirmation control (only for existing customers) - $confirmationKey = $customer->getConfirmation(); - if ($confirmationKey || $customer->isConfirmationRequired()) { - $confirmationAttribute = $customer->getAttribute('confirmation'); - if (!$confirmationKey) { - $confirmationKey = $customer->getRandomConfirmationKey(); - } - $element = $fieldset->addField('confirmation', 'select', array( - 'name' => 'confirmation', - 'label' => Mage::helper('Mage_Customer_Helper_Data')->__($confirmationAttribute->getFrontendLabel()), - ))->setEntityAttribute($confirmationAttribute) - ->setValues(array('' => 'Confirmed', $confirmationKey => 'Not confirmed')); - - // Prepare send welcome email checkbox if customer is not confirmed - // no need to add it, if website ID is empty - if ($customer->getConfirmation() && $customer->getWebsiteId()) { - $fieldset->addField('sendemail', 'checkbox', array( - 'name' => 'sendemail', - 'label' => Mage::helper('Mage_Customer_Helper_Data')->__('Send Welcome Email after Confirmation') - )); - $customer->setData('sendemail', '1'); - } - } - } + $this->_addEditCustomerFormFields($form, $fieldset, $customer); } else { - $newFieldset = $form->addFieldset( - 'password_fieldset', - array('legend'=>Mage::helper('Mage_Customer_Helper_Data')->__('Password Management')) - ); - $field = $newFieldset->addField('password', 'text', - array( - 'label' => Mage::helper('Mage_Customer_Helper_Data')->__('Password'), - 'class' => 'input-text required-entry validate-password', - 'name' => 'password', - 'required' => true - ) - ); - $field->setRenderer($this->getLayout()->createBlock('Mage_Adminhtml_Block_Customer_Edit_Renderer_Newpass')); - - // Prepare send welcome email checkbox - $fieldset->addField('sendemail', 'checkbox', array( - 'label' => Mage::helper('Mage_Customer_Helper_Data')->__('Send Welcome Email'), - 'name' => 'sendemail', - 'id' => 'sendemail', - )); + $this->_addNewCustomerFormFields($form, $fieldset); $customer->setData('sendemail', '1'); - if (!Mage::app()->isSingleStoreMode()) { - $fieldset->addField('sendemail_store_id', 'select', array( - 'label' => $this->helper('Mage_Customer_Helper_Data')->__('Send From'), - 'name' => 'sendemail_store_id', - 'values' => Mage::getSingleton('Mage_Core_Model_System_Store')->getStoreValuesForForm() - )); + } + + $this->_disableSendEmailStoreForEmptyWebsite($form); + $this->_handleReadOnlyCustomer($form, $customer); + + $form->setValues($customer->getData()); + $this->setForm($form); + return $this; + } + + /** + * Return predefined additional element types + * + * @return array + */ + protected function _getAdditionalElementTypes() + { + return array( + 'file' => Mage::getConfig()->getBlockClassName('Mage_Adminhtml_Block_Customer_Form_Element_File'), + 'image' => Mage::getConfig()->getBlockClassName('Mage_Adminhtml_Block_Customer_Form_Element_Image'), + 'boolean' => Mage::getConfig()->getBlockClassName('Mage_Adminhtml_Block_Customer_Form_Element_Boolean'), + ); + } + + /** + * Initialize attribute set + * + * @param Mage_Customer_Model_Form $customerFor + * @return Mage_Eav_Model_Entity_Attribute[] + */ + protected function _initCustomerAttributes(Mage_Customer_Model_Form $customerForm) + { + $attributes = $customerForm->getAttributes(); + foreach ($attributes as $attribute) { + /* @var $attribute Mage_Eav_Model_Entity_Attribute */ + $attributeLabel = Mage::helper('Mage_Customer_Helper_Data')->__($attribute->getFrontend()->getLabel()); + $attribute->setFrontendLabel($attributeLabel); + $attribute->unsIsVisible(); + } + return $attributes; + } + + /** + * Initialize customer form + * + * @param Mage_Customer_Model_Customer $customer + * @return Mage_Customer_Model_Form $customerForm + */ + protected function _initCustomerForm(Mage_Customer_Model_Customer $customer) + { + /** @var $customerForm Mage_Customer_Model_Form */ + $customerForm = Mage::getModel('Mage_Customer_Model_Form'); + $customerForm->setEntity($customer) + ->setFormCode('adminhtml_customer') + ->initDefaultValues(); + + return $customerForm; + } + + /** + * Handle Read-Only customer + * + * @param Varien_Data_Form $form + * @param Mage_Customer_Model_Customer $customer + */ + protected function _handleReadOnlyCustomer($form, $customer) + { + if (!$customer->isReadonly()) { + return; + } + foreach ($customer->getAttributes() as $attribute) { + $element = $form->getElement($attribute->getAttributeCode()); + if ($element) { + $element->setReadonly(true, true); } } + } - // Make sendemail and sendmail_store_id disabled if website_id has empty value + /** + * Make sendemail or sendmail_store_id disabled if website_id has an empty value + * + * @param Varien_Data_Form $form + */ + protected function _disableSendEmailStoreForEmptyWebsite(Varien_Data_Form $form) + { $isSingleMode = Mage::app()->isSingleStoreMode(); $sendEmailId = $isSingleMode ? 'sendemail' : 'sendemail_store_id'; $sendEmail = $form->getElement($sendEmailId); @@ -259,32 +224,186 @@ function(v, elem){ . '' ); } + } - if ($customer->isReadonly()) { - foreach ($customer->getAttributes() as $attribute) { - $element = $form->getElement($attribute->getAttributeCode()); - if ($element) { - $element->setReadonly(true, true); - } + /** + * Create New Customer form fields + * + * @param Varien_Data_Form $form + * @param Varien_Data_Form_Element_Fieldset $fieldset + */ + protected function _addNewCustomerFormFields($form, $fieldset) + { + $fieldset->removeField('created_in'); + + $this->_addPasswordManagementFieldset($form, 'Password', false); + + // Prepare send welcome email checkbox + $fieldset->addField('sendemail', 'checkbox', array( + 'label' => Mage::helper('Mage_Customer_Helper_Data')->__('Send Welcome Email'), + 'name' => 'sendemail', + 'id' => 'sendemail', + )); + if (!Mage::app()->isSingleStoreMode()) { + $form->getElement('website_id')->addClass('validate-website-has-store'); + + $websites = array(); + foreach (Mage::app()->getWebsites(true) as $website) { + $websites[$website->getId()] = !is_null($website->getDefaultStore()); } + $prefix = $form->getHtmlIdPrefix(); + + $note = Mage::helper('Mage_Customer_Helper_Data')->__('Please select a website which contains store view'); + $form->getElement('website_id')->setAfterElementHtml( + '' + ); + $renderer = $this->getLayout() + ->createBlock('Mage_Adminhtml_Block_Store_Switcher_Form_Renderer_Fieldset_Element'); + $form->getElement('website_id')->setRenderer($renderer); + + $fieldset->addField('sendemail_store_id', 'select', array( + 'label' => $this->helper('Mage_Customer_Helper_Data')->__('Send From'), + 'name' => 'sendemail_store_id', + 'values' => Mage::getSingleton('Mage_Core_Model_System_Store')->getStoreValuesForForm() + )); + } else { + $fieldset->removeField('website_id'); + $fieldset->addField('website_id', 'hidden', array( + 'name' => 'website_id' + )); } + } - $form->setValues($customer->getData()); - $this->setForm($form); - return $this; + /** + * Edit/View Existing Customer form fields + * + * @param Varien_Data_Form $form + * @param Varien_Data_Form_Element_Fieldset $fieldset + * @param Mage_Customer_Model_Customer $customer + */ + protected function _addEditCustomerFormFields($form, $fieldset, $customer) + { + $form->getElement('created_in')->setDisabled('disabled'); + if (!Mage::app()->isSingleStoreMode()) { + $form->getElement('website_id')->setDisabled('disabled'); + $renderer = $this->getLayout() + ->createBlock('Mage_Adminhtml_Block_Store_Switcher_Form_Renderer_Fieldset_Element'); + $form->getElement('website_id')->setRenderer($renderer); + } else { + $fieldset->removeField('website_id'); + } + + if ($customer->isReadonly()) { + return; + } + $this->_addPasswordManagementFieldset($form, 'New Password', true); + + // Prepare customer confirmation control (only for existing customers) + $confirmationKey = $customer->getConfirmation(); + if ($confirmationKey || $customer->isConfirmationRequired()) { + $confirmationAttr = $customer->getAttribute('confirmation'); + if (!$confirmationKey) { + $confirmationKey = $customer->getRandomConfirmationKey(); + } + + $element = $fieldset->addField('confirmation', 'select', array( + 'name' => 'confirmation', + 'label' => Mage::helper('Mage_Customer_Helper_Data')->__($confirmationAttr->getFrontendLabel()), + )); + $element->setEntityAttribute($confirmationAttr); + $element->setValues(array( + '' => 'Confirmed', + $confirmationKey => 'Not confirmed' + )); + + // Prepare send welcome email checkbox if customer is not confirmed + // no need to add it, if website ID is empty + if ($customer->getConfirmation() && $customer->getWebsiteId()) { + $fieldset->addField('sendemail', 'checkbox', array( + 'name' => 'sendemail', + 'label' => Mage::helper('Mage_Customer_Helper_Data')->__('Send Welcome Email after Confirmation') + )); + $customer->setData('sendemail', '1'); + } + } } /** - * Return predefined additional element types + * Add Password management fieldset * - * @return array + * @param Varien_Data_Form $form + * @param string $fieldLabel + * @param boolean $isNew whether we set initial password or change existing one */ - protected function _getAdditionalElementTypes() + protected function _addPasswordManagementFieldset($form, $fieldLabel, $isNew) { - return array( - 'file' => Mage::getConfig()->getBlockClassName('Mage_Adminhtml_Block_Customer_Form_Element_File'), - 'image' => Mage::getConfig()->getBlockClassName('Mage_Adminhtml_Block_Customer_Form_Element_Image'), - 'boolean' => Mage::getConfig()->getBlockClassName('Mage_Adminhtml_Block_Customer_Form_Element_Boolean'), + // Add password management fieldset + $newFieldset = $form->addFieldset( + 'password_fieldset', + array('legend' => Mage::helper('Mage_Customer_Helper_Data')->__('Password Management')) ); + if ($isNew) { + // New customer password for existing customer + $elementId = 'new_password'; + $elementClass = 'validate-new-password'; + } else { + // Password field for newly generated customer + $elementId = 'password'; + $elementClass = 'input-text required-entry validate-password'; + } + $field = $newFieldset->addField($elementId, 'text', + array( + 'label' => Mage::helper('Mage_Customer_Helper_Data')->__($fieldLabel), + 'name' => $elementId, + 'class' => $elementClass, + 'required' => !$isNew, + ) + ); + $field->setRenderer( + $this->getLayout()->createBlock('Mage_Adminhtml_Block_Customer_Edit_Renderer_Newpass') + ); + } + + /** + * Get Customer Store Id + * + * @param Mage_Customer_Model_Customer $customer + * @return int|null + */ + protected function _getCustomerStoreId(Mage_Customer_Model_Customer $customer) + { + $customerStoreId = null; + if ($customer->getId()) { + $customerStoreId = Mage::app()->getWebsite($customer->getWebsiteId()) + ->getDefaultStore() + ->getId(); + } + return $customerStoreId; + } + + /** + * Set Customer Website Id in Single Store Mode + * + * @param Mage_Customer_Model_Customer $customer + */ + protected function _setCustomerWebsiteId(Mage_Customer_Model_Customer $customer) + { + if (Mage::app()->hasSingleStore()) { + $customer->setWebsiteId(Mage::app()->getStore(true)->getWebsiteId()); + } } } diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit/Form.php index 62cb9a7560a4b..87caf5f07d400 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit/Form.php @@ -65,7 +65,7 @@ protected function _prepareForm() 'image' => $this->getSkinUrl('images/grid-cal.gif') )); - if (!Mage::app()->isSingleStoreMode()) { + if (!Mage::app()->hasSingleStore()) { $fieldset->addField('stores','multiselect',array( 'name' => 'stores[]', 'label' => Mage::helper('Mage_Newsletter_Helper_Data')->__('Subscribers From'), @@ -91,7 +91,7 @@ protected function _prepareForm() 'image' => $this->getSkinUrl('images/grid-cal.gif') )); - if (!Mage::app()->isSingleStoreMode()) { + if (!Mage::app()->hasSingleStore()) { $fieldset->addField('stores','multiselect',array( 'name' => 'stores[]', 'label' => Mage::helper('Mage_Newsletter_Helper_Data')->__('Subscribers From'), diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid.php index 044465586215d..39c73d05bcbd5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid.php @@ -33,14 +33,29 @@ */ class Mage_Adminhtml_Block_Newsletter_Subscriber_Grid extends Mage_Adminhtml_Block_Widget_Grid { + /** + * Application instance + * + * @var Mage_Core_Model_App + */ + protected $_app; + /** * Constructor * * Set main configuration of grid + * + * @param array $attributes + * @throws InvalidArgumentException */ - public function __construct() + public function __construct(array $attributes = array()) { - parent::__construct(); + $this->_app = isset($attributes['app']) ? $attributes['app'] : Mage::app(); + + if (!($this->_app instanceof Mage_Core_Model_App)) { + throw new InvalidArgumentException('Required application object is invalid'); + } + parent::__construct($attributes); $this->setId('subscriberGrid'); $this->setUseAjax(true); $this->setDefaultSort('subscriber_id', 'desc'); @@ -117,26 +132,28 @@ protected function _prepareColumns() ) )); - $this->addColumn('website', array( - 'header' => Mage::helper('Mage_Newsletter_Helper_Data')->__('Website'), - 'index' => 'website_id', - 'type' => 'options', - 'options' => $this->_getWebsiteOptions() - )); - - $this->addColumn('group', array( - 'header' => Mage::helper('Mage_Newsletter_Helper_Data')->__('Store'), - 'index' => 'group_id', - 'type' => 'options', - 'options' => $this->_getStoreGroupOptions() - )); - - $this->addColumn('store', array( - 'header' => Mage::helper('Mage_Newsletter_Helper_Data')->__('Store View'), - 'index' => 'store_id', - 'type' => 'options', - 'options' => $this->_getStoreOptions() - )); + if (!$this->_app->isSingleStoreMode()) { + $this->addColumn('website', array( + 'header' => Mage::helper('Mage_Newsletter_Helper_Data')->__('Website'), + 'index' => 'website_id', + 'type' => 'options', + 'options' => $this->_getWebsiteOptions() + )); + + $this->addColumn('group', array( + 'header' => Mage::helper('Mage_Newsletter_Helper_Data')->__('Store'), + 'index' => 'group_id', + 'type' => 'options', + 'options' => $this->_getStoreGroupOptions() + )); + + $this->addColumn('store', array( + 'header' => Mage::helper('Mage_Newsletter_Helper_Data')->__('Store View'), + 'index' => 'store_id', + 'type' => 'options', + 'options' => $this->_getStoreOptions() + )); + } $this->addExportType('*/*/exportCsv', Mage::helper('Mage_Customer_Helper_Data')->__('CSV')); $this->addExportType('*/*/exportXml', Mage::helper('Mage_Customer_Helper_Data')->__('Excel XML')); diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php index b050057767e74..a6fb89495679b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php @@ -122,7 +122,7 @@ protected function _prepareForm() ), )); - if (Mage::app()->isSingleStoreMode()) { + if (Mage::app()->hasSingleStore()) { $websiteId = Mage::app()->getStore(true)->getWebsiteId(); $fieldset->addField('website_ids', 'hidden', array( 'name' => 'website_ids[]', diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Labels.php b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Labels.php index 361689760f588..6f46171ffbed4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Labels.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Labels.php @@ -28,6 +28,29 @@ class Mage_Adminhtml_Block_Promo_Quote_Edit_Tab_Labels extends Mage_Adminhtml_Block_Widget_Form implements Mage_Adminhtml_Block_Widget_Tab_Interface { + /** + * Application instance + * + * @var Mage_Core_Model_App + */ + protected $_app; + + /** + * Class constructor + * + * @param array $data + * @throws InvalidArgumentException + */ + public function __construct(array $data = array()) + { + $this->_app = isset($data['app']) ? $data['app'] : Mage::app(); + + if (!($this->_app instanceof Mage_Core_Model_App)) { + throw new InvalidArgumentException('Required application object is invalid'); + } + parent::__construct($data); + } + /** * Prepare content for tab * @@ -78,6 +101,7 @@ protected function _prepareForm() 'legend' => Mage::helper('Mage_SalesRule_Helper_Data')->__('Default Label') )); $labels = $rule->getStoreLabels(); + $fieldset->addField('store_default_label', 'text', array( 'name' => 'store_labels[0]', 'required' => false, @@ -85,16 +109,39 @@ protected function _prepareForm() 'value' => isset($labels[0]) ? $labels[0] : '', )); + if (!$this->_app->isSingleStoreMode()) { + $fieldset = $this->_createStoreSpecificFieldset($form, $labels); + } + + if ($rule->isReadonly()) { + foreach ($fieldset->getElements() as $element) { + $element->setReadonly(true, true); + } + } + + $this->setForm($form); + return parent::_prepareForm(); + } + + /** + * Create store specific fieldset + * + * @param Varien_Data_Form $form + * @param array $labels + * @return Varien_Data_Form_Element_Fieldset mixed + */ + protected function _createStoreSpecificFieldset($form, $labels) + { $fieldset = $form->addFieldset('store_labels_fieldset', array( - 'legend' => Mage::helper('Mage_SalesRule_Helper_Data')->__('Store View Specific Labels'), - 'table_class' => 'form-list stores-tree', + 'legend' => Mage::helper('Mage_SalesRule_Helper_Data')->__('Store View Specific Labels'), + 'table_class' => 'form-list stores-tree', )); $renderer = $this->getLayout()->createBlock('Mage_Adminhtml_Block_Store_Switcher_Form_Renderer_Fieldset'); $fieldset->setRenderer($renderer); foreach (Mage::app()->getWebsites() as $website) { $fieldset->addField("w_{$website->getId()}_label", 'note', array( - 'label' => $website->getName(), + 'label' => $website->getName(), 'fieldset_html_class' => 'website', )); foreach ($website->getGroups() as $group) { @@ -103,29 +150,20 @@ protected function _prepareForm() continue; } $fieldset->addField("sg_{$group->getId()}_label", 'note', array( - 'label' => $group->getName(), + 'label' => $group->getName(), 'fieldset_html_class' => 'store-group', )); foreach ($stores as $store) { $fieldset->addField("s_{$store->getId()}", 'text', array( - 'name' => 'store_labels['.$store->getId().']', - 'required' => false, - 'label' => $store->getName(), - 'value' => isset($labels[$store->getId()]) ? $labels[$store->getId()] : '', + 'name' => 'store_labels[' . $store->getId() . ']', + 'required' => false, + 'label' => $store->getName(), + 'value' => isset($labels[$store->getId()]) ? $labels[$store->getId()] : '', 'fieldset_html_class' => 'store', )); } } } - - - if ($rule->isReadonly()) { - foreach ($fieldset->getElements() as $element) { - $element->setReadonly(true, true); - } - } - - $this->setForm($form); - return parent::_prepareForm(); + return $fieldset; } } diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php index 7d934dc383511..eb6ad64f779af 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php @@ -125,7 +125,7 @@ protected function _prepareForm() $model->setData('is_active', '1'); } - if (Mage::app()->isSingleStoreMode()) { + if (Mage::app()->hasSingleStore()) { $websiteId = Mage::app()->getStore(true)->getWebsiteId(); $fieldset->addField('website_ids', 'hidden', array( 'name' => 'website_ids[]', diff --git a/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tab/Form.php b/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tab/Form.php index 2cde99ee2dd48..ec94f36ddbf1b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tab/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tab/Form.php @@ -34,6 +34,29 @@ class Mage_Adminhtml_Block_Rating_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form { + /** + * Application instance + * + * @var Mage_Core_Model_App + */ + protected $_app; + + /** + * Class constructor + * + * @param array $data + * @throws InvalidArgumentException + */ + public function __construct(array $data = array()) + { + $this->_app = isset($data['app']) ? $data['app'] : Mage::app(); + + if (!($this->_app instanceof Mage_Core_Model_App)) { + throw new InvalidArgumentException('Required app object is invalid'); + } + parent::__construct($data); + } + /** * Prepare rating edit form * @@ -105,14 +128,25 @@ protected function _prepareForm() $fieldset = $form->addFieldset('visibility_form', array( 'legend' => Mage::helper('Mage_Rating_Helper_Data')->__('Rating Visibility') )); + if (!$this->_app->isSingleStoreMode()) { + $field = $fieldset->addField('stores', 'multiselect', array( + 'label' => Mage::helper('Mage_Rating_Helper_Data')->__('Visible In'), + 'name' => 'stores[]', + 'values' => Mage::getSingleton('Mage_Core_Model_System_Store')->getStoreValuesForForm(), + )); + $renderer = $this->getLayout()->createBlock('Mage_Adminhtml_Block_Store_Switcher_Form_Renderer_Fieldset_Element'); + $field->setRenderer($renderer); + + if (Mage::registry('rating_data')) { + $form->getElement('stores')->setValue(Mage::registry('rating_data')->getStores()); + } + } - $field = $fieldset->addField('stores', 'multiselect', array( - 'label' => Mage::helper('Mage_Rating_Helper_Data')->__('Visible In'), - 'name' => 'stores[]', - 'values' => Mage::getSingleton('Mage_Core_Model_System_Store')->getStoreValuesForForm(), + $fieldset->addField('is_active', 'checkbox', array( + 'label' => Mage::helper('Mage_Rating_Helper_Data')->__('Is Active'), + 'name' => 'is_active', + 'value' => 1, )); - $renderer = $this->getLayout()->createBlock('Mage_Adminhtml_Block_Store_Switcher_Form_Renderer_Fieldset_Element'); - $field->setRenderer($renderer); $fieldset->addField('position', 'text', array( 'label' => Mage::helper('Mage_Rating_Helper_Data')->__('Sort Order'), @@ -121,7 +155,7 @@ protected function _prepareForm() if (Mage::registry('rating_data')) { $form->getElement('position')->setValue(Mage::registry('rating_data')->getPosition()); - $form->getElement('stores')->setValue(Mage::registry('rating_data')->getStores()); + $form->getElement('is_active')->setIsChecked(Mage::registry('rating_data')->getIsActive()); } return parent::_prepareForm(); diff --git a/app/code/core/Mage/Adminhtml/Block/Rating/Grid.php b/app/code/core/Mage/Adminhtml/Block/Rating/Grid.php index 6ed76c6e97b17..b1e09e4e923e2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Rating/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Rating/Grid.php @@ -78,6 +78,17 @@ protected function _prepareColumns() 'index' => 'position', )); + $this->addColumn('is_active', array( + 'header' => Mage::helper('Mage_Rating_Helper_Data')->__('Is Active'), + 'align' => 'left', + 'type' => 'options', + 'index' => 'is_active', + 'options' => array( + '1' => Mage::helper('Mage_Rating_Helper_Data')->__('Active'), + '0' => Mage::helper('Mage_Rating_Helper_Data')->__('Inactive') + ), + )); + return parent::_prepareColumns(); } diff --git a/app/code/core/Mage/Adminhtml/Block/Review/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Review/Edit/Form.php index 0dcdb9f2b1156..7da5bbcd2b88b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Review/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Review/Edit/Form.php @@ -91,7 +91,7 @@ protected function _prepareForm() /** * Check is single store mode */ - if (!Mage::app()->isSingleStoreMode()) { + if (!Mage::app()->hasSingleStore()) { $field = $fieldset->addField('select_stores', 'multiselect', array( 'label' => Mage::helper('Mage_Review_Helper_Data')->__('Visible In'), 'required' => true, diff --git a/app/code/core/Mage/Adminhtml/Block/Review/Rating/Detailed.php b/app/code/core/Mage/Adminhtml/Block/Review/Rating/Detailed.php index 6f14ada7cc90b..e2f21e47fae98 100644 --- a/app/code/core/Mage/Adminhtml/Block/Review/Rating/Detailed.php +++ b/app/code/core/Mage/Adminhtml/Block/Review/Rating/Detailed.php @@ -56,6 +56,7 @@ public function getRating() ->getResourceCollection() ->addEntityFilter('product') ->setStoreFilter($stores) + ->setActiveFilter(true) ->setPositionOrder() ->load() ->addOptionToItems(); diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/New/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/New/Form.php index 2d4c12470618c..d8cc4e7f95077 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/New/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/New/Form.php @@ -42,50 +42,71 @@ public function __construct() */ protected function _prepareForm() { - $model = Mage::registry('current_status'); - $labels = $model ? $model->getStoreLabels() : array(); + $model = Mage::registry('current_status'); - $form = new Varien_Data_Form(array( - 'id' => 'edit_form', - 'action' => $this->getData('action'), - 'method' => 'post' + $form = new Varien_Data_Form(array( + 'id' => 'edit_form', + 'action' => $this->getData('action'), + 'method' => 'post' )); - $fieldset = $form->addFieldset('base_fieldset', array( - 'legend' => Mage::helper('Mage_Sales_Helper_Data')->__('Order Status Information') + $fieldset = $form->addFieldset('base_fieldset', array( + 'legend' => Mage::helper('Mage_Sales_Helper_Data')->__('Order Status Information') )); $fieldset->addField('is_new', 'hidden', array('name' => 'is_new', 'value' => 1)); $fieldset->addField('status', 'text', array( - 'name' => 'status', - 'label' => Mage::helper('Mage_Sales_Helper_Data')->__('Status Code'), - 'class' => 'required-entry validate-code', - 'required' => true, + 'name' => 'status', + 'label' => Mage::helper('Mage_Sales_Helper_Data')->__('Status Code'), + 'class' => 'required-entry validate-code', + 'required' => true, ) ); $fieldset->addField('label', 'text', array( - 'name' => 'label', - 'label' => Mage::helper('Mage_Sales_Helper_Data')->__('Status Label'), - 'class' => 'required-entry', - 'required' => true, + 'name' => 'label', + 'label' => Mage::helper('Mage_Sales_Helper_Data')->__('Status Label'), + 'class' => 'required-entry', + 'required' => true, ) ); + if (!Mage::app()->isSingleStoreMode()) { + $this->_addStoresFieldset($model, $form); + } + if ($model) { + $form->addValues($model->getData()); + } + $form->setAction($this->getUrl('*/sales_order_status/save')); + $form->setUseContainer(true); + $this->setForm($form); + + return parent::_prepareForm(); + } + + /** + * Add Fieldset with Store labels + * + * @param Mage_Sales_Model_Order_Status $model + * @param Varien_Data_Form $form + */ + protected function _addStoresFieldset($model, $form) + { + $labels = $model ? $model->getStoreLabels() : array(); $fieldset = $form->addFieldset('store_labels_fieldset', array( - 'legend' => Mage::helper('Mage_Sales_Helper_Data')->__('Store View Specific Labels'), - 'table_class' => 'form-list stores-tree', + 'legend' => Mage::helper('Mage_Sales_Helper_Data')->__('Store View Specific Labels'), + 'table_class' => 'form-list stores-tree', )); $renderer = $this->getLayout()->createBlock('Mage_Adminhtml_Block_Store_Switcher_Form_Renderer_Fieldset'); $fieldset->setRenderer($renderer); foreach (Mage::app()->getWebsites() as $website) { $fieldset->addField("w_{$website->getId()}_label", 'note', array( - 'label' => $website->getName(), + 'label' => $website->getName(), 'fieldset_html_class' => 'website', )); foreach ($website->getGroups() as $group) { @@ -94,28 +115,19 @@ protected function _prepareForm() continue; } $fieldset->addField("sg_{$group->getId()}_label", 'note', array( - 'label' => $group->getName(), + 'label' => $group->getName(), 'fieldset_html_class' => 'store-group', )); foreach ($stores as $store) { $fieldset->addField("store_label_{$store->getId()}", 'text', array( - 'name' => 'store_labels['.$store->getId().']', - 'required' => false, - 'label' => $store->getName(), - 'value' => isset($labels[$store->getId()]) ? $labels[$store->getId()] : '', + 'name' => 'store_labels[' . $store->getId() . ']', + 'required' => false, + 'label' => $store->getName(), + 'value' => isset($labels[$store->getId()]) ? $labels[$store->getId()] : '', 'fieldset_html_class' => 'store', )); } } } - - if ($model) { - $form->addValues($model->getData()); - } - $form->setAction($this->getUrl('*/sales_order_status/save')); - $form->setUseContainer(true); - $this->setForm($form); - - return parent::_prepareForm(); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Sitemap/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Sitemap/Edit/Form.php index 2853e7aa22473..2643fb99a167b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sitemap/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sitemap/Edit/Form.php @@ -80,7 +80,7 @@ protected function _prepareForm() 'value' => $model->getSitemapPath() )); - if (!Mage::app()->isSingleStoreMode()) { + if (!Mage::app()->hasSingleStore()) { $field = $fieldset->addField('store_id', 'select', array( 'label' => Mage::helper('Mage_Sitemap_Helper_Data')->__('Store View'), 'title' => Mage::helper('Mage_Sitemap_Helper_Data')->__('Store View'), diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php index e7d3032a4a5d0..01e60ab889ddf 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php @@ -683,18 +683,26 @@ protected function _canShowField($field) return false; } + $fieldIsDisplayable = (bool)$field->show_in_default + || (bool)$field->show_in_website + || (bool)$field->show_in_store; + if (Mage::app()->isSingleStoreMode() && $fieldIsDisplayable) { + return !(int)$field->hide_in_single_store_mode; + } + + $result = true; switch ($this->getScope()) { case self::SCOPE_DEFAULT: - return (int)$field->show_in_default; + $result = (int)$field->show_in_default; break; case self::SCOPE_WEBSITES: - return (int)$field->show_in_website; + $result = (int)$field->show_in_website; break; case self::SCOPE_STORES: - return (int)$field->show_in_store; + $result = (int)$field->show_in_store; break; } - return true; + return $result; } /** diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field.php index 989a7cbac3651..585921cd6bfc2 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field.php @@ -24,13 +24,12 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - /** * Abstract config form element renderer * * @category Mage * @package Mage_Adminhtml - * @author Magento Core Team + * @author Magento Core Team */ class Mage_Adminhtml_Block_System_Config_Form_Field extends Mage_Adminhtml_Block_Abstract @@ -38,7 +37,7 @@ class Mage_Adminhtml_Block_System_Config_Form_Field { /** - * Enter description here... + * Retrieve element HTML markup * * @param Varien_Data_Form_Element_Abstract $element * @return string @@ -49,92 +48,131 @@ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) } /** - * Enter description here... + * Retrieve HTML markup for given form element * * @param Varien_Data_Form_Element_Abstract $element * @return string */ public function render(Varien_Data_Form_Element_Abstract $element) { - $id = $element->getHtmlId(); - - $useContainerId = $element->getData('use_container_id'); - $html = '' - . ''; + $htmlId = $element->getHtmlId(); + $isCheckboxRequired = $this->_isInheritCheckboxRequired($element); - //$isDefault = !$this->getRequest()->getParam('website') && !$this->getRequest()->getParam('store'); - $isMultiple = $element->getExtType()==='multiple'; - - // replace [value] with [inherit] - $namePrefix = preg_replace('#\[value\](\[\])?$#', '', $element->getName()); + // Disable element if value is inherited from other scope. Flag has to be set before the value is rendered. + if ($element->getInherit() == 1 && $isCheckboxRequired) { + $element->setDisabled(true); + } - $options = $element->getValues(); + $html = ''; + $html .= ''; + $html .= $this->_renderValue($element); - $addInheritCheckbox = false; - if ($element->getCanUseWebsiteValue()) { - $addInheritCheckbox = true; - $checkboxLabel = Mage::helper('Mage_Adminhtml_Helper_Data')->__('Use Website'); - } - elseif ($element->getCanUseDefaultValue()) { - $addInheritCheckbox = true; - $checkboxLabel = Mage::helper('Mage_Adminhtml_Helper_Data')->__('Use Default'); + if ($isCheckboxRequired) { + $html .= $this->_renderInheritCheckbox($element); } - if ($addInheritCheckbox) { - $inherit = $element->getInherit()==1 ? 'checked="checked"' : ''; - if ($inherit) { - $element->setDisabled(true); - } - } + $html .= $this->_renderScopeLabel($element); + $html .= $this->_renderHint($element); + + $html .= ''; + return $html; + } - $html.= ''; - $html.= $this->_getElementHtml($element); + /** + * Render element value + * + * @param Varien_Data_Form_Element_Abstract $element + * @return string + */ + protected function _renderValue(Varien_Data_Form_Element_Abstract $element) + { + $html = ''; + $html .= $this->_getElementHtml($element); if ($element->getComment()) { - $html.= '

'.$element->getComment().'

'; + $html .= '

' . $element->getComment() . '

'; } - $html.= ''; - - if ($addInheritCheckbox) { - - $defText = $element->getDefaultValue(); - if ($options) { - $defTextArr = array(); - foreach ($options as $k=>$v) { - if ($isMultiple) { - if (is_array($v['value']) && in_array($k, $v['value'])) { - $defTextArr[] = $v['label']; - } - } elseif ($v['value']==$defText) { - $defTextArr[] = $v['label']; - break; - } - } - $defText = join(', ', $defTextArr); - } - - // default value - $html.= ''; - //$html.= ''; - $html.= ' '; - $html.= ''; - $html.= ''; + $html .= ''; + return $html; + } + + /** + * Render inheritance checkbox (Use Default or Use Website) + * + * @param Varien_Data_Form_Element_Abstract $element + * @return string + */ + protected function _renderInheritCheckbox(Varien_Data_Form_Element_Abstract $element) + { + $htmlId = $element->getHtmlId(); + $namePrefix = preg_replace('#\[value\](\[\])?$#', '', $element->getName()); + $checkedHtml = ($element->getInherit() == 1) ? 'checked="checked"' : ''; + + $html = ''; + $html .= ' '; + $html .= ''; + $html .= ''; + + return $html; + } + + /** + * Check if inheritance checkbox has to be rendered + * + * @param Varien_Data_Form_Element_Abstract $element + * @return bool + */ + protected function _isInheritCheckboxRequired(Varien_Data_Form_Element_Abstract $element) + { + return $element->getCanUseWebsiteValue() || $element->getCanUseDefaultValue(); + } + + /** + * Retrieve label for the inheritance checkbox + * + * @param Varien_Data_Form_Element_Abstract $element + * @return string + */ + protected function _getInheritCheckboxLabel(Varien_Data_Form_Element_Abstract $element) + { + $checkboxLabel = Mage::helper('Mage_Adminhtml_Helper_Data')->__('Use Default'); + if ($element->getCanUseWebsiteValue()) { + $checkboxLabel = Mage::helper('Mage_Adminhtml_Helper_Data')->__('Use Website'); } + return $checkboxLabel; + } - $html.= ''; - if ($element->getScope()) { + /** + * Render scope label + * + * @param Varien_Data_Form_Element_Abstract $element + * @return Mage_Adminhtml_Block_System_Config_Form_Field + */ + protected function _renderScopeLabel(Varien_Data_Form_Element_Abstract $element) + { + $html = ''; + if ($element->getScope() && !Mage::app()->isSingleStoreMode()) { $html .= $element->getScopeLabel(); } - $html.= ''; + $html .= ''; + return $html; + } - $html.= ''; + /** + * Render field hint + * + * @param Varien_Data_Form_Element_Abstract $element + * @return string + */ + protected function _renderHint(Varien_Data_Form_Element_Abstract $element) + { + $html = ''; if ($element->getHint()) { - $html.= '
'; - $html.= '
' . $element->getHint() . '
'; - $html.= '
'; + $html .= '
' . $element->getHint() . '
'; } - $html.= ''; - - $html.= ''; + $html .= ''; return $html; } diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Switcher.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Switcher.php index 4f65191a2ec1b..bf17114054380 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Switcher.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Switcher.php @@ -115,4 +115,17 @@ public function getHintHtml() { return Mage::getBlockSingleton('Mage_Adminhtml_Block_Store_Switcher')->getHintHtml(); } + + /** + * Prepare html output + * + * @return string + */ + protected function _toHtml() + { + if (!Mage::app()->isSingleStoreMode()) { + return parent::_toHtml(); + } + return ''; + } } diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Form.php b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Form.php index 7ee9844ce2b9b..8806f90ae396f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Form.php @@ -148,7 +148,7 @@ protected function _prepareForm() $form->setId('rate_form'); $form->setMethod('post'); - if (!Mage::app()->isSingleStoreMode()) { + if (!Mage::app()->hasSingleStore()) { $form->addElement( Mage::getBlockSingleton('Mage_Adminhtml_Block_Tax_Rate_Title_Fieldset') ->setLegend(Mage::helper('Mage_Tax_Helper_Data') diff --git a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php index 2e3c77b911881..ee3f282e9744f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php @@ -191,7 +191,7 @@ protected function _prepareForm() protected function _prepareStoreElement($fieldset) { // get store switcher or a hidden field with it's id - if (Mage::app()->isSingleStoreMode()) { + if (Mage::app()->hasSingleStore()) { $fieldset->addField('store_id', 'hidden', array( 'name' => 'store_id', 'value' => Mage::app()->getStore(true)->getId() diff --git a/app/code/core/Mage/Adminhtml/Model/Config.php b/app/code/core/Mage/Adminhtml/Model/Config.php index 9517f4b700154..14d6489512a97 100644 --- a/app/code/core/Mage/Adminhtml/Model/Config.php +++ b/app/code/core/Mage/Adminhtml/Model/Config.php @@ -49,6 +49,25 @@ class Mage_Adminhtml_Model_Config extends Varien_Simplexml_Config */ protected $_tabs; + /** + * Main Application object + * + * @var Mage_Core_Model_App + */ + protected $_app; + + /** + * Initializes XML for this configuration + * + * @param array $arguments + */ + public function __construct(array $arguments = array()) + { + $this->_app = isset($arguments['app']) ? $arguments['app'] : Mage::app(); + $sourceData = isset($arguments['data']) ? $arguments['data'] : array(); + return parent::__construct($sourceData); + } + /** * Enter description here... * @@ -114,55 +133,57 @@ public function getSection($sectionCode=null, $websiteCode=null, $storeCode=null } /** - * Enter description here... + * Check whether node has child node that can be shown * * @param Varien_Simplexml_Element $node * @param string $websiteCode * @param string $storeCode - * @param boolean $isField * @return boolean */ - public function hasChildren ($node, $websiteCode=null, $storeCode=null, $isField=false) + public function hasChildren($node, $websiteCode = null, $storeCode = null) { - $showTab = false; - if ($storeCode) { - if (isset($node->show_in_store)) { - if ((int)$node->show_in_store) { - $showTab=true; - } - } - }elseif ($websiteCode) { - if (isset($node->show_in_website)) { - if ((int)$node->show_in_website) { - $showTab=true; - } - } - } elseif (isset($node->show_in_default)) { - if ((int)$node->show_in_default) { - $showTab=true; - } + if (!$this->_canShowNode($node, $websiteCode, $storeCode)) { + return false; } - if ($showTab) { - if (isset($node->groups)) { - foreach ($node->groups->children() as $children){ - if ($this->hasChildren ($children, $websiteCode, $storeCode)) { - return true; - } - } - }elseif (isset($node->fields)) { + if (isset($node->groups)) { + $children = $node->groups->children(); + } elseif (isset($node->fields)) { + $children = $node->fields->children(); + } else { + return true; + } - foreach ($node->fields->children() as $children){ - if ($this->hasChildren ($children, $websiteCode, $storeCode, true)) { - return true; - } - } - } else { + foreach ($children as $child) { + if ($this->hasChildren($child, $websiteCode, $storeCode)) { return true; } } return false; + } + + /** + * Checks whether it is possible to show the node + * + * @param Varien_Simplexml_Element $node + * @param string $websiteCode + * @param string $storeCode + * @return boolean + */ + protected function _canShowNode($node, $websiteCode = null, $storeCode = null) + { + $showTab = false; + if ($storeCode) { + $showTab = (int)$node->show_in_store; + } elseif ($websiteCode) { + $showTab = (int)$node->show_in_website; + } elseif (!empty($node->show_in_default)) { + $showTab = true; + } + $showTab = $showTab || $this->_app->isSingleStoreMode(); + $showTab = $showTab && !($this->_app->isSingleStoreMode() && (int)$node->hide_in_single_store_mode); + return $showTab; } /** diff --git a/app/code/core/Mage/Adminhtml/Model/Config/Data.php b/app/code/core/Mage/Adminhtml/Model/Config/Data.php index 01b8cb121e482..b3a7de03b9662 100644 --- a/app/code/core/Mage/Adminhtml/Model/Config/Data.php +++ b/app/code/core/Mage/Adminhtml/Model/Config/Data.php @@ -76,7 +76,7 @@ public function save() /** * Map field names if they were cloned */ - $groupConfig = $sections->descend($section.'/groups/'.$group); + $groupConfig = $sections->descend($section . '/groups/' . $group); if ($clonedFields = !empty($groupConfig->clone_fields)) { if ($groupConfig->clone_model) { @@ -85,12 +85,12 @@ public function save() Mage::throwException('Config form fieldset clone model required to be able to clone fields'); } $mappedFields = array(); - $fieldsConfig = $sections->descend($section.'/groups/'.$group.'/fields'); + $fieldsConfig = $sections->descend($section . '/groups/' . $group . '/fields'); if ($fieldsConfig->hasChildren()) { foreach ($fieldsConfig->children() as $field => $node) { foreach ($cloneModel->getPrefixes() as $prefix) { - $mappedFields[$prefix['field'].(string)$field] = (string)$field; + $mappedFields[$prefix['field'] . (string)$field] = (string)$field; } } } @@ -104,27 +104,32 @@ public function save() } foreach ($groupData['fields'] as $field => $fieldData) { - /** * Get field backend model */ - $backendClass = (string)$sections->descend($section.'/groups/'.$group.'/fields/'.$field.'/backend_model'); + $backendClass = (string)$sections->descend( + $section . '/groups/' . $group . '/fields/' . $field . '/backend_model' + ); if (!$backendClass && $clonedFields && isset($mappedFields[$field])) { - $backendClass = (string)$sections->descend($section.'/groups/'.$group.'/fields/'.$mappedFields[$field].'/backend_model'); + $backendClass = (string)$sections->descend( + $section . '/groups/' . $group . '/fields/' . $mappedFields[$field] . '/backend_model' + ); } if (!$backendClass) { $backendClass = 'Mage_Core_Model_Config_Data'; } + /* @var $dataObject Mage_Core_Model_Config_Data */ $dataObject = Mage::getModel($backendClass); if (!$dataObject instanceof Mage_Core_Model_Config_Data) { - Mage::throwException('Invalid config field backend model: '.$backendClass); + Mage::throwException('Invalid config field backend model: ' . $backendClass); } - /* @var $dataObject Mage_Core_Model_Config_Data */ - $fieldConfig = $sections->descend($section.'/groups/'.$group.'/fields/'.$field); + $fieldConfig = $sections->descend($section . '/groups/' . $group . '/fields/' . $field); if (!$fieldConfig && $clonedFields && isset($mappedFields[$field])) { - $fieldConfig = $sections->descend($section.'/groups/'.$group.'/fields/'.$mappedFields[$field]); + $fieldConfig = $sections->descend( + $section . '/groups/' . $group . '/fields/' . $mappedFields[$field] + ); } $dataObject @@ -136,18 +141,15 @@ public function save() ->setScope($scope) ->setScopeId($scopeId) ->setFieldConfig($fieldConfig) - ->setFieldsetData($fieldsetData) - ; + ->setFieldsetData($fieldsetData); + + $this->_checkSingleStoreMode($fieldConfig, $dataObject); if (!isset($fieldData['value'])) { $fieldData['value'] = null; } - /*if (is_array($fieldData['value'])) { - $fieldData['value'] = join(',', $fieldData['value']); - }*/ - - $path = $section.'/'.$group.'/'.$field; + $path = $section . '/' . $group . '/' . $field; /** * Look for custom defined field path @@ -178,12 +180,10 @@ public function save() */ if (!$inherit) { $saveTransaction->addObject($dataObject); - } - else { + } else { $deleteTransaction->addObject($dataObject); } - } - elseif (!$inherit) { + } elseif (!$inherit) { $dataObject->unsConfigId(); $saveTransaction->addObject($dataObject); } @@ -303,4 +303,25 @@ protected function _getPathConfig($path, $full = true) } return $config; } + + /** + * Set correct scope if isSingleStoreMode = true + * + * @param Varien_Simplexml_Element $fieldConfig + * @param Mage_Core_Model_Config_Data $dataObject + */ + protected function _checkSingleStoreMode($fieldConfig, $dataObject) + { + $isSingleStoreMode = Mage::app()->isSingleStoreMode(); + if (!$isSingleStoreMode) { + return; + } + if (!(int)$fieldConfig->show_in_default) { + $websites = Mage::app()->getWebsites(); + $singleStoreWebsite = array_shift($websites); + $dataObject->setScope('websites'); + $dataObject->setWebsiteCode($singleStoreWebsite->getCode()); + $dataObject->setScopeId($singleStoreWebsite->getId()); + } + } } diff --git a/app/code/core/Mage/Adminhtml/Model/Session/Quote.php b/app/code/core/Mage/Adminhtml/Model/Session/Quote.php index 8ff13b2d3f57a..a0873a1cd92f1 100644 --- a/app/code/core/Mage/Adminhtml/Model/Session/Quote.php +++ b/app/code/core/Mage/Adminhtml/Model/Session/Quote.php @@ -66,7 +66,7 @@ class Mage_Adminhtml_Model_Session_Quote extends Mage_Core_Model_Session_Abstrac public function __construct() { $this->init('adminhtml_quote'); - if (Mage::app()->isSingleStoreMode()) { + if (Mage::app()->hasSingleStore()) { $this->setStoreId(Mage::app()->getStore(true)->getId()); } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php index d4e7439ed7f43..7cda96758f3a4 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php @@ -320,6 +320,15 @@ public function saveAction() 'request' => $this->getRequest() )); + /** + * Check "Use Default Value" checkboxes values + */ + if ($useDefaults = $this->getRequest()->getPost('use_default')) { + foreach ($useDefaults as $attributeCode) { + $category->setData($attributeCode, false); + } + } + /** * Proceed with $_POST['use_config'] * set into category model for proccessing through validation @@ -339,15 +348,6 @@ public function saveAction() } } - /** - * Check "Use Default Value" checkboxes values - */ - if ($useDefaults = $this->getRequest()->getPost('use_default')) { - foreach ($useDefaults as $attributeCode) { - $category->setData($attributeCode, false); - } - } - /** * Unset $_POST['use_config'] before save */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php index 0e0d74dfed0a4..c0c8379c771da 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php @@ -320,7 +320,7 @@ public function postAction() $session = Mage::getSingleton('Mage_Adminhtml_Model_Session'); if ($data = $this->getRequest()->getPost()) { - if (Mage::app()->isSingleStoreMode()) { + if (Mage::app()->hasSingleStore()) { $data['stores'] = array(Mage::app()->getStore(true)->getId()); } else if (isset($data['select_stores'])) { $data['stores'] = $data['select_stores']; diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php index a918412713aad..df4759b3e904a 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php @@ -589,7 +589,7 @@ protected function _initProductSave($product) $product->lockAttribute('media'); } - if (Mage::app()->isSingleStoreMode()) { + if (Mage::app()->hasSingleStore()) { $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId())); } diff --git a/app/code/core/Mage/Adminhtml/controllers/Newsletter/QueueController.php b/app/code/core/Mage/Adminhtml/controllers/Newsletter/QueueController.php index ce540fc28aa29..821190b376c26 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Newsletter/QueueController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Newsletter/QueueController.php @@ -261,6 +261,10 @@ public function saveAction() } $queue->save(); + + $this->_getSession()->addSuccess($this->_getHelper()->__('The newsletter queue has been saved.')); + $this->_getSession()->setFormData(false); + $this->_redirect('*/*'); } catch (Mage_Core_Exception $e) { diff --git a/app/code/core/Mage/Adminhtml/controllers/Newsletter/TemplateController.php b/app/code/core/Mage/Adminhtml/controllers/Newsletter/TemplateController.php index 458c8ffc0de62..206962e484ad2 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Newsletter/TemplateController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Newsletter/TemplateController.php @@ -182,18 +182,25 @@ public function saveAction () if ($this->getRequest()->getParam('_save_as_flag')) { $template->setId(null); } + $template->save(); + + $this->_getSession()->addSuccess($this->_getHelper()->__('The newsletter template has been saved.')); + $this->_getSession()->setFormData(false); + $this->_redirect('*/*'); - } - catch (Mage_Core_Exception $e) { + return; + } catch (Mage_Core_Exception $e) { $this->_getSession()->addError(nl2br($e->getMessage())); $this->_getSession()->setData('newsletter_template_form_data', $this->getRequest()->getParams()); - } - catch (Exception $e) { - $this->_getSession()->addException($e, Mage::helper('Mage_Adminhtml_Helper_Data')->__('An error occurred while saving this template.')); + } catch (Exception $e) { + $this->_getSession()->addException($e, + $this->_getHelper()->__('An error occurred while saving this template.') + ); $this->_getSession()->setData('newsletter_template_form_data', $this->getRequest()->getParams()); } + $this->_forward('new'); } @@ -208,12 +215,14 @@ public function deleteAction () if ($template->getId()) { try { $template->delete(); - } - catch (Mage_Core_Exception $e) { + $this->_getSession()->addSuccess($this->_getHelper()->__('The newsletter template has been deleted.')); + $this->_getSession()->setFormData(false); + } catch (Mage_Core_Exception $e) { $this->_getSession()->addError($e->getMessage()); - } - catch (Exception $e) { - $this->_getSession()->addException($e, Mage::helper('Mage_Adminhtml_Helper_Data')->__('An error occurred while deleting this template.')); + } catch (Exception $e) { + $this->_getSession()->addException($e, + $this->_getHelper()->__('An error occurred while deleting this template.') + ); } } $this->_redirect('*/*'); diff --git a/app/code/core/Mage/Adminhtml/controllers/RatingController.php b/app/code/core/Mage/Adminhtml/controllers/RatingController.php index dabb71e938691..59da19f559b8c 100644 --- a/app/code/core/Mage/Adminhtml/controllers/RatingController.php +++ b/app/code/core/Mage/Adminhtml/controllers/RatingController.php @@ -85,11 +85,13 @@ public function saveAction() $stores = $this->getRequest()->getParam('stores'); $position = (int)$this->getRequest()->getParam('position'); $stores[] = 0; + $isActive = (bool)$this->getRequest()->getParam('is_active'); $ratingModel->setRatingCode($this->getRequest()->getParam('rating_code')) ->setRatingCodes($this->getRequest()->getParam('rating_codes')) ->setStores($stores) ->setPosition($position) ->setId($this->getRequest()->getParam('id')) + ->setIsActive($isActive) ->setEntityId(Mage::registry('entityId')) ->save(); diff --git a/app/code/core/Mage/Adminhtml/view/adminhtml/customer/tab/view/sales.phtml b/app/code/core/Mage/Adminhtml/view/adminhtml/customer/tab/view/sales.phtml index 3ab79a2dd9cfc..7482625ab6a82 100644 --- a/app/code/core/Mage/Adminhtml/view/adminhtml/customer/tab/view/sales.phtml +++ b/app/code/core/Mage/Adminhtml/view/adminhtml/customer/tab/view/sales.phtml @@ -30,20 +30,24 @@ - - - + isSingleStoreMode()): ?> + + + + - - - - - - - + isSingleStoreMode()): ?> + + + + + + + + getRows()): ?> @@ -52,30 +56,34 @@ $_stores): ?> - getStoreId() == 0): ?> - - - > - - - - - - - - - - - - - + isSingleStoreMode()): ?> + getStoreId() == 0): ?> + + + > + + + + + + + + + + + + + + + + - +
__('Website') ?>__('Store') ?>__('Store View') ?>__('Website') ?>__('Store') ?>__('Store View') ?> __('Lifetime Sales') ?> __('Average Sale') ?>
__('All Store Views') ?>formatCurrency($this->getTotals()->getBaseLifetime()) ?>formatCurrency($this->getTotals()->getAvgsale()) ?>
__('All Store Views') ?>formatCurrency($this->getTotals()->getBaseLifetime()) ?>formatCurrency($this->getTotals()->getAvgsale()) ?>
getStoreName() ?>getWebsiteName() ?>getGroupName() ?>getStoreName() ?>formatCurrency($_row->getLifetime(), $_row->getWebsiteId()) ?>formatCurrency($_row->getAvgsale(), $_row->getWebsiteId()) ?>
getStoreName() ?>getWebsiteName() ?>getGroupName() ?>getStoreName() ?>
formatCurrency($_row->getLifetime(), $_row->getWebsiteId()) ?>formatCurrency($_row->getAvgsale(), $_row->getWebsiteId()) ?>
diff --git a/app/code/core/Mage/Adminhtml/view/adminhtml/sales/order/view/info.phtml b/app/code/core/Mage/Adminhtml/view/adminhtml/sales/order/view/info.phtml index 024f86c578240..be84f623646f4 100644 --- a/app/code/core/Mage/Adminhtml/view/adminhtml/sales/order/view/info.phtml +++ b/app/code/core/Mage/Adminhtml/view/adminhtml/sales/order/view/info.phtml @@ -61,10 +61,12 @@ $orderStoreDate = $this->formatDate($_order->getCreatedAtStoreDate(), 'medium', getStatusLabel() ?> + isSingleStoreMode() == false):?> getOrderStoreName() ?> + getRelationChildId()): ?> diff --git a/app/code/core/Mage/Backend/Block/Menu.php b/app/code/core/Mage/Backend/Block/Menu.php index 4ebacfbebb84f..f568476d79453 100644 --- a/app/code/core/Mage/Backend/Block/Menu.php +++ b/app/code/core/Mage/Backend/Block/Menu.php @@ -42,12 +42,12 @@ class Mage_Backend_Block_Menu extends Mage_Backend_Block_Template /** * @var string */ - protected $_containerRendererBlock; + protected $_containerRenderer; /** * @var string */ - protected $_itemRendererBlock; + protected $_itemRenderer; /** * Backend URL instance @@ -75,34 +75,127 @@ protected function _construct() } /** - * Retrieve cache lifetime + * Check whether given item is currently selected * - * @return int + * @param Mage_Backend_Model_Menu_Item $item + * @param int $level + * @return bool */ - public function getCacheLifetime() + protected function _isItemActive(Mage_Backend_Model_Menu_Item $item, $level) { - return 86400; + $itemModel = $this->getActiveItemModel(); + $output = false; + + if ($level == 0 + && $itemModel instanceof Mage_Backend_Model_Menu_Item + && ($itemModel->getId() == $item->getId() + || $item->getChildren()->get($itemModel->getId())!== null) + ) { + $output = true; + } + return $output; } /** - * Get Key pieces for caching block content + * Render menu item anchor label * - * @return array + * @param Mage_Backend_Model_Menu_Item $menuItem + * @return string */ - public function getCacheKeyInfo() + protected function _getAnchorLabel($menuItem) { - $cacheKeyInfo = array( - 'admin_top_nav', - $this->getActive(), - Mage::getSingleton('Mage_Backend_Model_Auth_Session')->getUser()->getId(), - Mage::app()->getLocale()->getLocaleCode() - ); - // Add additional key parameters if needed - $additionalCacheKeyInfo = $this->getAdditionalCacheKeyInfo(); - if (is_array($additionalCacheKeyInfo) && !empty($additionalCacheKeyInfo)) { - $cacheKeyInfo = array_merge($cacheKeyInfo, $additionalCacheKeyInfo); - } - return $cacheKeyInfo; + return $this->escapeHtml($menuItem->getModuleHelper()->__($menuItem->getTitle())); + } + + /** + * Render menu item anchor title + * + * @param Mage_Backend_Model_Menu_Item $menuItem + * @return string + */ + protected function _renderItemAnchorTitle($menuItem) + { + return $menuItem->hasTooltip() ? + 'title="' . $menuItem->getModuleHelper()->__($menuItem->getTooltip()) . '"' : + ''; + } + + /** + * Render menu item onclick function + * + * @param Mage_Backend_Model_Menu_Item $menuItem + * @return string + */ + protected function _renderItemOnclickFunction($menuItem) + { + return $menuItem->hasClickCallback() ? ' onclick="' . $menuItem->getClickCallback() . '"' : ''; + } + + /** + * Render menu item anchor css class + * + * @param Mage_Backend_Model_Menu_Item $menuItem + * @param int $level + * @return string + */ + protected function _renderAnchorCssClass($menuItem, $level) + { + return $this->_isItemActive($menuItem, $level) ? 'active' : ''; + } + + /** + * Render menu item mouse events + * @param Mage_Backend_Model_Menu_Item $menuItem + * @return string + */ + protected function _renderMouseEvent($menuItem) + { + return $menuItem->hasChildren() ? + 'onmouseover="Element.addClassName(this,\'over\')" onmouseout="Element.removeClassName(this,\'over\')"' : + ''; + } + + /** + * Render item css class + * + * @param Mage_Backend_Model_Menu_Item $menuItem + * @param int $level + * @return string + */ + protected function _renderItemCssClass($menuItem, $level) + { + $isLast = 0 == $level && (bool) $this->getMenuModel()->isLast($menuItem) ? 'last' : ''; + $output = ($this->_isItemActive($menuItem, $level) ? 'active' : '') + . ' ' . ($menuItem->hasChildren() ? 'parent' : '') + . ' ' . $isLast + . ' ' . 'level' . $level; + return $output; + } + + /** + * Render menu item anchor + * @param Mage_Backend_Model_Menu_Item $menuItem + * @param int $level + * @return string + */ + protected function _renderAnchor($menuItem, $level) + { + return '_renderItemAnchorTitle($menuItem) + . $this->_renderItemOnclickFunction($menuItem) + . ' class="' . $this->_renderAnchorCssClass($menuItem, $level) . '">' + . '' . $this->_getAnchorLabel($menuItem) . '' + . ''; + } + + /** + * Get menu filter iterator + * + * @param Mage_Backend_Model_Menu $menu + * @return Mage_Backend_Model_Menu_Filter_Iterator + */ + protected function _getMenuIterator($menu) + { + return Mage::getModel('Mage_Backend_Model_Menu_Filter_Iterator', $menu->getIterator()); } /** @@ -135,67 +228,72 @@ protected function _callbackSecretKey($match) } /** - * Get menu config model - * @return Mage_Backend_Model_Menu + * Retrieve cache lifetime + * + * @return int */ - public function getMenuModel() + public function getCacheLifetime() { - return Mage::getSingleton('Mage_Backend_Model_Menu_Config')->getMenu(); + return 86400; } /** - * Render menu container - * @param $menu - * @param $level - * @return string HTML + * Get Key pieces for caching block content + * + * @return array */ - public function renderMenuContainer($menu, $level = 0) + public function getCacheKeyInfo() { - $block = $this->getChildBlock($this->getContainerRendererBlock()); - $block->setMenu($menu); - $block->setLevel($level); - $block->setMenuBlock($this); - return $block->toHtml(); + $cacheKeyInfo = array( + 'admin_top_nav', + $this->getActive(), + Mage::getSingleton('Mage_Backend_Model_Auth_Session')->getUser()->getId(), + Mage::app()->getLocale()->getLocaleCode() + ); + // Add additional key parameters if needed + $newCacheKeyInfo = $this->getAdditionalCacheKeyInfo(); + if (is_array($newCacheKeyInfo) && !empty($newCacheKeyInfo)) { + $cacheKeyInfo = array_merge($cacheKeyInfo, $newCacheKeyInfo); + } + return $cacheKeyInfo; } /** - * Set container renderer block name - * @param string $renderer - * @return Mage_Backend_Block_Menu + * Get menu config model + * + * @return Mage_Backend_Model_Menu */ - public function setContainerRendererBlock($renderer) + public function getMenuModel() { - $this->_containerRendererBlock = $renderer; - return $this; + return Mage::getSingleton('Mage_Backend_Model_Menu_Config')->getMenu(); } /** - * Get container renderer block name - * @return string + * Render menu + * + * @param Mage_Backend_Model_Menu $menu + * @param int $level + * @return string HTML */ - public function getContainerRendererBlock() + public function renderMenu($menu, $level = 0) { - return $this->_containerRendererBlock; - } + $output = ''; + + return $output; } /** diff --git a/app/code/core/Mage/Backend/Block/Menu/Container.php b/app/code/core/Mage/Backend/Block/Menu/Container.php deleted file mode 100644 index 9b7ba884a71ac..0000000000000 --- a/app/code/core/Mage/Backend/Block/Menu/Container.php +++ /dev/null @@ -1,99 +0,0 @@ - - */ -class Mage_Backend_Block_Menu_Container extends Mage_Backend_Block_Template -{ - /** - * @var Mage_Backend_Model_Menu - */ - protected $_menu; - - /** - * Set menu model - * @return Mage_Backend_Model_Menu - */ - public function getMenu() - { - return $this->_menu; - } - - /** - * Get menu filter iterator - * @return Mage_Backend_Model_Menu_Filter_Iterator - */ - public function getMenuIterator() - { - return Mage::getModel('Mage_Backend_Model_Menu_Filter_Iterator', $this->getMenu()->getIterator()); - } - - /** - * Get menu model - * - * @param Mage_Backend_Model_Menu $menu - * @return Mage_Backend_Block_Menu_Container - */ - public function setMenu(Mage_Backend_Model_Menu $menu) - { - $this->_menu = $menu; - return $this; - } - - /** - * Render menu item element - * @param Mage_Backend_Model_Menu_Item $menuItem - * @return string - */ - public function renderMenuItem(Mage_Backend_Model_Menu_Item $menuItem) - { - /** - * Save current level - */ - $currentLevel = $this->getLevel(); - - /** - * Render child blocks - * @var Mage_Backend_Block_Menu_Item - */ - $block = $this->getMenuBlock()->getChildBlock($this->getMenuBlock()->getItemRendererBlock()); - $block->setMenuItem($menuItem); - $block->setLevel($currentLevel); - $block->setContainerRenderer($this->getMenuBlock()); - $output = $block->toHtml(); - - /** - * Set current level, because it will be changed in child block - */ - $this->setLevel($currentLevel); - return $output; - } -} diff --git a/app/code/core/Mage/Backend/Block/Menu/Item.php b/app/code/core/Mage/Backend/Block/Menu/Item.php deleted file mode 100644 index 68c7bc943184c..0000000000000 --- a/app/code/core/Mage/Backend/Block/Menu/Item.php +++ /dev/null @@ -1,115 +0,0 @@ - - */ -class Mage_Backend_Block_Menu_Item extends Mage_Backend_Block_Template -{ - /** - * @var Mage_Backend_Block_Menu - */ - protected $_containerRenderer; - - /** - * @var Mage_Backend_Model_Menu_Item - */ - protected $_menuItem; - - /** - * Set menu model - * @return Mage_Backend_Model_Menu_Item - */ - public function getMenuItem() - { - return $this->_menuItem; - } - - /** - * Get menu item model - * - * @param Mage_Backend_Model_Menu_Item $menuItem - * @return Mage_Backend_Block_Menu_Item - */ - public function setMenuItem(Mage_Backend_Model_Menu_Item $menuItem) - { - $this->_menuItem = $menuItem; - return $this; - } - - /** - * Check whether given item is currently selected - * - * @param Mage_Backend_Model_Menu_Item $item - * @return bool - */ - public function isItemActive(Mage_Backend_Model_Menu_Item $item) - { - $itemModel = $this->getContainerRenderer()->getActiveItemModel(); - $output = false; - - if ($this->getLevel() == 0 - && $itemModel instanceof Mage_Backend_Model_Menu_Item - && ($itemModel->getId() == $item->getId() - || $item->getChildren()->get($itemModel->getId())!== null) - ) { - $output = true; - } - return $output; - } - - /** - * Current menu item is last - * @return bool - */ - public function isLast() - { - return ($this->getLevel() == 0 - && (bool)$this->getContainerRenderer()->getMenuModel()->isLast($this->getMenuItem())); - } - - /** - * @return Mage_Backend_Block_Menu - */ - public function getContainerRenderer() - { - return $this->_containerRenderer; - } - - /** - * @param Mage_Backend_Block_Menu $block - * @return Mage_Backend_Block_Menu_Item - */ - public function setContainerRenderer(Mage_Backend_Block_Menu $block) - { - $this->_containerRenderer = $block; - return $this; - } -} diff --git a/app/code/core/Mage/Backend/Model/Menu/Builder.php b/app/code/core/Mage/Backend/Model/Menu/Builder.php index 573ac181931f9..b0e561e67208b 100644 --- a/app/code/core/Mage/Backend/Model/Menu/Builder.php +++ b/app/code/core/Mage/Backend/Model/Menu/Builder.php @@ -98,7 +98,7 @@ public function getResult() } // Build menu tree based on "parent" param - foreach($items as $id => $item) { + foreach ($items as $id => $item) { $sortOrder = isset($params[$id]['sortOrder']) ? $params[$id]['sortOrder'] : null; $parentId = isset($params[$id]['parent']) ? $params[$id]['parent'] : null; $isRemoved = isset($params[$id]['removed']); diff --git a/app/code/core/Mage/Backend/Model/Menu/Builder/Command/Add.php b/app/code/core/Mage/Backend/Model/Menu/Builder/Command/Add.php index e676ab50d7023..a26fa64ecd2df 100644 --- a/app/code/core/Mage/Backend/Model/Menu/Builder/Command/Add.php +++ b/app/code/core/Mage/Backend/Model/Menu/Builder/Command/Add.php @@ -64,7 +64,7 @@ public function chain(Mage_Backend_Model_Menu_Builder_CommandAbstract $command) */ protected function _execute(array $itemParams) { - foreach($this->_data as $key => $value) { + foreach ($this->_data as $key => $value) { $itemParams[$key] = isset($itemParams[$key]) ? $itemParams[$key] : $value; } return $itemParams; diff --git a/app/code/core/Mage/Backend/Model/Menu/Builder/CommandAbstract.php b/app/code/core/Mage/Backend/Model/Menu/Builder/CommandAbstract.php index d97e8162d8adf..f1e01a763e908 100644 --- a/app/code/core/Mage/Backend/Model/Menu/Builder/CommandAbstract.php +++ b/app/code/core/Mage/Backend/Model/Menu/Builder/CommandAbstract.php @@ -56,7 +56,7 @@ abstract class Mage_Backend_Model_Menu_Builder_CommandAbstract */ public function __construct(array $data = array()) { - foreach($this->_requiredParams as $param) { + foreach ($this->_requiredParams as $param) { if (!isset($data[$param]) || is_null($data[$param])) { throw new InvalidArgumentException("Missing required param " . $param); } diff --git a/app/code/core/Mage/Backend/Model/Menu/Config.php b/app/code/core/Mage/Backend/Model/Menu/Config.php index b3c56f3c741bb..449a38218abaf 100644 --- a/app/code/core/Mage/Backend/Model/Menu/Config.php +++ b/app/code/core/Mage/Backend/Model/Menu/Config.php @@ -26,6 +26,7 @@ class Mage_Backend_Model_Menu_Config { const CACHE_ID = 'backend_menu_config'; + const CACHE_MENU_OBJECT = 'backend_menu_object'; /** * @var Mage_Core_Model_Cache @@ -43,9 +44,9 @@ class Mage_Backend_Model_Menu_Config protected $_eventManager; /** - * @var Mage_Backend_Model_Menu_Builder + * @var Mage_Backend_Model_Menu_Factory */ - protected $_menuBuilder; + protected $_menuFactory; /** * Menu model * @@ -70,12 +71,8 @@ public function __construct(array $arguments = array()) ? $arguments['logger'] : Mage::getSingleton('Mage_Backend_Model_Menu_Logger'); - $this->_menuBuilder = isset($arguments['menuBuilder']) - ? $arguments['menuBuilder'] - : Mage::getSingleton('Mage_Backend_Model_Menu_Builder', array( - 'menu' => Mage::getSingleton('Mage_Backend_Model_Menu_Factory')->getMenuInstance(), - 'itemFactory' => Mage::getSingleton('Mage_Backend_Model_Menu_Item_Factory'), - )); + $this->_menuFactory = isset($arguments['menuFactory']) ? $arguments['menuFactory'] : + Mage::getSingleton('Mage_Backend_Model_Menu_Factory'); } /** @@ -111,6 +108,22 @@ public function getMenu() protected function _initMenu() { if (!$this->_menu) { + $this->_menu = $this->_menuFactory->getMenuInstance(); + + if ($this->_cache->canUse('config')) { + $cache = $this->_cache->load(self::CACHE_MENU_OBJECT); + if ($cache) { + $this->_menu->unserialize($cache); + return; + } + } + + /* @var $director Mage_Backend_Model_Menu_Builder */ + $menuBuilder = $this->_appConfig->getModelInstance('Mage_Backend_Model_Menu_Builder', array( + 'menu' => $this->_menu, + 'itemFactory' => $this->_appConfig->getModelInstance('Mage_Backend_Model_Menu_Item_Factory'), + )); + /* @var $director Mage_Backend_Model_Menu_Director_Dom */ $director = $this->_appConfig->getModelInstance( 'Mage_Backend_Model_Menu_Director_Dom', @@ -120,9 +133,17 @@ protected function _initMenu() 'logger' => $this->_logger ) ); - $director->buildMenu($this->_menuBuilder); - $this->_menu = $this->_menuBuilder->getResult(); + $director->buildMenu($menuBuilder); + $this->_menu = $menuBuilder->getResult(); $this->_eventManager->dispatch('backend_menu_load_after', array('menu' => $this->_menu)); + + if ($this->_cache->canUse('config')) { + $this->_cache->save( + $this->_menu->serialize(), + self::CACHE_MENU_OBJECT, + array(Mage_Core_Model_Config::CACHE_TAG) + ); + } } } diff --git a/app/code/core/Mage/Backend/Model/Menu/Config/Menu.php b/app/code/core/Mage/Backend/Model/Menu/Config/Menu.php index 5d38d46701bcc..ca9c6431f798f 100644 --- a/app/code/core/Mage/Backend/Model/Menu/Config/Menu.php +++ b/app/code/core/Mage/Backend/Model/Menu/Config/Menu.php @@ -42,10 +42,10 @@ public function getSchemaFile() /** * Extract configuration data from the DOM structure * - * @param DOMDocument $dom + * @param DOMDocument $domDocument * @return array */ - protected function _extractData(DOMDocument $dom) + protected function _extractData(DOMDocument $domDocument) { return array(); } diff --git a/app/code/core/Mage/Backend/Model/Menu/Item.php b/app/code/core/Mage/Backend/Model/Menu/Item.php index 0f97f112f7e50..139795ad21aef 100644 --- a/app/code/core/Mage/Backend/Model/Menu/Item.php +++ b/app/code/core/Mage/Backend/Model/Menu/Item.php @@ -49,6 +49,13 @@ class Mage_Backend_Model_Menu_Item * @var Mage_Core_Helper_Abstract */ protected $_moduleHelper; + + /** + * Module helper name + * + * @var string + */ + protected $_moduleHelperName; /** * Menu item sort index in list @@ -260,7 +267,7 @@ public function hasClickCallback() /** * Retrieve item click callback * - * @return bool + * @return string */ public function getClickCallback() { @@ -434,4 +441,34 @@ public function isAllowed() return false; } } + + public function __sleep() + { + $this->_moduleHelperName = get_class($this->_moduleHelper); + return array( + '_parentId', + '_moduleHelperName', + '_sortIndex', + '_dependsOnConfig', + '_id', + '_resource', + '_path', + '_action', + '_dependsOnModule', + '_tooltip', + '_title', + '_submenu', + ); + } + + public function __wakeup() + { + $this->_moduleHelper = Mage::helper($this->_moduleHelperName); + $this->_validator = Mage::getSingleton('Mage_Backend_Model_Menu_Item_Validator'); + $this->_acl = Mage::getSingleton('Mage_Core_Model_Authorization'); + $this->_appConfig = Mage::getConfig(); + $this->_storeConfig = Mage::getSingleton('Mage_Core_Model_Store_Config'); + $this->_menuFactory = Mage::getSingleton('Mage_Backend_Model_Menu_Factory'); + $this->_urlModel = Mage::getSingleton('Mage_Backend_Model_Url'); + } } diff --git a/app/code/core/Mage/Backend/Model/Menu/Item/Validator.php b/app/code/core/Mage/Backend/Model/Menu/Item/Validator.php index 2975b5a63a40a..c65b3108b7938 100644 --- a/app/code/core/Mage/Backend/Model/Menu/Item/Validator.php +++ b/app/code/core/Mage/Backend/Model/Menu/Item/Validator.php @@ -81,14 +81,14 @@ public function __construct() $textValidator = new Zend_Validate_StringLength(array('min' => 3, 'max' => 50)); $titleValidator = $tooltipValidator = $textValidator; - $actionValidator = $moduleDependencyValidator = $configDependencyValidator = $attributeValidator; + $actionValidator = $moduleDepValidator = $configDepValidator = $attributeValidator; $this->_validators['id'] = $idValidator; $this->_validators['title'] = $titleValidator; $this->_validators['action'] = $actionValidator; $this->_validators['resource'] = $resourceValidator; - $this->_validators['dependsOnModule'] = $moduleDependencyValidator; - $this->_validators['dependsOnConfig'] = $configDependencyValidator; + $this->_validators['dependsOnModule'] = $moduleDepValidator; + $this->_validators['dependsOnConfig'] = $configDepValidator; $this->_validators['toolTip'] = $tooltipValidator; } /** diff --git a/app/code/core/Mage/Backend/Model/Menu/Logger.php b/app/code/core/Mage/Backend/Model/Menu/Logger.php index c4cedbbc5cbcc..6edf9e92058e3 100644 --- a/app/code/core/Mage/Backend/Model/Menu/Logger.php +++ b/app/code/core/Mage/Backend/Model/Menu/Logger.php @@ -53,10 +53,10 @@ public function log($message, $level = null, $file = '', $forceLog = false) /** * Log exception wrapper * - * @param Exception $e + * @param Exception $exception */ - public function logException(Exception $e) + public function logException(Exception $exception) { - $this->log("\n" . $e->__toString(), Zend_Log::ERR); + $this->log("\n" . $exception->__toString(), Zend_Log::ERR); } } diff --git a/app/code/core/Mage/Backend/view/adminhtml/layout.xml b/app/code/core/Mage/Backend/view/adminhtml/layout.xml index d06896a6ca19f..e29edd8b97b1b 100644 --- a/app/code/core/Mage/Backend/view/adminhtml/layout.xml +++ b/app/code/core/Mage/Backend/view/adminhtml/layout.xml @@ -28,12 +28,7 @@ - - - - menu_container_renderer - menu_item_renderer - + diff --git a/app/code/core/Mage/Backend/view/adminhtml/menu.phtml b/app/code/core/Mage/Backend/view/adminhtml/menu.phtml index c3ff88c590386..d2b696694377f 100644 --- a/app/code/core/Mage/Backend/view/adminhtml/menu.phtml +++ b/app/code/core/Mage/Backend/view/adminhtml/menu.phtml @@ -26,7 +26,7 @@ ?> diff --git a/app/code/core/Mage/Backend/view/adminhtml/menu/container.phtml b/app/code/core/Mage/Backend/view/adminhtml/menu/container.phtml deleted file mode 100644 index 6947fadefabc0..0000000000000 --- a/app/code/core/Mage/Backend/view/adminhtml/menu/container.phtml +++ /dev/null @@ -1,32 +0,0 @@ - - -
    getLevel() ? 'id="nav"' : '') ?>> - getMenuIterator() as $menuItem) : ?> - renderMenuItem($menuItem); ?> - -
diff --git a/app/code/core/Mage/Backend/view/adminhtml/menu/item.phtml b/app/code/core/Mage/Backend/view/adminhtml/menu/item.phtml deleted file mode 100644 index 3a1c0d3e7452a..0000000000000 --- a/app/code/core/Mage/Backend/view/adminhtml/menu/item.phtml +++ /dev/null @@ -1,37 +0,0 @@ - - -
  • getMenuItem()->hasChildren() ? 'onmouseover="Element.addClassName(this,\'over\')" onmouseout="Element.removeClassName(this,\'over\')"' : ''); ?> - class="isItemActive($this->getMenuItem()) ? 'active' : '') . ' ' . ($this->getMenuItem()->hasChildren() ? 'parent' : '') . ' ' . ($this->isLast() ? 'last' : '') . ' ' . ('level' . $this->getLevel()); ?>"> - getMenuItem()->hasTooltip() ? 'title="' . $this->getMenuItem()->getModuleHelper()->__($this->getMenuItem()->getTooltip()) . '"' : '') . ($this->getMenuItem()->hasClickCallback() ? ' onclick="' . $this->getMenuItem()->getClickCallback() . '"' : ''); ?> class="isItemActive($this->getMenuItem()) ? 'active' : ''); ?>"> - escapeHtml($this->getMenuItem()->getModuleHelper()->__($this->getMenuItem()->getTitle())); ?> - - getMenuItem()->hasChildren()) : ?> - getContainerRenderer()->renderMenuContainer($this->getMenuItem()->getChildren(), $this->getLevel() + 1); ?> - -
  • - diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option.php index 0e4c36209ae1a..20042d90b6d00 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option.php @@ -117,7 +117,7 @@ public function getElement() public function isMultiWebsites() { - return !Mage::app()->isSingleStoreMode(); + return !Mage::app()->hasSingleStore(); } protected function _prepareLayout() diff --git a/app/code/core/Mage/Catalog/Model/Api2/Product/Rest.php b/app/code/core/Mage/Catalog/Model/Api2/Product/Rest.php index eff796a98f84b..f679b3e3fc0f7 100644 --- a/app/code/core/Mage/Catalog/Model/Api2/Product/Rest.php +++ b/app/code/core/Mage/Catalog/Model/Api2/Product/Rest.php @@ -210,7 +210,7 @@ protected function _getProduct() // Check display settings for customers & guests if ($this->getApiUser()->getType() != Mage_Api2_Model_Auth_User_Admin::USER_TYPE) { // check if product assigned to any website and can be shown - if ((!Mage::app()->isSingleStoreMode() && !count($product->getWebsiteIds())) + if ((!Mage::app()->hasSingleStore() && !count($product->getWebsiteIds())) || !$productHelper->canShow($product) ) { $this->_critical(self::RESOURCE_NOT_FOUND); diff --git a/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Sortby.php b/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Sortby.php index a2d9b5bbfb1d5..a28cc47aecf26 100644 --- a/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Sortby.php +++ b/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Sortby.php @@ -24,7 +24,6 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - /** * Catalog Category Attribute Default and Available Sort By Backend Model * @@ -97,7 +96,8 @@ public function validate($object) * @param Varien_Object $object * @return Mage_Catalog_Model_Category_Attribute_Backend_Sortby */ - public function beforeSave($object) { + public function beforeSave($object) + { $attributeCode = $this->getAttribute()->getName(); if ($attributeCode == 'available_sort_by') { $data = $object->getData($attributeCode); @@ -106,13 +106,14 @@ public function beforeSave($object) { } $object->setData($attributeCode, join(',', $data)); } - if (is_null($object->getData($attributeCode))) { + if (!$object->hasData($attributeCode)) { $object->setData($attributeCode, false); } return $this; } - public function afterLoad($object) { + public function afterLoad($object) + { $attributeCode = $this->getAttribute()->getName(); if ($attributeCode == 'available_sort_by') { $data = $object->getData($attributeCode); diff --git a/app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php b/app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php index 4c7100b1583e7..7f46e3596a227 100644 --- a/app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php +++ b/app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php @@ -322,7 +322,7 @@ public function getStoreByCode($store) /** * In single store mode all data should be saved as default */ - if (Mage::app()->isSingleStoreMode()) { + if (Mage::app()->hasSingleStore()) { return Mage::app()->getStore(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID); } @@ -345,7 +345,7 @@ public function getStoreById($id) /** * In single store mode all data should be saved as default */ - if (Mage::app()->isSingleStoreMode()) { + if (Mage::app()->hasSingleStore()) { return Mage::app()->getStore(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID); } diff --git a/app/code/core/Mage/Catalog/Model/Product/Api.php b/app/code/core/Mage/Catalog/Model/Product/Api.php index 1c798bf40e06d..4ab7f02b0fb53 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Api.php +++ b/app/code/core/Mage/Catalog/Model/Product/Api.php @@ -309,7 +309,7 @@ protected function _prepareDataForSave($product, $productData) $product->setWebsiteIds($productData['websites']); } - if (Mage::app()->isSingleStoreMode()) { + if (Mage::app()->hasSingleStore()) { $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId())); } diff --git a/app/code/core/Mage/Catalog/Model/Product/Api/V2.php b/app/code/core/Mage/Catalog/Model/Product/Api/V2.php index 91a07177f32f9..1e19a50f0c288 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Api/V2.php +++ b/app/code/core/Mage/Catalog/Model/Product/Api/V2.php @@ -256,7 +256,7 @@ protected function _prepareDataForSave ($product, $productData) $product->setWebsiteIds($productData->websites); } - if (Mage::app()->isSingleStoreMode()) { + if (Mage::app()->hasSingleStore()) { $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId())); } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Abstract.php b/app/code/core/Mage/Catalog/Model/Resource/Abstract.php index decfb5b910f9d..3616a387a72cd 100755 --- a/app/code/core/Mage/Catalog/Model/Resource/Abstract.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Abstract.php @@ -114,7 +114,7 @@ protected function _getLoadAttributesSelect($object, $table) * store mode, customize some value per specific store view and than back * to single store mode. We should load correct values */ - if (Mage::app()->isSingleStoreMode()) { + if (Mage::app()->hasSingleStore()) { $storeId = (int)Mage::app()->getStore(true)->getId(); } else { $storeId = (int)$object->getStoreId(); @@ -228,7 +228,7 @@ protected function _saveAttributeValue($object, $attribute, $value) * for default store id * In this case we clear all not default values */ - if (Mage::app()->isSingleStoreMode()) { + if (Mage::app()->hasSingleStore()) { $storeId = $this->getDefaultStoreId(); $write->delete($table, array( 'attribute_id = ?' => $attribute->getAttributeId(), diff --git a/app/code/core/Mage/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.16-1.6.0.0.17.php b/app/code/core/Mage/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.16-1.6.0.0.17.php index b70409fbc1c66..d6b6e780592ad 100644 --- a/app/code/core/Mage/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.16-1.6.0.0.17.php +++ b/app/code/core/Mage/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.16-1.6.0.0.17.php @@ -24,6 +24,9 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** Bug MAGETWO-3318 Segmentation Fault */ +return; + /** @var $this Mage_Catalog_Model_Resource_Setup */ /** @var $installer Mage_Core_Model_Resource_Setup_Migration */ diff --git a/app/code/core/Mage/Catalog/etc/system.xml b/app/code/core/Mage/Catalog/etc/system.xml index 4b563a99eb68e..01bb855893a0d 100644 --- a/app/code/core/Mage/Catalog/etc/system.xml +++ b/app/code/core/Mage/Catalog/etc/system.xml @@ -276,6 +276,7 @@ 1 0 0 + 1 diff --git a/app/code/core/Mage/CatalogRule/data/catalogrule_setup/data-upgrade-1.6.0.3-1.6.0.4.php b/app/code/core/Mage/CatalogRule/data/catalogrule_setup/data-upgrade-1.6.0.3-1.6.0.4.php index 0782b76065638..150af420663a3 100644 --- a/app/code/core/Mage/CatalogRule/data/catalogrule_setup/data-upgrade-1.6.0.3-1.6.0.4.php +++ b/app/code/core/Mage/CatalogRule/data/catalogrule_setup/data-upgrade-1.6.0.3-1.6.0.4.php @@ -24,6 +24,9 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** Bug MAGETWO-3318 Segmentation Fault */ +return; + /** @var $installer Mage_Core_Model_Resource_Setup_Migration */ $installer = Mage::getResourceModel('Mage_Core_Model_Resource_Setup_Migration', 'core_setup'); $installer->startSetup(); diff --git a/app/code/core/Mage/Cms/Model/Resource/Block.php b/app/code/core/Mage/Cms/Model/Resource/Block.php index 5f77a3e3b35f9..bcb0409954dda 100755 --- a/app/code/core/Mage/Cms/Model/Resource/Block.php +++ b/app/code/core/Mage/Cms/Model/Resource/Block.php @@ -193,7 +193,7 @@ protected function _getLoadSelect($field, $value, $object) */ public function getIsUniqueBlockToStores(Mage_Core_Model_Abstract $object) { - if (Mage::app()->isSingleStoreMode()) { + if (Mage::app()->hasSingleStore()) { $stores = array(Mage_Core_Model_App::ADMIN_STORE_ID); } else { $stores = (array)$object->getData('stores'); diff --git a/app/code/core/Mage/Cms/Model/Resource/Page.php b/app/code/core/Mage/Cms/Model/Resource/Page.php index 3d38d8db22e58..57c4c62c86b7b 100755 --- a/app/code/core/Mage/Cms/Model/Resource/Page.php +++ b/app/code/core/Mage/Cms/Model/Resource/Page.php @@ -246,7 +246,7 @@ protected function _getLoadByIdentifierSelect($identifier, $store, $isActive = n */ public function getIsUniquePageToStores(Mage_Core_Model_Abstract $object) { - if (Mage::app()->isSingleStoreMode() || !$object->hasStores()) { + if (Mage::app()->hasSingleStore() || !$object->hasStores()) { $stores = array(Mage_Core_Model_App::ADMIN_STORE_ID); } else { $stores = (array)$object->getData('stores'); diff --git a/app/code/core/Mage/Cms/data/cms_setup/data-upgrade-1.6.0.0.2-1.6.0.0.3.php b/app/code/core/Mage/Cms/data/cms_setup/data-upgrade-1.6.0.0.2-1.6.0.0.3.php index fcdcb606a1fe0..8fbcd4e794e69 100644 --- a/app/code/core/Mage/Cms/data/cms_setup/data-upgrade-1.6.0.0.2-1.6.0.0.3.php +++ b/app/code/core/Mage/Cms/data/cms_setup/data-upgrade-1.6.0.0.2-1.6.0.0.3.php @@ -24,6 +24,9 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** Bug MAGETWO-3318 Segmentation Fault */ +return; + /** @var $installer Mage_Core_Model_Resource_Setup_Migration */ $installer = Mage::getResourceModel('Mage_Core_Model_Resource_Setup_Migration', 'core_setup'); $installer->startSetup(); diff --git a/app/code/core/Mage/Core/Helper/Data.php b/app/code/core/Mage/Core/Helper/Data.php index af14a4b960ca7..2295e630252c4 100644 --- a/app/code/core/Mage/Core/Helper/Data.php +++ b/app/code/core/Mage/Core/Helper/Data.php @@ -57,6 +57,8 @@ class Mage_Core_Helper_Data extends Mage_Core_Helper_Abstract const XML_PATH_MERCHANT_VAT_NUMBER = 'general/store_information/merchant_vat_number'; const XML_PATH_EU_COUNTRIES_LIST = 'general/country/eu_countries'; + const XML_PATH_SINGLE_STORE_MODE_ENABLED = 'general/single_store_mode/enabled'; + /** * Const for correct dividing decimal values */ @@ -819,4 +821,17 @@ public function isStaticFilesSigned() { return (bool) Mage::getStoreConfig(self::XML_PATH_STATIC_FILE_SIGNATURE); } + + /** + * Check if Single-Store mode is enabled in configuration + * + * This flag only shows that admin does not want to show certain UI components at backend (like store switchers etc) + * if Magento has only one store view but it does not check the store view collection + * + * @return bool + */ + public function isSingleStoreModeEnabled() + { + return (bool) Mage::getStoreConfig(self::XML_PATH_SINGLE_STORE_MODE_ENABLED); + } } diff --git a/app/code/core/Mage/Core/Model/App.php b/app/code/core/Mage/Core/Model/App.php index 1b4d7370c9257..94c3cc9588148 100644 --- a/app/code/core/Mage/Core/Model/App.php +++ b/app/code/core/Mage/Core/Model/App.php @@ -171,11 +171,11 @@ class Mage_Core_Model_App protected $_stores = array(); /** - * is a single store mode + * Flag that shows that system has only one store view * * @var bool */ - protected $_isSingleStore; + protected $_hasSingleStore; /** * @var bool @@ -342,7 +342,7 @@ public function run($params) Magento_Profiler::stop('init'); - if ($this->_cache->processRequest()) { + if ($this->_cache->processRequest($this->getResponse())) { $this->getResponse()->sendResponse(); } else { Magento_Profiler::start('init'); @@ -629,9 +629,9 @@ protected function _initStores() ->initCache($this->getCache(), 'app', array(Mage_Core_Model_Store::CACHE_TAG)) ->setLoadDefault(true); - $this->_isSingleStore = false; + $this->_hasSingleStore = false; if ($this->_isSingleStoreAllowed) { - $this->_isSingleStore = $storeCollection->count() < 3; + $this->_hasSingleStore = $storeCollection->count() < 3; } $websiteStores = array(); @@ -688,16 +688,26 @@ protected function _initStores() } /** - * Is single Store mode (only one store without default) + * Check if system is run in the single store mode * * @return bool */ public function isSingleStoreMode() + { + return $this->hasSingleStore() && Mage::helper('Mage_Core_Helper_Data')->isSingleStoreModeEnabled(); + } + + /** + * Check if store has only one store view + * + * @return bool + */ + public function hasSingleStore() { if (!Mage::isInstalled()) { return false; } - return $this->_isSingleStore; + return $this->_hasSingleStore; } /** @@ -824,7 +834,7 @@ public function getStore($id = null) return $this->_getDefaultStore(); } - if ($id === true && $this->isSingleStoreMode()) { + if ($id === true && $this->hasSingleStore()) { return $this->_store; } diff --git a/app/code/core/Mage/Core/Model/Cache.php b/app/code/core/Mage/Core/Model/Cache.php index 301c22607a0ff..f7a789a2c445e 100644 --- a/app/code/core/Mage/Core/Model/Cache.php +++ b/app/code/core/Mage/Core/Model/Cache.php @@ -36,6 +36,16 @@ class Mage_Core_Model_Cache const INVALIDATED_TYPES = 'core_cache_invalidate'; const XML_PATH_TYPES = 'global/cache/types'; + /** + * @var Mage_Core_Model_Config + */ + protected $_config; + + /** + * @var Mage_Core_Helper_Abstract + */ + protected $_helper; + /** * @var string */ @@ -104,7 +114,10 @@ class Mage_Core_Model_Cache */ public function __construct(array $options = array()) { - $this->_defaultBackendOptions['cache_dir'] = Mage::getBaseDir('cache'); + $this->_config = isset($options['config']) ? $options['config'] : Mage::getConfig(); + $this->_helper = isset($options['helper']) ? $options['helper'] : Mage::helper('Mage_Core_Helper_Data'); + + $this->_defaultBackendOptions['cache_dir'] = $this->_config->getOptions()->getDir('cache'); /** * Initialize id prefix */ @@ -113,13 +126,13 @@ public function __construct(array $options = array()) $this->_idPrefix = $options['prefix']; } if (empty($this->_idPrefix)) { - $this->_idPrefix = substr(md5(Mage::getConfig()->getOptions()->getEtcDir()), 0, 3).'_'; + $this->_idPrefix = substr(md5($this->_config->getOptions()->getEtcDir()), 0, 3).'_'; } $backend = $this->_getBackendOptions($options); $frontend = $this->_getFrontendOptions($options); - $this->_frontend = Zend_Cache::factory('Varien_Cache_Core', $backend['type'], $frontend, $backend['options'], + $this->_frontend = Zend_Cache::factory($frontend['type'], $backend['type'], $frontend, $backend['options'], true, true, true ); @@ -305,6 +318,7 @@ protected function _getFrontendOptions(array $cacheOptions) $options['automatic_cleaning_factor'] = 0; } $options['cache_id_prefix'] = $this->_idPrefix; + $options['type'] = isset($cacheOptions['frontend']) ? $cacheOptions['frontend'] : 'Varien_Cache_Core'; return $options; } @@ -463,7 +477,7 @@ protected function _initOptions() $this->_allowedCacheOptions = unserialize($options); } - if (Mage::getConfig()->getOptions()->getData('global_ban_use_cache')) { + if ($this->_config->getOptions()->getData('global_ban_use_cache')) { foreach ($this->_allowedCacheOptions as $key => $val) { $this->_allowedCacheOptions[$key] = false; } @@ -541,7 +555,7 @@ public function allowUse($typeCode) public function getTagsByType($type) { $path = self::XML_PATH_TYPES.'/'.$type.'/tags'; - $tagsConfig = Mage::getConfig()->getNode($path); + $tagsConfig = $this->_config->getNode($path); if ($tagsConfig) { $tags = (string) $tagsConfig; $tags = explode(',', $tags); @@ -559,13 +573,13 @@ public function getTagsByType($type) public function getTypes() { $types = array(); - $config = Mage::getConfig()->getNode(self::XML_PATH_TYPES); + $config = $this->_config->getNode(self::XML_PATH_TYPES); if ($config) { foreach ($config->children() as $type=>$node) { $types[$type] = new Varien_Object(array( 'id' => $type, - 'cache_type' => Mage::helper('Mage_Core_Helper_Data')->__((string)$node->label), - 'description' => Mage::helper('Mage_Core_Helper_Data')->__((string)$node->description), + 'cache_type' => $this->_helper->__((string)$node->label), + 'description' => $this->_helper->__((string)$node->description), 'tags' => strtoupper((string) $node->tags), 'status' => (int)$this->canUse($type), )); @@ -661,9 +675,10 @@ public function cleanType($typeCode) /** * Try to get response body from cache storage with predefined processors * + * @param Zend_Controller_Response_Abstract $response * @return bool */ - public function processRequest() + public function processRequest(Zend_Controller_Response_Abstract $response) { if (empty($this->_requestProcessors)) { return false; @@ -678,7 +693,7 @@ public function processRequest() } if ($content) { - Mage::app()->getResponse()->appendBody($content); + $response->appendBody($content); return true; } return false; @@ -686,10 +701,15 @@ public function processRequest() /** * Get request processor object + * + * @param string|object $processor Class or object + * @return object */ protected function _getProcessor($processor) { - $processor = new $processor; + if (!is_object($processor)) { + $processor = new $processor; + } return $processor; } } diff --git a/app/code/core/Mage/Core/Model/Config.php b/app/code/core/Mage/Core/Model/Config.php index 5601fce66f79a..2040fdbe8df24 100644 --- a/app/code/core/Mage/Core/Model/Config.php +++ b/app/code/core/Mage/Core/Model/Config.php @@ -217,9 +217,13 @@ class Mage_Core_Model_Config extends Mage_Core_Model_Config_Base public function __construct($sourceData=null) { $this->setCacheId('config_global'); - $this->_options = new Mage_Core_Model_Config_Options($sourceData); - $this->_prototype = new Mage_Core_Model_Config_Base(); - $this->_cacheChecksum = null; + $options = $sourceData; + if (!is_array($options)) { + $options = array($options); + } + $this->_options = new Mage_Core_Model_Config_Options($options); + $this->_prototype = new Mage_Core_Model_Config_Base(); + $this->_cacheChecksum = null; parent::__construct($sourceData); } diff --git a/app/code/core/Mage/Core/Model/Config/Options.php b/app/code/core/Mage/Core/Model/Config/Options.php index e4526d7a8bc06..77bd7b66372f9 100644 --- a/app/code/core/Mage/Core/Model/Config/Options.php +++ b/app/code/core/Mage/Core/Model/Config/Options.php @@ -54,13 +54,24 @@ class Mage_Core_Model_Config_Options extends Varien_Object */ protected $_dirExists = array(); + /** + * Flag cache for existing or already created directories + * + * @var array + */ + protected $_io; + /** * Initialize default values of the options + * + * @param array $data */ - public function __construct() + public function __construct(array $data = array()) { - parent::__construct(); - $appRoot= Mage::getRoot(); + $this->_io = isset($data['io']) ? $data['io'] : new Varien_Io_File(); + unset ($data['io']); + parent::__construct($data); + $appRoot = isset($data['app_dir']) ? $data['app_dir'] : Mage::getRoot(); $root = dirname($appRoot); $this->_data['app_dir'] = $appRoot; @@ -213,11 +224,12 @@ public function getSysTmpDir() * Var folder paths getter * * @return string + * @throws Mage_Core_Exception */ public function getVarDir() { $dir = isset($this->_data['var_dir']) ? $this->_data['var_dir'] - : $this->_data['base_dir'] . DS . self::VAR_DIRECTORY; + : $this->_data['base_dir'] . DIRECTORY_SEPARATOR . self::VAR_DIRECTORY; if (!$this->createDirIfNotExists($dir)) { $dir = $this->getSysTmpDir() . DIRECTORY_SEPARATOR . 'magento' . DIRECTORY_SEPARATOR . 'var'; if (!$this->createDirIfNotExists($dir)) { @@ -315,19 +327,10 @@ public function createDirIfNotExists($dir) if (!empty($this->_dirExists[$dir])) { return true; } - if (file_exists($dir)) { - if (!is_dir($dir)) { - return false; - } - if (!is_dir_writeable($dir)) { - return false; - } - } else { - $oldUmask = umask(0); - if (!@mkdir($dir, 0777, true)) { - return false; - } - umask($oldUmask); + try { + $this->_io->checkAndCreateFolder($dir); + } catch (Exception $e) { + return false; } $this->_dirExists[$dir] = true; return true; diff --git a/app/code/core/Mage/Core/Model/Resource/Db/Collection/Abstract.php b/app/code/core/Mage/Core/Model/Resource/Db/Collection/Abstract.php index 8f60118e3a576..9c0d65582aeff 100644 --- a/app/code/core/Mage/Core/Model/Resource/Db/Collection/Abstract.php +++ b/app/code/core/Mage/Core/Model/Resource/Db/Collection/Abstract.php @@ -496,7 +496,7 @@ public function getAllIds() $idsSelect->reset(Zend_Db_Select::COLUMNS); $idsSelect->columns($this->getResource()->getIdFieldName(), 'main_table'); - return $this->getConnection()->fetchCol($idsSelect); + return $this->getConnection()->fetchCol($idsSelect, $this->_bindParams); } public function getData() diff --git a/app/code/core/Mage/Core/Model/Resource/Setup/Migration.php b/app/code/core/Mage/Core/Model/Resource/Setup/Migration.php index 3e2211a89d06f..a54d36b617c05 100644 --- a/app/code/core/Mage/Core/Model/Resource/Setup/Migration.php +++ b/app/code/core/Mage/Core/Model/Resource/Setup/Migration.php @@ -292,7 +292,7 @@ protected function _getRowsCount($tableName, $fieldName, $additionalWhere = '') $adapter = $this->getConnection(); $query = $adapter->select() - ->from($adapter->getTableName($tableName), array('rows_count' => new Zend_Db_Expr('COUNT(*)'))) + ->from($this->getTable($tableName), array('rows_count' => new Zend_Db_Expr('COUNT(*)'))) ->where($fieldName . ' IS NOT NULL'); if (!empty($additionalWhere)) { @@ -362,7 +362,7 @@ protected function _updateRowsData($tableName, $fieldName, array $fieldReplaceme $where[$adapter->quoteIdentifier($whereFieldName) . ' = ?'] = $value; } $adapter->update( - $adapter->getTableName($tableName), + $this->getTable($tableName), array($fieldName => $fieldReplacement['to']), $where ); @@ -387,7 +387,7 @@ protected function _getTableData($tableName, $fieldName, array $fieldsToSelect, $adapter = $this->getConnection(); $query = $adapter->select() - ->from($adapter->getTableName($tableName), $fieldsToSelect) + ->from($this->getTable($tableName), $fieldsToSelect) ->where($fieldName . ' IS NOT NULL'); if (!empty($additionalWhere)) { diff --git a/app/code/core/Mage/Core/Model/Url.php b/app/code/core/Mage/Core/Model/Url.php index db8334862dcce..5ab51faf4e8d0 100644 --- a/app/code/core/Mage/Core/Model/Url.php +++ b/app/code/core/Mage/Core/Model/Url.php @@ -664,7 +664,7 @@ public function setRouteParams(array $data, $unsetOldParams = true) if (isset($data['_store_to_url']) && (bool)$data['_store_to_url'] === true) { if (!Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_STORE_IN_URL, $this->getStore()) - && !Mage::app()->isSingleStoreMode() + && !Mage::app()->hasSingleStore() ) { $this->setQueryParam('___store', $this->getStore()->getCode()); } diff --git a/app/code/core/Mage/Core/data/core_setup/data-upgrade-1.6.0.3-1.6.0.4.php b/app/code/core/Mage/Core/data/core_setup/data-upgrade-1.6.0.3-1.6.0.4.php index 36e88c5accd4a..6bd1a5cd1e477 100644 --- a/app/code/core/Mage/Core/data/core_setup/data-upgrade-1.6.0.3-1.6.0.4.php +++ b/app/code/core/Mage/Core/data/core_setup/data-upgrade-1.6.0.3-1.6.0.4.php @@ -24,6 +24,9 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** Bug MAGETWO-3318 Segmentation Fault */ +return; + /** @var $installer Mage_Core_Model_Resource_Setup_Migration */ $installer = Mage::getResourceModel('Mage_Core_Model_Resource_Setup_Migration', 'core_setup'); $installer->startSetup(); diff --git a/app/code/core/Mage/Core/etc/config.xml b/app/code/core/Mage/Core/etc/config.xml index 32ca68e3a69d3..0ecb7be29bf0c 100644 --- a/app/code/core/Mage/Core/etc/config.xml +++ b/app/code/core/Mage/Core/etc/config.xml @@ -338,6 +338,9 @@ + + 0 + diff --git a/app/code/core/Mage/Core/etc/system.xml b/app/code/core/Mage/Core/etc/system.xml index 7be3d7970174e..3f9c66c40e191 100644 --- a/app/code/core/Mage/Core/etc/system.xml +++ b/app/code/core/Mage/Core/etc/system.xml @@ -757,6 +757,26 @@ + + + text + 150 + 1 + 0 + 0 + + + + select + Mage_Adminhtml_Model_System_Config_Source_Yesno + 10 + 1 + 0 + 0 + This setting will not be taken into account if system has more than one store view. + + + diff --git a/app/code/core/Mage/Customer/data/customer_setup/data-upgrade-1.6.2.0.1-1.6.2.0.2.php b/app/code/core/Mage/Customer/data/customer_setup/data-upgrade-1.6.2.0.1-1.6.2.0.2.php index 1829ab6adc0fd..7e1eb9cf39976 100644 --- a/app/code/core/Mage/Customer/data/customer_setup/data-upgrade-1.6.2.0.1-1.6.2.0.2.php +++ b/app/code/core/Mage/Customer/data/customer_setup/data-upgrade-1.6.2.0.1-1.6.2.0.2.php @@ -24,6 +24,9 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** Bug MAGETWO-3318 Segmentation Fault */ +return; + /** @var $installer Mage_Core_Model_Resource_Setup_Migration */ $installer = Mage::getResourceModel('Mage_Core_Model_Resource_Setup_Migration', 'core_setup'); $installer->startSetup(); diff --git a/app/code/core/Mage/Customer/etc/system.xml b/app/code/core/Mage/Customer/etc/system.xml index 3a83eadb10e62..6ce36278dba59 100644 --- a/app/code/core/Mage/Customer/etc/system.xml +++ b/app/code/core/Mage/Customer/etc/system.xml @@ -50,6 +50,7 @@ 1 0 0 + 1 diff --git a/app/code/core/Mage/DesignEditor/Block/Adminhtml/Launcher/Form.php b/app/code/core/Mage/DesignEditor/Block/Adminhtml/Launcher/Form.php index 286889a126e96..85cc22984bb0f 100644 --- a/app/code/core/Mage/DesignEditor/Block/Adminhtml/Launcher/Form.php +++ b/app/code/core/Mage/DesignEditor/Block/Adminhtml/Launcher/Form.php @@ -42,7 +42,7 @@ protected function _prepareForm() 'target' => '_blank' )); - if (!Mage::app()->isSingleStoreMode()) { + if (!Mage::app()->hasSingleStore()) { $fieldset = $form->addFieldset( 'base_fieldset', array('legend' => Mage::helper('Mage_DesignEditor_Helper_Data')->__('Context Information')) diff --git a/app/code/core/Mage/DesignEditor/Block/Toolbar/Buttons.php b/app/code/core/Mage/DesignEditor/Block/Toolbar/Buttons.php index f3ce386f2e4f4..db09ca2e5a9cc 100644 --- a/app/code/core/Mage/DesignEditor/Block/Toolbar/Buttons.php +++ b/app/code/core/Mage/DesignEditor/Block/Toolbar/Buttons.php @@ -46,7 +46,7 @@ public function getExitUrl() */ public function getViewLayoutUrl() { - return $this->getUrl('design/editor/compactXml'); + return $this->getUrl('design/editor/getLayoutUpdate'); } /** diff --git a/app/code/core/Mage/DesignEditor/Model/History/Manager/Adapter.php b/app/code/core/Mage/DesignEditor/Model/Change/Collection.php similarity index 55% rename from app/code/core/Mage/DesignEditor/Model/History/Manager/Adapter.php rename to app/code/core/Mage/DesignEditor/Model/Change/Collection.php index b421dfe24b559..a1dbf793d04df 100644 --- a/app/code/core/Mage/DesignEditor/Model/History/Manager/Adapter.php +++ b/app/code/core/Mage/DesignEditor/Model/Change/Collection.php @@ -25,34 +25,40 @@ */ /** - * Visual design editor manager adapter + * Visual design editor changes collection */ -class Mage_DesignEditor_Model_History_Manager_Adapter extends Mage_Core_Model_Abstract +class Mage_DesignEditor_Model_Change_Collection extends Varien_Data_Collection { /** - * Layout change type + * Collection item class + * + * @var string */ - const CHANGE_TYPE_LAYOUT = 'layout'; + protected $_itemObjectClass = 'Mage_DesignEditor_Model_ChangeAbstract'; + + /** + * Get collection item class + * + * @return string + */ + public function getItemClass() + { + return $this->_itemObjectClass; + } /** - * Get change by type + * Get array of changes suited for encoding to JSON * - * @static - * @throws Mage_DesignEditor_Exception - * @param string $adapter - * @return Mage_DesignEditor_Model_History_Manager_Adapter_Abstract + * @param array $fields + * @return array */ - public static function factory($adapter) + public function toArray($fields = array()) { - switch ($adapter) { - case self::CHANGE_TYPE_LAYOUT: - return Mage::getModel('Mage_DesignEditor_Model_History_Manager_Adapter_Layout'); - break; - default: - throw new Mage_DesignEditor_Exception( - Mage::helper('Mage_DesignEditor_Helper_Data')->__('Change type %s is not exist.', $adapter) - ); - break; + $items = array(); + /** @var $item Mage_DesignEditor_Model_ChangeAbstract */ + foreach ($this as $item) { + $items[] = $item->toArray($fields); } + return $items; } } diff --git a/app/code/core/Mage/DesignEditor/Model/Change/Factory.php b/app/code/core/Mage/DesignEditor/Model/Change/Factory.php new file mode 100644 index 0000000000000..34f08262a19b4 --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/Change/Factory.php @@ -0,0 +1,115 @@ +getType(); + } + + if (!$type) { + throw new Magento_Exception('Impossible to get change type'); + } + + return $type; + } + + /** + * Get change layout directive + * + * @param Varien_Object|array $change + * @throws Magento_Exception + * @return string + */ + protected static function _getChangeLayoutDirective($change) + { + $directive = null; + if (is_array($change)) { + $directive = isset($change['action_name']) ? $change['action_name'] : null; + } elseif ($change instanceof Varien_Object) { + $directive = $change->getActionName(); + } + + if (!$directive) { + throw new Magento_Exception('Impossible to get layout change directive'); + } + + return $directive; + } +} diff --git a/app/code/core/Mage/DesignEditor/Model/History/Manager.php b/app/code/core/Mage/DesignEditor/Model/Change/Layout/Move.php similarity index 51% rename from app/code/core/Mage/DesignEditor/Model/History/Manager.php rename to app/code/core/Mage/DesignEditor/Model/Change/Layout/Move.php index 1e1384270e762..18e4bbc27078b 100644 --- a/app/code/core/Mage/DesignEditor/Model/History/Manager.php +++ b/app/code/core/Mage/DesignEditor/Model/Change/Layout/Move.php @@ -25,59 +25,52 @@ */ /** - * Visual design editor manager model + * Layout move change model */ -class Mage_DesignEditor_Model_History_Manager extends Mage_Core_Model_Abstract +class Mage_DesignEditor_Model_Change_Layout_Move extends Mage_DesignEditor_Model_Change_LayoutAbstract { /** - * Change collection - * - * @var null|Mage_DesignEditor_Model_History_Manager_Collection + * Layout directive associated with this change */ - protected $_changeCollection; + const LAYOUT_DIRECTIVE_MOVE = 'move'; /** - * Add change + * Get required data fields for move layout change * - * @param array $change - * @return Mage_DesignEditor_Model_History_Manager + * @return array */ - public function addChange($change) + protected function _getRequiredFields() { - $this->_getChangeCollection()->addElement($change); - return $this; + $requiredFields = parent::_getRequiredFields(); + $requiredFields[] = 'destination_container'; + $requiredFields[] = 'destination_order'; + $requiredFields[] = 'origin_container'; + $requiredFields[] = 'origin_order'; + + return $requiredFields; } /** - * Get history log + * Get data to render layout update directive * * @return array */ - public function getHistoryLog() + public function getLayoutUpdateData() { - return $this->_getChangeCollection()->toHistoryLog(); + return array( + 'element' => $this->getData('element_name'), + 'after' => $this->getData('destination_order'), + 'destination' => $this->getData('destination_container') + ); } /** - * Get xml changes + * Get layout update directive for given layout change * * @return string */ - public function getXml() - { - return $this->_getChangeCollection()->toXml(); - } - - /** - * Get change collection - * - * @return Mage_DesignEditor_Model_History_Manager_Collection - */ - protected function _getChangeCollection() + public function getLayoutDirective() { - if ($this->_changeCollection == null) { - $this->_changeCollection = Mage::getModel('Mage_DesignEditor_Model_History_Manager_Collection'); - } - return $this->_changeCollection; + return self::LAYOUT_DIRECTIVE_MOVE; } } diff --git a/app/code/core/Mage/DesignEditor/Model/Change/Layout/Remove.php b/app/code/core/Mage/DesignEditor/Model/Change/Layout/Remove.php new file mode 100644 index 0000000000000..c24ca20f62286 --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/Change/Layout/Remove.php @@ -0,0 +1,56 @@ + $this->getData('element_name')); + } + + /** + * Get layout update directive for given layout change + * + * @return string + */ + public function getLayoutDirective() + { + return self::LAYOUT_DIRECTIVE_REMOVE; + } +} diff --git a/app/code/core/Mage/DesignEditor/Model/Change/LayoutAbstract.php b/app/code/core/Mage/DesignEditor/Model/Change/LayoutAbstract.php new file mode 100644 index 0000000000000..d9c4989fdc525 --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/Change/LayoutAbstract.php @@ -0,0 +1,82 @@ +_getRequiredFields() as $field) { + if ($this->getData($field) === null) { + $errors[] = Mage::helper('Mage_DesignEditor_Helper_Data')->__('Invalid "%s" data', $field); + } + } + + if (count($errors)) { + Mage::throwException(join("\n", $errors)); + } + return $this; + } + + /** + * Get data to render layout update directive + * + * @abstract + * @return array + */ + abstract public function getLayoutUpdateData(); + + /** + * Get required data fields for layout change + * + * @return array + */ + protected function _getRequiredFields() + { + return array('type', 'handle', 'element_name', 'action_name'); + } + + /** + * Get layout update directive for given layout change + * + * @return string + */ + abstract public function getLayoutDirective(); +} diff --git a/app/code/core/Mage/DesignEditor/Model/ChangeAbstract.php b/app/code/core/Mage/DesignEditor/Model/ChangeAbstract.php new file mode 100644 index 0000000000000..1fa6c7c5e342a --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/ChangeAbstract.php @@ -0,0 +1,51 @@ +_validate(); + } + + /** + * Signature of validation method to implement in subclasses + * + * @abstract + * @throws Magento_Exception + * @return Mage_DesignEditor_Model_ChangeAbstract + */ + abstract protected function _validate(); +} diff --git a/app/code/core/Mage/DesignEditor/Model/History.php b/app/code/core/Mage/DesignEditor/Model/History.php index 381429137c2d7..d21d2c80e8ee8 100644 --- a/app/code/core/Mage/DesignEditor/Model/History.php +++ b/app/code/core/Mage/DesignEditor/Model/History.php @@ -27,117 +27,134 @@ /** * Visual Design Editor history model */ -class Mage_DesignEditor_Model_History extends Mage_Backend_Model_Auth_Session +class Mage_DesignEditor_Model_History { /** - * Required change fields - * - * @var array + * Base class for all change instances */ - protected $_requiredFields = array('handle', 'change_type', 'element_name', 'action_name'); + const BASE_CHANGE_CLASS = 'Mage_DesignEditor_Model_ChangeAbstract'; + /** + * Changes collection class + */ + const CHANGE_COLLECTION_CLASS = 'Mage_DesignEditor_Model_Change_Collection'; /** - * Change log + * Internal collection of changes * - * @var array + * @var Mage_DesignEditor_Model_Change_Collection */ - protected $_changeLog = array(); + protected $_collection; /** - * Manager model - * - * @var null|Mage_DesignEditor_Model_History_Manager + * Initialize empty internal collection */ - protected $_managerModel; + public function __construct() + { + $this->_initCollection(); + } /** - * Get compact log + * Initialize changes collection * - * @return array + * @return Mage_DesignEditor_Model_History */ - public function getCompactLog() + protected function _initCollection() { - return $this->_compactLog()->_getManagerModel()->getHistoryLog(); + $this->_collection = Mage::getModel(self::CHANGE_COLLECTION_CLASS); + return $this; } /** - * Get compact xml + * Get change instance * - * @return string + * @param array $data + * @return Mage_DesignEditor_Model_ChangeAbstract */ - public function getCompactXml() + protected function _getChangeItem($data) { - return $this->_compactLog()->_getManagerModel()->getXml(); + return Mage_DesignEditor_Model_Change_Factory::getInstance($data); } /** - * Set change log + * Load changes from DB. To be able to effectively compact changes they should be all loaded first. * - * @param array $changeLog * @return Mage_DesignEditor_Model_History */ - public function setChangeLog($changeLog) + public function loadChanges() { - $this->_changeLog = $changeLog; return $this; } /** - * Compact log + * Add change to internal collection * + * @param Mage_DesignEditor_Model_ChangeAbstract|Varien_Object|array $item * @return Mage_DesignEditor_Model_History */ - protected function _compactLog() + public function addChange($item) { - $managerModel = $this->_getManagerModel(); - foreach ($this->_getChangeLog() as $change) { - $this->_validateChange($change); - $managerModel->addChange($change); + $baseChangeClass = self::BASE_CHANGE_CLASS; + if (!$item instanceof $baseChangeClass) { + $item = $this->_getChangeItem($item); } + $this->_collection->addItem($item); return $this; } /** - * Get change log + * Add changes to internal collection * - * @return array + * @param array|Traversable $changes + * @return Mage_DesignEditor_Model_History */ - protected function _getChangeLog() + public function addChanges($changes) { - return $this->_changeLog; + foreach ($changes as $change) { + $this->addChange($change); + } + + return $this; } /** - * Get change model + * Set changes to internal collection * - * @return Mage_DesignEditor_Model_History_Manager + * @param array|Traversable $changes + * @return Mage_DesignEditor_Model_History */ - protected function _getManagerModel() + public function setChanges($changes) { - if ($this->_managerModel == null) { - $this->_managerModel = Mage::getModel('Mage_DesignEditor_Model_History_Manager'); + $collectionClass = self::CHANGE_COLLECTION_CLASS; + if ($changes instanceof $collectionClass) { + $this->_collection = $changes; + } else { + $this->_initCollection(); + $this->addChanges($changes); } - return $this->_managerModel; + + return $this; } /** - * Validate change + * Get changes collection * - * @throws Mage_DesignEditor_Exception - * @param array $change - * @return Mage_DesignEditor_Model_History + * @return Mage_DesignEditor_Model_Change_Collection */ - protected function _validateChange($change) + public function getChanges() { - foreach ($this->_requiredFields as $field) { - if (!is_array($change) || !array_key_exists($field, $change) || empty($change[$field])) { - throw new Mage_DesignEditor_Exception( - Mage::helper('Mage_DesignEditor_Helper_Data')->__('Invalid change data') - ); - } - } - return $this; + return $this->_collection; + } + + /** + * Render all types of output + * + * @param Mage_DesignEditor_Model_History_RendererInterface $renderer + * @return Mage_DesignEditor_Model_History_RendererInterface + */ + public function output(Mage_DesignEditor_Model_History_RendererInterface $renderer) + { + return $renderer->render($this->_collection); } } diff --git a/app/code/core/Mage/DesignEditor/Model/History/Compact.php b/app/code/core/Mage/DesignEditor/Model/History/Compact.php new file mode 100644 index 0000000000000..dda3011265af0 --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/History/Compact.php @@ -0,0 +1,95 @@ +getItemClass(); + if (!$itemType == 'Mage_DesignEditor_Model_ChangeAbstract') { + Mage::throwException( + Mage::helper('Mage_DesignEditor_Helper_Data')->__('Invalid collection items\' type "%s"', $itemType) + ); + } + + /** @var $model Mage_DesignEditor_Model_History_CompactInterface */ + foreach ($this->_getCompactModels() as $model) { + $model->compact($collection); + } + + return $this; + } + + /** + * Get compaction strategies array ordered to minimize performance impact + * + * @return array + */ + protected function _getCompactModels() + { + if (!$this->_compactModels) { + foreach ($this->_getConfig() as $class) { + $this->_compactModels[] = Mage::getModel($class); + } + } + + return $this->_compactModels; + } + + /** + * Get configuration for compact + * + * @return array + */ + protected function _getConfig() + { + return $this->_config; + } +} diff --git a/app/code/core/Mage/DesignEditor/Model/History/Compact/Diff.php b/app/code/core/Mage/DesignEditor/Model/History/Compact/Diff.php new file mode 100644 index 0000000000000..9a381a073494c --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/History/Compact/Diff.php @@ -0,0 +1,44 @@ +_scheduleActions()->_compactLayoutChanges(); + } + + /** + * Schedule layout actions + * + * @return Mage_DesignEditor_Model_History_Compact_Layout + */ + protected function _scheduleActions() + { + /** @var $change Mage_DesignEditor_Model_Change_LayoutAbstract */ + foreach ($this->getChangesCollection() as $changeKey => $change) { + if (!$change instanceof Mage_DesignEditor_Model_Change_LayoutAbstract) { + continue; + } + switch ($change->getData('action_name')) { + case Mage_DesignEditor_Model_Change_Layout_Remove::LAYOUT_DIRECTIVE_REMOVE: + $this->_scheduledRemoves[$change->getData('element_name')][] = array( + 'collection_key' => $changeKey + ); + break; + + case Mage_DesignEditor_Model_Change_Layout_Move::LAYOUT_DIRECTIVE_MOVE: + $this->_scheduledMoves[$change->getData('element_name')][] = array( + 'collection_key' => $changeKey, + 'change' => $change + ); + break; + + default: + break; + } + } + return $this; + } + + /** + * Compact layout changes + * + * @return Mage_DesignEditor_Model_History_Compact_Layout + */ + protected function _compactLayoutChanges() + { + return $this->_compactRemoves()->_compactMoves(); + } + + /** + * Compact remove layout directives + * + * @return Mage_DesignEditor_Model_History_Compact_Layout + */ + protected function _compactRemoves() + { + foreach ($this->_scheduledRemoves as $itemName => $removeItem) { + $arrayToRemove = array(); + if (!empty($this->_scheduledMoves[$itemName])) { + $arrayToRemove = $this->_scheduledMoves[$itemName]; + } + $this->_removeElements(array_merge($arrayToRemove, array_slice($removeItem, 0, count($removeItem) - 1))); + } + return $this; + } + + /** + * Compact move layout directives + * + * @return Mage_DesignEditor_Model_History_Compact_Layout + */ + protected function _compactMoves() + { + foreach ($this->_scheduledMoves as $moveItem) { + if (count($moveItem) === 1) { + continue; + } + $arrayToRemove = array(); + $lastMove = array_pop($moveItem); + $lastMoveElement = $lastMove['change']; + + $firstMove = $moveItem[0]['change']; + $originContainer = $firstMove->getData('origin_container'); + $originOrder = $firstMove->getData('origin_order'); + $hasContainerChanged = $lastMoveElement->getData('destination_container') != $originContainer; + if (!$hasContainerChanged) { + $hasOrderChanged = $lastMoveElement->getData('destination_order') != $originOrder; + if (!$hasOrderChanged) { + $arrayToRemove = array($lastMove); + } + } + + $this->_removeElements(array_merge($arrayToRemove, $moveItem)); + } + return $this; + } + + /** + * Remove array of elements from change collection + * + * @param array $elements + * @return Mage_DesignEditor_Model_History_Compact_Layout + */ + protected function _removeElements($elements) + { + foreach ($elements as $element) { + $this->getChangesCollection()->removeItemByKey($element['collection_key']); + } + return $this; + } +} diff --git a/app/code/core/Mage/DesignEditor/Model/History/CompactAbstract.php b/app/code/core/Mage/DesignEditor/Model/History/CompactAbstract.php new file mode 100644 index 0000000000000..077afd7a5b8a3 --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/History/CompactAbstract.php @@ -0,0 +1,78 @@ +_changesCollection = $collection; + return $this; + } + + /** + * Get change collection + * + * @return Mage_DesignEditor_Model_Change_Collection + */ + public function getChangesCollection() + { + return $this->_changesCollection; + } + + /** + * Signature of compact method to implement in subclasses + * + * @param Mage_DesignEditor_Model_Change_Collection $collection + * @throws Magento_Exception + * @return Mage_DesignEditor_Model_History_CompactInterface + */ + public function compact($collection = null) + { + if (null === $collection) { + if (!$this->getChangesCollection()) { + throw new Magento_Exception('Compact collection is missed'); + } + } + return $this->setChangesCollection($collection); + } +} diff --git a/app/code/core/Mage/DesignEditor/Model/History/CompactInterface.php b/app/code/core/Mage/DesignEditor/Model/History/CompactInterface.php new file mode 100644 index 0000000000000..1d14158798f08 --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/History/CompactInterface.php @@ -0,0 +1,55 @@ +getActions() as $action => $data) { - $resultData[] = array( - 'handle' => $this->getHandle(), - 'change_type' => $this->getType(), - 'element_name' => $this->getName(), - 'action_name' => $action, - 'action_data' => $data, - ); - } - - return $resultData; - } -} diff --git a/app/code/core/Mage/DesignEditor/Model/History/Manager/Adapter/Layout.php b/app/code/core/Mage/DesignEditor/Model/History/Manager/Adapter/Layout.php deleted file mode 100644 index 5371ecc62aa64..0000000000000 --- a/app/code/core/Mage/DesignEditor/Model/History/Manager/Adapter/Layout.php +++ /dev/null @@ -1,187 +0,0 @@ -_executeActionByType($action, self::TYPE_ADD, $data); - return $this; - } - - /** - * Execute action by type - * - * @throws Mage_DesignEditor_Exception - * @param string $action - * @param string $type - * @param null|array $data - * @return mixed - */ - protected function _executeActionByType($action, $type, $data = null) - { - switch ($action) { - case self::ACTION_MOVE: - return $this->{'_' . self::ACTION_MOVE . $type}($data); - break; - case self::ACTION_REMOVE: - return $this->{'_' . self::ACTION_REMOVE . $type}($data); - break; - default: - throw new Mage_DesignEditor_Exception( - Mage::helper('Mage_DesignEditor_Helper_Data')->__('Action not exist: %s', $action) - ); - break; - } - } - - /** - * Remove action - * - * @return Mage_DesignEditor_Model_History_Manager_Adapter_Layout - */ - protected function _removeAdd() - { - $this->_clearActions()->setRemoveFlag(true)->setActions(array(self::ACTION_REMOVE => array())); - return $this; - } - - /** - * Clear actions data - * - * @return Mage_DesignEditor_Model_History_Manager_Adapter_Layout - */ - protected function _clearActions() - { - $this->setActions(null); - return $this; - } - - /** - * Action move - * - * @param array $data - * @return Mage_DesignEditor_Model_History_Manager_Adapter_Layout - */ - protected function _moveAdd($data) - { - if ($this->getRemoveFlag()) { - return $this; - } - $this->setActions(array(self::ACTION_MOVE => $data)); - return $this; - } - - /** - * Element render action - * - * @return Mage_DesignEditor_Model_History_Manager_Adapter_Layout - */ - public function render() - { - /** @var $handleObject Varien_Simplexml_Element */ - $handleObject = $this->getHandleObject(); - foreach ($this->getActions() as $action => $data) { - $handleObject->appendChild($this->_executeActionByType($action, self::TYPE_RENDER, $data)); - } - return $this; - } - - /** - * - * Render move action - * - * @param array $actionData - * @return Varien_Simplexml_Element - */ - protected function _moveRender($actionData) - { - $move = new Varien_Simplexml_Element(''); - $move->addAttribute('element', $this->getName()); - - if (isset($actionData['after'])) { - $move->addAttribute('after', $actionData['after']); - } elseif ($actionData['before']) { - $move->addAttribute('before', $actionData['before']); - } - - if (isset($actionData['as'])) { - $move->addAttribute('as', $actionData['as']); - } - - $move->addAttribute('destination', $actionData['destination_container']); - return $move; - } - - /** - * Render remove action - * - * @return Varien_Simplexml_Element - */ - protected function _removeRender() - { - $remove = new Varien_Simplexml_Element(''); - $remove->addAttribute('name', $this->getName()); - return $remove; - } -} diff --git a/app/code/core/Mage/DesignEditor/Model/History/Manager/Collection.php b/app/code/core/Mage/DesignEditor/Model/History/Manager/Collection.php deleted file mode 100644 index cdba806549824..0000000000000 --- a/app/code/core/Mage/DesignEditor/Model/History/Manager/Collection.php +++ /dev/null @@ -1,166 +0,0 @@ -_elements; - } - - /** - * Get element - * - * @param string $type - * @param string $name - * @return Mage_DesignEditor_Model_History_Manager_Adapter_Abstract - */ - protected function _getElement($type, $name) - { - if (!isset($this->_elements[$type][$name])) { - $this->_elements[$type][$name] = $this->_createElementByType($type); - } - return $this->_elements[$type][$name]; - } - - /** - * Create element by type - * - * @param string $type - * @return Mage_DesignEditor_Model_History_Manager_Adapter_Abstract - */ - protected function _createElementByType($type) - { - return Mage_DesignEditor_Model_History_Manager_Adapter::factory($type); - } - - /** - * Get elements by type - * - * @param string $type - * @return array|Mage_DesignEditor_Model_History_Manager_Adapter_Abstract - */ - protected function _getElementsByType($type) - { - return isset($this->_elements[$type]) ? $this->_elements[$type] : array(); - } - - /** - * Add element - * - * @param string $change - * @return Mage_DesignEditor_Model_History_Manager_Adapter_Abstract - */ - public function addElement($change) - { - $handle = $change['handle']; - $type = $change['change_type']; - $name = $change['element_name']; - $action = $change['action_name']; - $data = isset($change['action_data']) ? $change['action_data'] : ''; - - $element = $this->_getElement($type, $name); - $element->setHandle($handle)->setType($type)->setName($name)->addAction($action, $data); - return $this; - } - - /** - * Collection to xml - * - * @return string - */ - public function toXml() - { - /** @var $xmlObject Varien_Simplexml_Element */ - $xmlObject = new Varien_Simplexml_Element(''); - - foreach ($this->_xmlTypes as $type) { - foreach ($this->_getElementsByType($type) as $element) { - $handleObject = $this->_getChildByHandle($xmlObject, $element->getHandle()); - $element->setHandleObject($handleObject)->render(); - } - } - - return $xmlObject->asNiceXml(); - } - - /** - * Get child by handle - * - * @param Varien_Simplexml_Element $xmlObject - * @param string $handle - * @return Varien_Simplexml_Element - */ - protected function _getChildByHandle($xmlObject, $handle) - { - foreach ($xmlObject->children() as $child) { - if ($child->getName() == $handle) { - return $child; - } - } - return $xmlObject->addChild($handle); - } - - /** - * Collection to history log - * - * @return array - */ - public function toHistoryLog() - { - $historyLog = array(); - - foreach ($this->_getElements() as $elementsByType) { - foreach ($elementsByType as $element) { - $historyLog = array_merge($historyLog, $element->toHistoryLog()); - } - } - - return $historyLog; - } -} diff --git a/app/code/core/Mage/DesignEditor/Model/History/Renderer/LayoutUpdate.php b/app/code/core/Mage/DesignEditor/Model/History/Renderer/LayoutUpdate.php new file mode 100644 index 0000000000000..a546a367857f4 --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/History/Renderer/LayoutUpdate.php @@ -0,0 +1,102 @@ +formatOutput = true; + $dom->loadXML($this->_getInitialXml()); + + foreach ($collection as $item) { + if ($item instanceof Mage_DesignEditor_Model_Change_LayoutAbstract) { + $this->_render($dom, $item); + } + } + + $layoutUpdate = $dom->saveXML(); + + return $layoutUpdate; + } + + /** + * Get initial XML structure + * + * @return string + */ + protected function _getInitialXml() + { + return ''; + } + + /** + * Render layout update for single layout change + * + * @param DOMDocument $dom + * @param Mage_DesignEditor_Model_Change_LayoutAbstract $item + * @return DOMElement + */ + protected function _render(DOMDocument $dom, $item) + { + $handle = $this->_getHandleNode($dom, $item->getData('handle')); + + $directive = $dom->createElement($item->getLayoutDirective()); + $handle->appendChild($directive); + + foreach ($item->getLayoutUpdateData() as $attribute => $value) { + $directive->setAttribute($attribute, $value); + } + return $handle; + } + + /** + * Create or get existing handle node + * + * @param DOMDocument $dom + * @param string $handle + * @return DOMElement + */ + protected function _getHandleNode($dom, $handle) + { + $node = $dom->getElementsByTagName($handle)->item(0); + if (!$node) { + $node = $dom->createElement($handle); + $dom->documentElement->appendChild($node); + } + + return $node; + } +} diff --git a/app/code/core/Mage/DesignEditor/Model/History/RendererInterface.php b/app/code/core/Mage/DesignEditor/Model/History/RendererInterface.php new file mode 100644 index 0000000000000..a2ae9eb790c33 --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/History/RendererInterface.php @@ -0,0 +1,40 @@ +activateDesignEditor(); /* Redirect to the frontend */ $query = Mage_Core_Model_Session_Abstract::SESSION_ID_QUERY_PARAM . '=' . urlencode($session->getSessionId()); - if (!Mage::app()->isSingleStoreMode()) { + if (!Mage::app()->hasSingleStore()) { $storeId = (int)$this->getRequest()->getParam('store_id'); $store = Mage::app()->getStore($storeId); $baseUrl = $store->getBaseUrl(); diff --git a/app/code/core/Mage/DesignEditor/controllers/EditorController.php b/app/code/core/Mage/DesignEditor/controllers/EditorController.php index 65281c21e5634..fd729d4fce7b1 100644 --- a/app/code/core/Mage/DesignEditor/controllers/EditorController.php +++ b/app/code/core/Mage/DesignEditor/controllers/EditorController.php @@ -142,30 +142,50 @@ public function compactHistoryAction() { $historyData = Mage::app()->getRequest()->getPost(); + /** @var $helper Mage_Core_Helper_Data */ + $helper = Mage::helper('Mage_Core_Helper_Data'); + if (!$historyData) { - $this->getResponse()->setBody(Mage::helper('Mage_Core_Helper_Data')->jsonEncode( + $this->getResponse()->setBody($helper->jsonEncode( array(Mage_Core_Model_Message::ERROR => array($this->__('Invalid post data'))) )); return; } - /** @var $historyModel Mage_DesignEditor_Model_History */ - $historyModel = Mage::getModel('Mage_DesignEditor_Model_History'); try { - $this->getResponse()->setBody(Mage::helper('Mage_Core_Helper_Data')->jsonEncode(array( - Mage_Core_Model_Message::SUCCESS => array($historyModel->setChangeLog($historyData)->getCompactLog()) - ))); + $historyModel = $this->_compactHistory($historyData); + $response = array(Mage_Core_Model_Message::SUCCESS => array($historyModel->getChanges()->toArray())); } catch (Mage_Core_Exception $e) { - $this->getResponse()->setBody(Mage::helper('Mage_Core_Helper_Data')->jsonEncode( - array(Mage_Core_Model_Message::ERROR => array($e->getMessage())) - )); + $response = array( + Mage_Core_Model_Message::ERROR => array($e->getMessage()) + ); } + + $this->getResponse()->setBody($helper->jsonEncode($response)); + } + + /** + * Compact history + * + * @param array $historyData + * @return Mage_DesignEditor_Model_History + */ + protected function _compactHistory($historyData) + { + /** @var $historyModel Mage_DesignEditor_Model_History */ + $historyModel = Mage::getModel('Mage_DesignEditor_Model_History'); + /** @var $historyCompactModel Mage_DesignEditor_Model_History_Compact */ + $historyCompactModel = Mage::getModel('Mage_DesignEditor_Model_History_Compact'); + /** @var $collection Mage_DesignEditor_Model_Change_Collection */ + $collection = $historyModel->setChanges($historyData)->getChanges(); + $historyCompactModel->compact($collection); + return $historyModel; } /** * Get layout xml */ - public function compactXmlAction() + public function getLayoutUpdateAction() { $historyData = Mage::app()->getRequest()->getPost(); @@ -176,11 +196,13 @@ public function compactXmlAction() return; } - /** @var $historyModel Mage_DesignEditor_Model_History */ - $historyModel = Mage::getModel('Mage_DesignEditor_Model_History'); try { + $historyModel = $this->_compactHistory($historyData); + /** @var $layoutRenderer Mage_DesignEditor_Model_History_Renderer_LayoutUpdate */ + $layoutRenderer = Mage::getModel('Mage_DesignEditor_Model_History_Renderer_LayoutUpdate'); + $layoutUpdate = $historyModel->output($layoutRenderer); $this->getResponse()->setBody(Mage::helper('Mage_Core_Helper_Data')->jsonEncode(array( - Mage_Core_Model_Message::SUCCESS => array($historyModel->setChangeLog($historyData)->getCompactXml()) + Mage_Core_Model_Message::SUCCESS => array($layoutUpdate) ))); } catch (Mage_Core_Exception $e) { $this->getResponse()->setBody(Mage::helper('Mage_Core_Helper_Data')->jsonEncode( diff --git a/app/code/core/Mage/DesignEditor/view/frontend/js/change/history.js b/app/code/core/Mage/DesignEditor/view/frontend/js/change/history.js deleted file mode 100644 index a84e9ecc49860..0000000000000 --- a/app/code/core/Mage/DesignEditor/view/frontend/js/change/history.js +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Magento - * - * NOTICE OF LICENSE - * - * This source file is subject to the Academic Free License (AFL 3.0) - * that is bundled with this package in the file LICENSE_AFL.txt. - * It is also available through the world-wide-web at this URL: - * http://opensource.org/licenses/afl-3.0.php - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@magentocommerce.com so we can send you a copy immediately. - * - * DISCLAIMER - * - * Do not edit or add to this file if you wish to upgrade Magento to newer - * versions in the future. If you wish to customize Magento for your - * needs please refer to http://www.magentocommerce.com for more information. - * - * @category Mage - * @package Mage_DesignEditor - * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com) - * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) - */ - -( function ( $ ) { - /** - * Change history - */ - $.fn.history = (function() { - var _object; - - var _init = function() { - if (!_object) { - _object = new HistoryObject(); - } - return _object; - } - - return _init(); - })(); - - /** - * History object - */ - function HistoryObject() { - var history = []; - return { - add: function(revision, title) { - history[revision] = title; - console.log(history[revision]); - /** @todo add your code */ - }, - undo: function() { - /** @todo add your code */ - }, - redo: function() { - /** @todo add your code */ - }, - revertToRevision: function(revision) { - /** @todo add your code */ - } - - }; - - }; -})( jQuery ); \ No newline at end of file diff --git a/app/code/core/Mage/DesignEditor/view/frontend/js/change/layout.js b/app/code/core/Mage/DesignEditor/view/frontend/js/change/layout.js index 7c970f34d4387..bad19fc6b17fa 100644 --- a/app/code/core/Mage/DesignEditor/view/frontend/js/change/layout.js +++ b/app/code/core/Mage/DesignEditor/view/frontend/js/change/layout.js @@ -141,12 +141,12 @@ action: ACTION_MOVE, block: data.element_name, origin: { - container: null, - order: null + container: data.origin_container, + order: data.origin_order }, destination: { - container: data.action_data.container, - order: data.action_data.after + container: data.destination_container, + order: data.destination_order } }); }, @@ -171,19 +171,19 @@ _getPostDataMove: function(data) { return { handle: 'current_handle', - change_type: this.type, + type: this.type, element_name: data.block, action_name: ACTION_MOVE, - action_data: { - container: data.destination.container, - after: data.destination.order - } + destination_container: data.destination.container, + destination_order: data.destination.order, + origin_container: data.origin.container, + origin_order: data.origin.order } }, _getPostDataRemove: function(data) { return { handle: 'current_handle', - change_type: this.type, + type: this.type, element_name: data.block, action_name: ACTION_REMOVE } diff --git a/app/code/core/Mage/Directory/etc/system.xml b/app/code/core/Mage/Directory/etc/system.xml index d1a599b962280..487818ed10998 100644 --- a/app/code/core/Mage/Directory/etc/system.xml +++ b/app/code/core/Mage/Directory/etc/system.xml @@ -50,7 +50,7 @@ Mage_Adminhtml_Model_System_Config_Source_Currency Mage_Adminhtml_Model_System_Config_Backend_Currency_Base 1 - "Price" > "Catalog Price Scope").]]> + "Price" > "Catalog Price Scope").]]> 1 1 0 diff --git a/app/code/core/Mage/Eav/data/eav_setup/data-upgrade-1.6.0.0-1.6.0.1.php b/app/code/core/Mage/Eav/data/eav_setup/data-upgrade-1.6.0.0-1.6.0.1.php index 121778192c738..6414b8e21d59c 100644 --- a/app/code/core/Mage/Eav/data/eav_setup/data-upgrade-1.6.0.0-1.6.0.1.php +++ b/app/code/core/Mage/Eav/data/eav_setup/data-upgrade-1.6.0.0-1.6.0.1.php @@ -24,6 +24,9 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** Bug MAGETWO-3318 Segmentation Fault */ +return; + /** @var $installer Mage_Core_Model_Resource_Setup_Migration */ $installer = Mage::getResourceModel('Mage_Core_Model_Resource_Setup_Migration', 'core_setup'); $installer->startSetup(); diff --git a/app/code/core/Mage/GoogleCheckout/etc/config.xml b/app/code/core/Mage/GoogleCheckout/etc/config.xml index a06805c6f0cd1..5d54ff850ede2 100644 --- a/app/code/core/Mage/GoogleCheckout/etc/config.xml +++ b/app/code/core/Mage/GoogleCheckout/etc/config.xml @@ -131,6 +131,7 @@ 1 Mage_GoogleCheckout_Model_Payment + Google Checkout diff --git a/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Catalog/Category/Edit/Tab/Googleoptimizer.php b/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Catalog/Category/Edit/Tab/Googleoptimizer.php index 4c96f6552f9c5..cca7ad84ec1f2 100644 --- a/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Catalog/Category/Edit/Tab/Googleoptimizer.php +++ b/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Catalog/Category/Edit/Tab/Googleoptimizer.php @@ -106,7 +106,7 @@ public function _prepareLayout() ) ); //Mage::getStoreConfigFlag(Mage_Core_Model_Store::XML_PATH_STORE_IN_URL) - if ($this->getCategory()->getStoreId() == '0' && !Mage::app()->isSingleStoreMode()) { + if ($this->getCategory()->getStoreId() == '0' && !Mage::app()->hasSingleStore()) { $fieldset->addField('conversion_page_url', 'note', array( 'name' => 'conversion_page_url', diff --git a/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Catalog/Product/Edit/Tab/Googleoptimizer.php b/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Catalog/Product/Edit/Tab/Googleoptimizer.php index 72a4bc5372117..2a6dfb3a3c3ce 100644 --- a/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Catalog/Product/Edit/Tab/Googleoptimizer.php +++ b/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Catalog/Product/Edit/Tab/Googleoptimizer.php @@ -90,7 +90,7 @@ protected function _prepareForm() ) ); - if ($this->getProduct()->getStoreId() == '0' && !Mage::app()->isSingleStoreMode()) { + if ($this->getProduct()->getStoreId() == '0' && !Mage::app()->hasSingleStore()) { $fieldset->addField('conversion_page_url', 'note', array( 'name' => 'conversion_page_url', diff --git a/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Tab/Googleoptimizer.php b/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Tab/Googleoptimizer.php index 3990d09f2b4c4..8b6940ea66fa4 100644 --- a/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Tab/Googleoptimizer.php +++ b/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Tab/Googleoptimizer.php @@ -68,7 +68,7 @@ protected function _prepareForm() ) ); - if (!Mage::app()->isSingleStoreMode()) { + if (!Mage::app()->hasSingleStore()) { $form->getElement('conversion_page')->setOnchange('googleOptimizerConversionCmsPageAction(this)'); $fieldset->addField('conversion_page_url', 'note', array( 'name' => 'conversion_page_url', diff --git a/app/code/core/Mage/GoogleOptimizer/Helper/Data.php b/app/code/core/Mage/GoogleOptimizer/Helper/Data.php index 82135e659901c..a0933ffea4019 100644 --- a/app/code/core/Mage/GoogleOptimizer/Helper/Data.php +++ b/app/code/core/Mage/GoogleOptimizer/Helper/Data.php @@ -194,7 +194,7 @@ public function getConversionPagesUrl() $storeBaseUrl = $store->getConfig($_path); $websiteBaseUrl = $store->getWebsite()->getConfig($_path); $defaultBaseUrl = Mage::app()->getStore(0)->getConfig($_path); - if ($storeBaseUrl == $websiteBaseUrl && !Mage::app()->isSingleStoreMode()) { + if ($storeBaseUrl == $websiteBaseUrl && !Mage::app()->hasSingleStore()) { $_query = array('__store' => $store->getCode()); } $urls[$choice['value']] = $url->setStore($this->getStoreId())->getUrl($route, diff --git a/app/code/core/Mage/Newsletter/Model/Template.php b/app/code/core/Mage/Newsletter/Model/Template.php index 88ab540dbc953..9ff4848516c59 100644 --- a/app/code/core/Mage/Newsletter/Model/Template.php +++ b/app/code/core/Mage/Newsletter/Model/Template.php @@ -188,7 +188,7 @@ public function getProcessedTemplate(array $variables = array(), $usePreprocess $variables['this'] = $this; } - if (Mage::app()->isSingleStoreMode()) { + if (Mage::app()->hasSingleStore()) { $processor->setStoreId(Mage::app()->getStore()); } else { $processor->setStoreId(Mage::app()->getRequest()->getParam('store_id')); diff --git a/app/code/core/Mage/Newsletter/data/newsletter_setup/data-upgrade-1.6.0.1-1.6.0.2.php b/app/code/core/Mage/Newsletter/data/newsletter_setup/data-upgrade-1.6.0.1-1.6.0.2.php index ab53fbadfcf5d..ac0a3a3b53224 100644 --- a/app/code/core/Mage/Newsletter/data/newsletter_setup/data-upgrade-1.6.0.1-1.6.0.2.php +++ b/app/code/core/Mage/Newsletter/data/newsletter_setup/data-upgrade-1.6.0.1-1.6.0.2.php @@ -24,6 +24,9 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** Bug MAGETWO-3318 Segmentation Fault */ +return; + /** @var $installer Mage_Core_Model_Resource_Setup_Migration */ $installer = Mage::getResourceModel('Mage_Core_Model_Resource_Setup_Migration', 'core_setup'); $installer->startSetup(); diff --git a/app/code/core/Mage/Rating/Model/Resource/Rating.php b/app/code/core/Mage/Rating/Model/Resource/Rating.php index 71bea5f3ff628..4837b8db90be0 100755 --- a/app/code/core/Mage/Rating/Model/Resource/Rating.php +++ b/app/code/core/Mage/Rating/Model/Resource/Rating.php @@ -35,6 +35,29 @@ class Mage_Rating_Model_Resource_Rating extends Mage_Core_Model_Resource_Db_Abst { const RATING_STATUS_APPROVED = 'Approved'; + /** + * Application instance + * + * @var Mage_Core_Model_App + */ + protected $_app; + + /** + * Class constructor + * + * @param array $arguments + * @throws InvalidArgumentException + */ + public function __construct(array $arguments = array()) + { + $this->_app = isset($arguments['app']) ? $arguments['app'] : Mage::app(); + + if (!($this->_app instanceof Mage_Core_Model_App)) { + throw new InvalidArgumentException('Required app object is invalid'); + } + parent::__construct($arguments); + } + /** * Resource initialization */ @@ -317,11 +340,15 @@ protected function _getEntitySummaryData($object) array()) ->joinLeft(array('review_store' => $this->getTable('review_store')), 'rating_vote.review_id=review_store.review_id', - array('review_store.store_id')) - ->join(array('rating_store' => $this->getTable('rating_store')), + array('review_store.store_id')); + if (!$this->_app->isSingleStoreMode()) { + $select->join( + array('rating_store' => $this->getTable('rating_store')), 'rating_store.rating_id = rating_vote.rating_id AND rating_store.store_id = review_store.store_id', - array()) - ->join(array('review_status' => $this->getTable('review_status')), + array() + ); + } + $select->join(array('review_status' => $this->getTable('review_status')), 'review.status_id = review_status.status_id', array()) ->where('review_status.status_code = :status_code') diff --git a/app/code/core/Mage/Rating/Model/Resource/Rating/Collection.php b/app/code/core/Mage/Rating/Model/Resource/Rating/Collection.php index 7786852f07845..57458a06a627c 100755 --- a/app/code/core/Mage/Rating/Model/Resource/Rating/Collection.php +++ b/app/code/core/Mage/Rating/Model/Resource/Rating/Collection.php @@ -33,6 +33,30 @@ */ class Mage_Rating_Model_Resource_Rating_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract { + /** + * Application instance + * + * @var Mage_Core_Model_App + */ + protected $_app; + + /** + * Collection constructor + * + * @param Mage_Core_Model_Resource_Db_Abstract $resource + * @param array $data + * @throws InvalidArgumentException + */ + public function __construct($resource = null, $data = array()) + { + $this->_app = isset($data['app']) ? $data['app'] : Mage::app(); + + if (!($this->_app instanceof Mage_Core_Model_App)) { + throw new InvalidArgumentException('Required app object is invalid'); + } + parent::__construct($resource); + } + /** * @var bool */ @@ -94,6 +118,9 @@ public function setPositionOrder($dir='ASC') */ public function setStoreFilter($storeId) { + if ($this->_app->isSingleStoreMode()) { + return $this; + } $adapter = $this->getConnection(); if (!is_array($storeId)) { $storeId = array($storeId === null ? -1 : $storeId); @@ -175,12 +202,14 @@ public function addEntitySummaryToItem($entityPkValue, $storeId) ->join( array('review_store' => $this->getTable('review_store')), 'rating_option_vote.review_id=review_store.review_id AND review_store.store_id = :store_id', - array()) - ->join( + array()); + if (!$this->_app->isSingleStoreMode()) { + $select->join( array('rst' => $this->getTable('rating_store')), 'rst.rating_id = rating_option_vote.rating_id AND rst.store_id = :rst_store_id', - array()) - ->join(array('review' => $this->getTable('review')), + array()); + } + $select->join(array('review' => $this->getTable('review')), 'review_store.review_id=review.review_id AND review.status_id=1', array()) ->where($inCond) @@ -188,9 +217,13 @@ public function addEntitySummaryToItem($entityPkValue, $storeId) ->group('rating_option_vote.rating_id'); $bind = array( ':store_id' => (int)$storeId, - ':rst_store_id' => (int)$storeId, + ':pk_value' => $entityPkValue ); + if (!$this->_app->isSingleStoreMode()) { + $bind[':rst_store_id'] = (int)$storeId; + } + $data = $this->getConnection()->fetchAll($select, $bind); foreach ($data as $item) { @@ -226,6 +259,9 @@ public function addRatingPerStoreName($storeId) */ public function addStoresToCollection() { + if ($this->_app->isSingleStoreMode()) { + return $this; + } if (!$this->_isCollectionLoaded) { return $this; } @@ -257,4 +293,16 @@ public function addStoresToCollection() } return $this; } + + /** + * Set Active Filter + * + * @param bool $isActive + * @return Mage_Rating_Model_Resource_Rating_Collection + */ + public function setActiveFilter($isActive = true) + { + $this->getSelect()->where('main_table.is_active=?', $isActive); + return $this; + } } diff --git a/app/code/core/Mage/Rating/Model/Resource/Rating/Option/Vote/Collection.php b/app/code/core/Mage/Rating/Model/Resource/Rating/Option/Vote/Collection.php index 54d71ddb620c5..740937d055197 100755 --- a/app/code/core/Mage/Rating/Model/Resource/Rating/Option/Vote/Collection.php +++ b/app/code/core/Mage/Rating/Model/Resource/Rating/Option/Vote/Collection.php @@ -33,6 +33,30 @@ */ class Mage_Rating_Model_Resource_Rating_Option_Vote_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract { + /** + * Application instance + * + * @var Mage_Core_Model_App + */ + protected $_app; + + /** + * Collection constructor + * + * @param Mage_Core_Model_Resource_Db_Abstract $resource + * @param array $data + * @throws InvalidArgumentException + */ + public function __construct($resource = null, $data = array()) + { + $this->_app = isset($data['app']) ? $data['app'] : Mage::app(); + + if (!($this->_app instanceof Mage_Core_Model_App)) { + throw new InvalidArgumentException('Required app object is invalid'); + } + parent::__construct($resource); + } + /** * Define model * @@ -76,6 +100,9 @@ public function setEntityPkFilter($entityId) */ public function setStoreFilter($storeId) { + if ($this->_app->isSingleStoreMode()) { + return $this; + } $this->getSelect() ->join(array('rstore'=>$this->getTable('review_store')), $this->getConnection()->quoteInto( @@ -105,26 +132,24 @@ public function addRatingInfo($storeId=null) $adapter->quoteInto('main_table.rating_id=title.rating_id AND title.store_id = ?', (int)Mage::app()->getStore()->getId()), array('rating_code' => $ratingCodeCond)); + if (!$this->_app->isSingleStoreMode()) { + if ($storeId == null) { + $storeId = Mage::app()->getStore()->getId(); + } - if ($storeId == null) { - $storeId = Mage::app()->getStore()->getId(); - } - - if (is_array($storeId)) { - $condition = $adapter->prepareSqlCondition('store.store_id', array( - 'in' => $storeId - )); - } else { - $condition = $adapter->quoteInto('store.store_id = ?', $storeId); - } + if (is_array($storeId)) { + $condition = $adapter->prepareSqlCondition('store.store_id', array( + 'in' => $storeId + )); + } else { + $condition = $adapter->quoteInto('store.store_id = ?', $storeId); + } - $this->getSelect() - ->join( + $this->getSelect()->join( array('store' => $this->getTable('rating_store')), - 'main_table.rating_id = store.rating_id AND ' . $condition) -// ->group('main_table.vote_id') - ; - + 'main_table.rating_id = store.rating_id AND ' . $condition + ); + } $adapter->fetchAll($this->getSelect()); return $this; } diff --git a/app/code/core/Mage/Rating/etc/config.xml b/app/code/core/Mage/Rating/etc/config.xml index c123024ef55e5..0beefa33f085b 100644 --- a/app/code/core/Mage/Rating/etc/config.xml +++ b/app/code/core/Mage/Rating/etc/config.xml @@ -28,7 +28,7 @@ - 1.6.0.0 + 1.6.0.1 true core diff --git a/app/code/core/Mage/Rating/sql/rating_setup/upgrade-1.6.0.0-1.6.0.1.php b/app/code/core/Mage/Rating/sql/rating_setup/upgrade-1.6.0.0-1.6.0.1.php new file mode 100644 index 0000000000000..1b26623b71fa2 --- /dev/null +++ b/app/code/core/Mage/Rating/sql/rating_setup/upgrade-1.6.0.0-1.6.0.1.php @@ -0,0 +1,36 @@ +getConnection() + ->addColumn($installer->getTable('rating'), 'is_active', array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Rating is active.' + )); diff --git a/app/code/core/Mage/Reports/etc/system.xml b/app/code/core/Mage/Reports/etc/system.xml index 457fa81525a3c..09358d180450f 100644 --- a/app/code/core/Mage/Reports/etc/system.xml +++ b/app/code/core/Mage/Reports/etc/system.xml @@ -45,6 +45,7 @@ 1 1 0 + 1 diff --git a/app/code/core/Mage/Review/Block/Form.php b/app/code/core/Mage/Review/Block/Form.php index f81d3f988fee1..ae81850b1e534 100644 --- a/app/code/core/Mage/Review/Block/Form.php +++ b/app/code/core/Mage/Review/Block/Form.php @@ -90,6 +90,7 @@ public function getRatings() ->setPositionOrder() ->addRatingPerStoreName(Mage::app()->getStore()->getId()) ->setStoreFilter(Mage::app()->getStore()->getId()) + ->setActiveFilter(true) ->load() ->addOptionToItems(); return $ratingCollection; diff --git a/app/code/core/Mage/Review/Model/Resource/Review.php b/app/code/core/Mage/Review/Model/Resource/Review.php index c35f5a5c7df32..4bd14848ac1a9 100755 --- a/app/code/core/Mage/Review/Model/Resource/Review.php +++ b/app/code/core/Mage/Review/Model/Resource/Review.php @@ -215,7 +215,7 @@ protected function _afterLoad(Mage_Core_Model_Abstract $object) ->from($this->_reviewStoreTable, array('store_id')) ->where('review_id = :review_id'); $stores = $adapter->fetchCol($select, array(':review_id' => $object->getId())); - if (empty($stores) && Mage::app()->isSingleStoreMode()) { + if (empty($stores) && Mage::app()->hasSingleStore()) { $object->setStores(array(Mage::app()->getStore(true)->getId())); } else { $object->setStores($stores); diff --git a/app/code/core/Mage/Sales/etc/config.xml b/app/code/core/Mage/Sales/etc/config.xml index b0d62cf803580..46f3ac39b4c5e 100644 --- a/app/code/core/Mage/Sales/etc/config.xml +++ b/app/code/core/Mage/Sales/etc/config.xml @@ -573,13 +573,6 @@ - - - 1 - Mage_GoogleCheckout_Model_Payment - Google Checkout - - 20 diff --git a/app/code/core/Mage/SalesRule/data/salesrule_setup/data-upgrade-1.6.0.3-1.6.0.4.php b/app/code/core/Mage/SalesRule/data/salesrule_setup/data-upgrade-1.6.0.3-1.6.0.4.php index 710278c4c36c7..103d0129e987e 100644 --- a/app/code/core/Mage/SalesRule/data/salesrule_setup/data-upgrade-1.6.0.3-1.6.0.4.php +++ b/app/code/core/Mage/SalesRule/data/salesrule_setup/data-upgrade-1.6.0.3-1.6.0.4.php @@ -24,6 +24,9 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** Bug MAGETWO-3318 Segmentation Fault */ +return; + /** @var $installer Mage_Core_Model_Resource_Setup_Migration */ $installer = Mage::getResourceModel('Mage_Core_Model_Resource_Setup_Migration', 'core_setup'); $installer->startSetup(); diff --git a/app/code/core/Mage/Weee/Block/Renderer/Weee/Tax.php b/app/code/core/Mage/Weee/Block/Renderer/Weee/Tax.php index a4559043cc6cb..c4f48df0a5487 100644 --- a/app/code/core/Mage/Weee/Block/Renderer/Weee/Tax.php +++ b/app/code/core/Mage/Weee/Block/Renderer/Weee/Tax.php @@ -96,7 +96,7 @@ public function getWebsiteCount() public function isMultiWebsites() { - return !Mage::app()->isSingleStoreMode(); + return !Mage::app()->hasSingleStore(); } public function getCountries() @@ -120,7 +120,7 @@ public function getWebsites() 'currency' => Mage::app()->getBaseCurrencyCode() ); - if (!Mage::app()->isSingleStoreMode() && !$this->getElement()->getEntityAttribute()->isScopeGlobal()) { + if (!Mage::app()->hasSingleStore() && !$this->getElement()->getEntityAttribute()->isScopeGlobal()) { if ($storeId = $this->getProduct()->getStoreId()) { $website = Mage::app()->getStore($storeId)->getWebsite(); $websites[$website->getId()] = array( diff --git a/app/code/core/Mage/Widget/data/widget_setup/data-upgrade-1.6.0.0-1.6.0.1.php b/app/code/core/Mage/Widget/data/widget_setup/data-upgrade-1.6.0.0-1.6.0.1.php index 1fa45b2bdb12f..2ac0c6f6fdf1e 100644 --- a/app/code/core/Mage/Widget/data/widget_setup/data-upgrade-1.6.0.0-1.6.0.1.php +++ b/app/code/core/Mage/Widget/data/widget_setup/data-upgrade-1.6.0.0-1.6.0.1.php @@ -24,6 +24,9 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** Bug MAGETWO-3318 Segmentation Fault */ +return; + /** @var $installer Mage_Core_Model_Resource_Setup_Migration */ $installer = Mage::getResourceModel('Mage_Core_Model_Resource_Setup_Migration', 'core_setup'); $installer->startSetup(); diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/General.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/General.php index 6fe6f11607bcb..f2ef239cac637 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/General.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/General.php @@ -76,7 +76,7 @@ protected function _prepareForm() /** * Check is single store mode */ - if (!Mage::app()->isSingleStoreMode()) { + if (!Mage::app()->hasSingleStore()) { $storeElement = $fieldset->addField('store_id', 'select', array( 'name' => 'store_id', 'label' => $this->__('Store View'), diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Payment.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Payment.php index e155bbaf82b19..e24253db4e822 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Payment.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Payment.php @@ -196,7 +196,7 @@ protected function _prepareForm() /** * PayPal MECL management */ - if (Mage::app()->isSingleStoreMode() + if (Mage::app()->hasSingleStore() || Mage::helper('Mage_XmlConnect_Helper_Data')->getApplication()->getId() ) { $paypalMeclIsAvailable = Mage::getModel('Mage_XmlConnect_Model_Payment_Method_Paypal_Mecl') diff --git a/app/code/core/Mage/XmlConnect/Model/Queue.php b/app/code/core/Mage/XmlConnect/Model/Queue.php index a1aa5eed28b5c..01e42e182ab51 100755 --- a/app/code/core/Mage/XmlConnect/Model/Queue.php +++ b/app/code/core/Mage/XmlConnect/Model/Queue.php @@ -173,7 +173,7 @@ public function getProcessedTemplate(array $variables = array()) $variables['this'] = $this; - if (Mage::app()->isSingleStoreMode()) { + if (Mage::app()->hasSingleStore()) { $processor->setStoreId(Mage::app()->getStore()); } else { $processor->setStoreId(1); diff --git a/app/code/core/Mage/XmlConnect/Model/Template.php b/app/code/core/Mage/XmlConnect/Model/Template.php index 017f1c890721e..16b79133d7f74 100755 --- a/app/code/core/Mage/XmlConnect/Model/Template.php +++ b/app/code/core/Mage/XmlConnect/Model/Template.php @@ -85,7 +85,7 @@ public function getProcessedTemplate(array $variables = array()) $variables['this'] = $this; - if (Mage::app()->isSingleStoreMode()) { + if (Mage::app()->hasSingleStore()) { $processor->setStoreId(Mage::app()->getStore()); } else { $processor->setStoreId(1); diff --git a/app/design/frontend/default/modern/skin/default/css/styles.css b/app/design/frontend/default/modern/skin/default/css/styles.css index 56bbe9e18b5f4..c5499ddcfabb0 100644 --- a/app/design/frontend/default/modern/skin/default/css/styles.css +++ b/app/design/frontend/default/modern/skin/default/css/styles.css @@ -891,7 +891,7 @@ tr.summary-details-excluded { font-style:italic; } .product-pricing, .tier-prices { margin:10px 0; padding:10px; background:#f4f9ea; border:1px solid #ddd; } .tier-prices .benefit { font-style:italic; font-weight:bold; } -.tier-prices .price { font-weight:bold;; } +.tier-prices .price { font-weight:bold; } .tier-prices-grouped li .price { font-weight:bold; } diff --git a/dev/tests/integration/testsuite/Mage/Adminhtml/Block/System/Config/FormTest.php b/dev/tests/integration/testsuite/Mage/Adminhtml/Block/System/Config/FormTest.php index 9f5317211f463..5e8f1f0824dc8 100644 --- a/dev/tests/integration/testsuite/Mage/Adminhtml/Block/System/Config/FormTest.php +++ b/dev/tests/integration/testsuite/Mage/Adminhtml/Block/System/Config/FormTest.php @@ -145,6 +145,9 @@ public function testInitFormAddsFieldsets() 'general_store_information_merchant_vat_number' => 'text', 'general_store_information_validate_vat_number' => 'text', 'general_store_information_address' => 'textarea', + ), + 'general_single_store_mode' => array( + 'general_single_store_mode_enabled' => 'select', ) ); $elements = $block->getForm()->getElements(); diff --git a/dev/tests/integration/testsuite/Mage/Adminhtml/Model/Config/DataTest.php b/dev/tests/integration/testsuite/Mage/Adminhtml/Model/Config/DataTest.php new file mode 100644 index 0000000000000..aa78d1b0b5f2d --- /dev/null +++ b/dev/tests/integration/testsuite/Mage/Adminhtml/Model/Config/DataTest.php @@ -0,0 +1,74 @@ +setSection('dev') + ->setWebsite('base') + ->load(); + $this->assertEmpty($_configData); + + $_configDataObject = new Mage_Adminhtml_Model_Config_Data(); + $_configDataObject->setSection('dev') + ->setGroups($groups) + ->save(); + + Mage::getConfig()->reinit(); + Mage::app()->reinitStores(); + + $_configDataObject = new Mage_Adminhtml_Model_Config_Data(); + $_configDataObject->setSection('dev') + ->setWebsite('base'); + + $_configData = $_configDataObject->load(); + $this->assertArrayHasKey('dev/debug/template_hints', $_configData); + $this->assertArrayHasKey('dev/debug/template_hints_blocks', $_configData); + + $_configDataObject = new Mage_Adminhtml_Model_Config_Data(); + $_configDataObject->setSection('dev'); + $_configData = $_configDataObject->load(); + $this->assertArrayNotHasKey('dev/debug/template_hints', $_configData); + $this->assertArrayNotHasKey('dev/debug/template_hints_blocks', $_configData); + } + + public function saveDataProvider() + { + return require(__DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'config_groups.php'); + } +} diff --git a/dev/tests/integration/testsuite/Mage/Core/controllers/IndexControllerTest.php b/dev/tests/integration/testsuite/Mage/Adminhtml/Model/Config/_files/config_groups.php similarity index 72% rename from dev/tests/integration/testsuite/Mage/Core/controllers/IndexControllerTest.php rename to dev/tests/integration/testsuite/Mage/Adminhtml/Model/Config/_files/config_groups.php index df3de47429e30..6c3e40e64a846 100644 --- a/dev/tests/integration/testsuite/Mage/Core/controllers/IndexControllerTest.php +++ b/dev/tests/integration/testsuite/Mage/Adminhtml/Model/Config/_files/config_groups.php @@ -19,17 +19,22 @@ * needs please refer to http://www.magentocommerce.com for more information. * * @category Magento - * @package Mage_Core + * @package Mage_Adminhtml * @subpackage integration_tests * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Core_IndexControllerTest extends Magento_Test_TestCase_ControllerAbstract -{ - public function testIndexAction() - { - $this->dispatch('core/index/index'); - $this->assertEquals('', $this->getResponse()->getBody()); - } -} +return array(array('groups' => array( + 'restrict' => array( + 'fields' => array( + 'allow_ips' => array('value' => ''), + ), + ), + 'debug' => array( + 'fields' => array( + 'template_hints' => array('value' => '0'), + 'template_hints_blocks' => array('value' => '0'), + ), + ), +))); \ No newline at end of file diff --git a/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/Catalog/CategoryControllerTest.php b/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/Catalog/CategoryControllerTest.php new file mode 100644 index 0000000000000..cac290623ed28 --- /dev/null +++ b/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/Catalog/CategoryControllerTest.php @@ -0,0 +1,208 @@ +load('fixturestore', 'code'); + $storeId = $store->getId(); + + $this->getRequest()->setPost($inputData); + $this->getRequest()->setParam('store', $storeId); + $this->getRequest()->setParam('id', 2); + $this->dispatch('backend/admin/catalog_category/save'); + + $messages = Mage::getSingleton('Mage_Backend_Model_Session') + ->getMessages(false)->getItemsByType(Mage_Core_Model_Message::SUCCESS); + $this->assertNotEmpty($messages, "Could not save category"); + $this->assertEquals('The category has been saved.', current($messages)->getCode()); + + $category = new Mage_Catalog_Model_Category(); + $category->setStoreId($storeId); + $category->load(2); + + $errors = array(); + foreach ($attributesSaved as $attribute => $value) { + $actualValue = $category->getData($attribute); + if ($value !== $actualValue) { + $errors[] = "value for '$attribute' attribute must be '$value', but '$actualValue' is found instead"; + } + } + + foreach ($defaultAttributes as $attribute => $exists) { + if ($exists !== $category->getExistsStoreValueFlag($attribute)) { + if ($exists) { + $errors[] = "custom value for '$attribute' attribute is not found"; + } else { + $errors[] = "custom value for '$attribute' attribute is found, but default one must be used"; + } + } + } + + $this->assertEmpty($errors, "\n" . join("\n", $errors)); + } + + /** + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @return array + */ + public function saveActionDataProvider() + { + return array( + 'default values' => array( + array( + 'general' => array( + 'id' => '2', + 'path' => '1/2', + 'url_key' => 'default-category', + 'is_anchor' => '0', + ), + 'use_default' => array( + 0 => 'name', + 1 => 'is_active', + 2 => 'thumbnail', + 3 => 'description', + 4 => 'image', + 5 => 'meta_title', + 6 => 'meta_keywords', + 7 => 'meta_description', + 8 => 'include_in_menu', + 9 => 'display_mode', + 10 => 'landing_page', + 11 => 'available_sort_by', + 12 => 'default_sort_by', + 13 => 'filter_price_range', + 14 => 'custom_apply_to_products', + 15 => 'custom_design', + 16 => 'custom_design_from', + 17 => 'custom_design_to', + 18 => 'page_layout', + 19 => 'custom_layout_update', + ), + ), + array( + 'name' => false, + 'default_sort_by' => false, + 'display_mode' => false, + 'meta_title' => false, + 'custom_design' => false, + 'page_layout' => false, + 'is_active' => false, + 'include_in_menu' => false, + 'landing_page' => false, + 'is_anchor' => false, + 'custom_apply_to_products' => false, + 'available_sort_by' => false, + 'description' => false, + 'meta_keywords' => false, + 'meta_description' => false, + 'custom_layout_update' => false, + 'custom_design_from' => false, + 'custom_design_to' => false, + 'filter_price_range' => false, + ), + ), + 'custom values' => array( + array( + 'general' => array( + 'id' => '2', + 'path' => '1/2', + 'name' => 'Custom Name', + 'is_active' => '0', + 'description' => 'Custom Description', + 'meta_title' => 'Custom Title', + 'meta_keywords' => 'Custom keywords', + 'meta_description' => 'Custom meta description', + 'include_in_menu' => '0', + 'url_key' => 'default-category', + 'display_mode' => 'PRODUCTS', + 'landing_page' => '1', + 'is_anchor' => '1', + 'custom_apply_to_products' => '0', + 'custom_design' => 'default/default/blank', + 'custom_design_from' => '', + 'custom_design_to' => '', + 'page_layout' => '', + 'custom_layout_update' => '', + ), + 'use_config' => array( + 0 => 'available_sort_by', + 1 => 'default_sort_by', + 2 => 'filter_price_range', + ), + ), + array( + 'name' => true, + 'default_sort_by' => true, + 'display_mode' => true, + 'meta_title' => true, + 'custom_design' => true, + 'page_layout' => true, + 'is_active' => true, + 'include_in_menu' => true, + 'landing_page' => true, + 'custom_apply_to_products' => true, + 'available_sort_by' => true, + 'description' => true, + 'meta_keywords' => true, + 'meta_description' => true, + 'custom_layout_update' => true, + 'custom_design_from' => true, + 'custom_design_to' => true, + 'filter_price_range' => true, + ), + array( + 'name' => 'Custom Name', + 'default_sort_by' => NULL, + 'display_mode' => 'PRODUCTS', + 'meta_title' => 'Custom Title', + 'custom_design' => 'default/default/blank', + 'page_layout' => NULL, + 'is_active' => '0', + 'include_in_menu' => '0', + 'landing_page' => '1', + 'custom_apply_to_products' => '0', + 'available_sort_by' => NULL, + 'description' => 'Custom Description', + 'meta_keywords' => 'Custom keywords', + 'meta_description' => 'Custom meta description', + 'custom_layout_update' => NULL, + 'custom_design_from' => NULL, + 'custom_design_to' => NULL, + 'filter_price_range' => NULL, + ), + ), + ); + } +} diff --git a/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/NewsletterQueueControllerTest.php b/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/NewsletterQueueControllerTest.php new file mode 100644 index 0000000000000..54b58f672466a --- /dev/null +++ b/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/NewsletterQueueControllerTest.php @@ -0,0 +1,77 @@ +_model = Mage::getModel('Mage_Newsletter_Model_Template'); + } + public function tearDown() + { + /** + * Unset messages + */ + Mage::getSingleton('Mage_Backend_Model_Session')->getMessages(true); + unset($this->_model); + } + + /** + * @magentoDataFixture Mage/Adminhtml/controllers/_files/newsletter_sample.php + * @magentoAppIsolation disabled + */ + public function testSaveActionQueueTemplateAndVerifySuccessMessage() + { + $postForQueue = array('sender_email'=>'johndoe_gieee@unknown-domain.com', + 'sender_name'=>'john doe', + 'subject'=>'test subject', + 'text'=>'newsletter text'); + $this->getRequest()->setPost($postForQueue); + $this->_model->loadByCode('some_unique_code'); + $this->getRequest()->setParam('template_id', $this->_model->getId()); + $this->dispatch('backend/admin/newsletter_queue/save'); + + /** + * Check that errors was generated and set to session + */ + $this->assertEmpty(Mage::getSingleton('Mage_Backend_Model_Session')->getMessages(false)->getErrors()); + + /** + * Check that success message is set + */ + $successMessages = Mage::getSingleton('Mage_Backend_Model_Session') + ->getMessages(false)->getItemsByType(Mage_Core_Model_Message::SUCCESS); + $this->assertCount(1, $successMessages, 'Success message was not set'); + $this->assertEquals('The newsletter queue has been saved.', current($successMessages)->getCode()); + } +} diff --git a/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/NewsletterTemplateControllerTest.php b/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/NewsletterTemplateControllerTest.php new file mode 100644 index 0000000000000..97d5a20adf5f5 --- /dev/null +++ b/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/NewsletterTemplateControllerTest.php @@ -0,0 +1,152 @@ +'test data', + 'subject'=>'test data2', + 'sender_email'=>'sender@email.com', + 'sender_name'=>'Test Sender Name', + 'text'=>'Template Content'); + $this->getRequest()->setPost($post); + $this->_model = Mage::getModel('Mage_Newsletter_Model_Template'); + } + + public function tearDown() + { + /** + * Unset messages + */ + Mage::getSingleton('Mage_Backend_Model_Session')->getMessages(true); + unset($this->_model); + } + + /** + * @magentoAppIsolation enabled + * @magentoDbIsolation enabled + */ + public function testSaveActionCreateNewTemplateAndVerifySuccessMessage() + { + $this->_model->loadByCode('some_unique_code'); + $this->getRequest()->setParam('id', $this->_model->getId()); + $this->dispatch('backend/admin/newsletter_template/save'); + /** + * Check that errors was generated and set to session + */ + $this->assertEmpty(Mage::getSingleton('Mage_Backend_Model_Session')->getMessages(false)->getErrors()); + /** + * Check that success message is set + */ + $successMessages = Mage::getSingleton('Mage_Backend_Model_Session') + ->getMessages(false)->getItemsByType(Mage_Core_Model_Message::SUCCESS); + $this->assertCount(1, $successMessages, 'Success message was not set'); + $this->assertEquals('The newsletter template has been saved.', current($successMessages)->getCode()); + } + + /** + * @magentoAppIsolation enabled + * @magentoDataFixture Mage/Adminhtml/controllers/_files/newsletter_sample.php + */ + public function testSaveActionEditTemplateAndVerifySuccessMessage() + { + $this->_model->loadByCode('some_unique_code'); + $this->getRequest()->setParam('id', $this->_model->getId()); + $this->dispatch('backend/admin/newsletter_template/save'); + + /** + * Check that errors was generated and set to session + */ + $this->assertEmpty(Mage::getSingleton('Mage_Backend_Model_Session')->getMessages(false)->getErrors()); + + /** + * Check that success message is set + */ + $successMessages = Mage::getSingleton('Mage_Backend_Model_Session') + ->getMessages(false)->getItemsByType(Mage_Core_Model_Message::SUCCESS); + $this->assertCount(1, $successMessages, 'Success message was not set'); + $this->assertEquals('The newsletter template has been saved.', current($successMessages)->getCode()); + } + + /** + * @magentoAppIsolation enabled + * @magentoDbIsolation enabled + */ + public function testSaveActionTemplateWithInvalidDataAndVerifySuccessMessage() + { + $post = array('code'=>'test data', + 'subject'=>'test data2', + 'sender_email'=>'sender_email.com', + 'sender_name'=>'Test Sender Name', + 'text'=>'Template Content'); + $this->getRequest()->setPost($post); + $this->dispatch('backend/admin/newsletter_template/save'); + + /** + * Check that errors was generated and set to session + */ + Mage::getSingleton('Mage_Backend_Model_Session')->getMessages(false)->getErrors(); + + /** + * Check that success message is not set + */ + $successMessages = Mage::getSingleton('Mage_Backend_Model_Session') + ->getMessages(false)->getItemsByType(Mage_Core_Model_Message::SUCCESS); + $this->assertEmpty($successMessages); + } + + /** + * @magentoAppIsolation enabled + * @magentoDataFixture Mage/Adminhtml/controllers/_files/newsletter_sample.php + */ + public function testDeleteActionTemplateAndVerifySuccessMessage() + { + $this->_model->loadByCode('some_unique_code'); + $this->getRequest()->setParam('id', $this->_model->getId()); + $this->dispatch('backend/admin/newsletter_template/delete'); + + /** + * Check that errors was generated and set to session + */ + $this->assertEmpty(Mage::getSingleton('Mage_Backend_Model_Session')->getMessages(false)->getErrors()); + + /** + * Check that success message is set + */ + $successMessages = Mage::getSingleton('Mage_Backend_Model_Session') + ->getMessages(false)->getItemsByType(Mage_Core_Model_Message::SUCCESS); + $this->assertCount(1, $successMessages, 'Success message was not set'); + $this->assertEquals('The newsletter template has been deleted.', current($successMessages)->getCode()); + } +} diff --git a/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/UrlrewriteControllerTest.php b/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/_files/newsletter_sample.php similarity index 53% rename from dev/tests/integration/testsuite/Mage/Adminhtml/controllers/UrlrewriteControllerTest.php rename to dev/tests/integration/testsuite/Mage/Adminhtml/controllers/_files/newsletter_sample.php index 1369a4e26cf5a..cfb9c811b0907 100644 --- a/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/UrlrewriteControllerTest.php +++ b/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/_files/newsletter_sample.php @@ -24,27 +24,16 @@ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** @var Mage_Newsletter_Model_Template $template */ +$template = Mage::getModel('Mage_Newsletter_Model_Template'); -class Mage_Adminhtml_UrlrewriteControllerTest extends Mage_Adminhtml_Utility_Controller -{ - /** - * Test presence of edit form - */ - public function testEditActionIsFormPresent() - { - $this->dispatch('backend/admin/urlrewrite/edit/id'); - $response = $this->getResponse()->getBody(); - // Check that there is only one instance of edit_form - $this->assertSelectCount('form#edit_form', 1, $response); - // Check edit form attributes - $saveUrl = Mage::helper('Mage_Adminhtml_Helper_Data')->getUrl('*/urlrewrite/save'); - $this->assertTag(array( - 'tag' => 'form', - 'attributes' => array( - 'id' => 'edit_form', - 'method' => 'post', - 'action' => $saveUrl - ) - ), $response, 'Edit form does not contain all required attributes'); - } -} +$templateData = array( + 'template_code'=>'some_unique_code', + 'template_type'=>Mage_Newsletter_Model_Template::TYPE_TEXT, + 'subject'=>'test data2__22', + 'template_sender_email'=>'sender@email.com', + 'template_sender_name'=>'Test Sender Name 222', + 'text'=>'Template Content 222', +); +$template->setData($templateData); +$template->save(); diff --git a/dev/tests/integration/testsuite/Mage/Core/Model/AppTest.php b/dev/tests/integration/testsuite/Mage/Core/Model/AppTest.php index 2c996be2fe9d7..1b475f54052d8 100644 --- a/dev/tests/integration/testsuite/Mage/Core/Model/AppTest.php +++ b/dev/tests/integration/testsuite/Mage/Core/Model/AppTest.php @@ -88,12 +88,30 @@ public function testGetCookie() $this->assertInstanceOf('Mage_Core_Model_Cookie', $this->_model->getCookie()); } - public function testIsSingleStoreMode() + /** + * @magentoAppIsolation enabled + * @magentoConfigFixture current_store general/single_store_mode/enabled 1 + */ + public function testIsSingleStoreModeWhenEnabled() { - $this->assertNull($this->_model->isSingleStoreMode()); $this->assertTrue($this->_mageModel->isSingleStoreMode()); } + /** + * @magentoAppIsolation enabled + * @magentoConfigFixture current_store general/single_store_mode/enabled 0 + */ + public function testIsSingleStoreModeWhenDisabled() + { + $this->assertFalse($this->_mageModel->isSingleStoreMode());; + } + + public function testHasSingleStore() + { + $this->assertNull($this->_model->hasSingleStore()); + $this->assertTrue($this->_mageModel->hasSingleStore()); + } + public function testSetCurrentStore() { $store = new Mage_Core_Model_Store(); diff --git a/dev/tests/integration/testsuite/Mage/Core/Model/CacheTest.php b/dev/tests/integration/testsuite/Mage/Core/Model/CacheTest.php index 4959e062b8496..ce98f907af42f 100644 --- a/dev/tests/integration/testsuite/Mage/Core/Model/CacheTest.php +++ b/dev/tests/integration/testsuite/Mage/Core/Model/CacheTest.php @@ -35,48 +35,26 @@ class Mage_Core_Model_CacheTest extends PHPUnit_Framework_TestCase public function setUp() { $this->_model = new Mage_Core_Model_Cache(); - - /* Setup preconditions: $this->_model->canUse('config') is true */ - $this->_model->save(serialize(array('config' => true)), Mage_Core_Model_Cache::OPTIONS_CACHE_ID); } public function tearDown() { - /* Cleanup all cached data */ - $this->_model->flush(); $this->_model = null; } - /** - * @dataProvider constructorDataProvider - */ - public function testConstructor(array $options, $expectedBackendClass) + public function testConstructorBackendDatabase() { - $model = new Mage_Core_Model_Cache($options); - + $model = new Mage_Core_Model_Cache(array('backend' => 'Database')); $backend = $model->getFrontend()->getBackend(); - $this->assertInstanceOf($expectedBackendClass, $backend); - } - - /** - * @return array - */ - public function constructorDataProvider() - { - return array( - array(array(), 'Zend_Cache_Backend_File'), - array(array('backend' => 'File'), 'Zend_Cache_Backend_File'), - array(array('backend' => 'File', 'backend_options' => array()), 'Zend_Cache_Backend_File'), - array(array('backend' => 'Database'), 'Varien_Cache_Backend_Database'), - ); + $this->assertInstanceOf('Varien_Cache_Backend_Database', $backend); } /** * @param string $optionCode * @param string $extensionRequired - * @dataProvider backendTwoLevelsDataProvider + * @dataProvider constructorBackendTwoLevelsDataProvider */ - public function testBackendTwoLevels($optionCode, $extensionRequired) + public function testConstructorBackendTwoLevels($optionCode, $extensionRequired) { if ($extensionRequired) { if (!extension_loaded($extensionRequired)) { @@ -92,7 +70,7 @@ public function testBackendTwoLevels($optionCode, $extensionRequired) /** * @return array */ - public function backendTwoLevelsDataProvider() + public function constructorBackendTwoLevelsDataProvider() { return array( array('Memcached', 'memcached'), @@ -100,242 +78,8 @@ public function backendTwoLevelsDataProvider() ); } - public function testGetFrontend() - { - $frontend = $this->_model->getFrontend(); - $this->assertInstanceOf('Varien_Cache_Core', $frontend); - } - - public function testLoadSaveRemove() - { - $this->assertFalse($this->_model->load('non_existing_cache_id')); - - $cacheId = 'cache_id_' . __METHOD__; - $expectedData = "Some data for $cacheId"; - - $this->assertTrue($this->_model->save($expectedData, $cacheId)); - $this->assertEquals($expectedData, $this->_model->load($cacheId)); - - $this->_model->remove($cacheId); - $this->assertFalse($this->_model->load($cacheId)); - } - - /** - * @dataProvider cleanDataProvider - */ - public function testClean(array $cacheData, array $cleanCacheTags, array $expectedCacheIds) - { - /* Fill cache with predefined tagged data */ - foreach ($cacheData as $cacheId => $cacheTags) { - $this->_model->save("data_for_$cacheId", $cacheId, $cacheTags); - } - - /* Clean cache by tags */ - $this->_model->clean($cleanCacheTags); - - /* Check removed data */ - foreach (array_keys($cacheData) as $cacheId) { - $cacheData = $this->_model->load($cacheId); - if (in_array($cacheId, $expectedCacheIds)) { - $this->assertNotEmpty($cacheData); - } else { - $this->assertFalse($cacheData); - } - } - } - - public function cleanDataProvider() - { - $cacheData = array( - 'cache_id_1' => array('unique_tag_1'), - 'cache_id_2' => array('shared_tag'), - 'cache_id_3' => array(), - 'cache_id_4' => array('unique_tag_4', 'shared_tag'), - 'cache_id_5' => array('unique_tag_5'), - ); - return array( - 'no tags' => array( - $cacheData, - array(), - array() - ), - 'app tag' => array( - $cacheData, - array(Mage_Core_Model_App::CACHE_TAG), - array() - ), - 'unique tag' => array( - $cacheData, - array('unique_tag_1'), - array('cache_id_2', 'cache_id_3', 'cache_id_4', 'cache_id_5') - ), - 'few unique tags' => array( - $cacheData, - array('unique_tag_1', 'unique_tag_5'), - array('cache_id_2', 'cache_id_3', 'cache_id_4') - ), - 'shared tag' => array( - $cacheData, - array('shared_tag'), - array('cache_id_1', 'cache_id_3', 'cache_id_5') - ) - ); - } - - public function testFlush() - { - $this->_model->save('data_for_cache_id_1', 'cache_id_1', array('tag_1')); - $this->_model->save('data_for_cache_id_2', 'cache_id_2', array('tag_2')); - $this->_model->save('data_for_cache_id_3', 'cache_id_3'); - $this->_model->flush(); - $this->assertFalse($this->_model->load('cache_id_1')); - $this->assertFalse($this->_model->load('cache_id_2')); - $this->assertFalse($this->_model->load('cache_id_3')); - } - public function testGetDbAdapter() { $this->assertInstanceOf('Zend_Db_Adapter_Abstract', $this->_model->getDbAdapter()); } - - /** - * @return Mage_Core_Model_Cache - */ - public function testCanUse() - { - $this->assertEquals(array('config' => true), $this->_model->canUse('')); - $this->assertTrue($this->_model->canUse('config')); - return $this->_model; - } - - /** - * @depends testCanUse - * @param Mage_Core_Model_Cache $model - * @return Mage_Core_Model_CacheTest - */ - public function testBanUse(Mage_Core_Model_Cache $model) - { - $this->assertTrue($model->canUse('config')); - $model->banUse('config'); - $this->assertFalse($model->canUse('config')); - return $model; - } - - /** - * @depends testBanUse - * @param Mage_Core_Model_Cache $model - */ - public function testAllowUse(Mage_Core_Model_Cache $model) - { - $this->assertFalse($model->canUse('config')); - $model->allowUse('config'); - $this->assertTrue($model->canUse('config')); - } - - /** - * @dataProvider getTagsByTypeDataProvider - */ - public function testGetTagsByType($cacheType, $expectedTags) - { - $actualTags = $this->_model->getTagsByType($cacheType); - $this->assertEquals($expectedTags, $actualTags); - } - - public function getTagsByTypeDataProvider() - { - return array( - array('config', array('CONFIG')), - array('layout', array('LAYOUT_GENERAL_CACHE_TAG')), - array('block_html', array('BLOCK_HTML')), - array('translate', array('TRANSLATE')), - array('collections', array('COLLECTION_DATA')), - array('non-existing', false), - ); - } - - public function testGetTypes() - { - /* Expect cache types introduced by Mage_Core module which can not be disabled */ - $expectedCacheTypes = array('config', 'layout', 'block_html', 'translate', 'collections'); - $expectedKeys = array('id', 'cache_type', 'description', 'tags', 'status'); - - $actualCacheTypesData = $this->_model->getTypes(); - $actualCacheTypes = array_keys($actualCacheTypesData); - - /* Assert that all expected cache types are present */ - $this->assertEquals($expectedCacheTypes, array_intersect($expectedCacheTypes, $actualCacheTypes)); - - foreach ($actualCacheTypesData as $cacheTypeData) { - /** @var $cacheTypeData Varien_Object */ - $this->assertInstanceOf('Varien_Object', $cacheTypeData); - $this->assertEquals($expectedKeys, array_keys($cacheTypeData->getData())); - } - } - - /** - * @covers Mage_Core_Model_Cache::getInvalidatedTypes - * @covers Mage_Core_Model_Cache::invalidateType - */ - public function testInvalidatedTypes() - { - $this->assertEquals(array(), $this->_model->getInvalidatedTypes()); - - $this->_model->invalidateType('config'); - - $actualCacheTypes = $this->_model->getInvalidatedTypes(); - - $this->assertEquals(array('config'), array_keys($actualCacheTypes)); - $this->assertInstanceOf('Varien_Object', $actualCacheTypes['config']); - } - - public function testCleanType() - { - /* Setup preconditions */ - $this->_model->save('some data with layout cache tag', 'some_cache_id', array('LAYOUT_GENERAL_CACHE_TAG')); - $this->_model->invalidateType('layout'); - - $this->_model->cleanType('layout'); - - $this->assertFalse($this->_model->load('some_cache_id')); - $this->assertEquals(array(), $this->_model->getInvalidatedTypes()); - } - - public function testProcessRequestFalse() - { - $model = new Mage_Core_Model_Cache(array()); - $this->assertFalse($model->processRequest()); - - $model = new Mage_Core_Model_Cache(array( - 'request_processors' => array('Mage_Core_Model_CacheTestRequestProcessor'), - )); - Mage_Core_Model_CacheTestRequestProcessor::$isEnabled = false; - $this->assertFalse($model->processRequest()); - } - - public function testProcessRequestTrue() - { - if (!Magento_Test_Bootstrap::canTestHeaders()) { - $this->markTestSkipped('Test requires to send headers.'); - } - $model = new Mage_Core_Model_Cache(array( - 'request_processors' => array('Mage_Core_Model_CacheTestRequestProcessor'), - )); - Mage_Core_Model_CacheTestRequestProcessor::$isEnabled = true; - $this->assertTrue($model->processRequest()); - } - -} - -class Mage_Core_Model_CacheTestRequestProcessor -{ - public static $isEnabled; - - public function extractContent($content) - { - if (self::$isEnabled && $content === false) { - return 'some content from cache'; - } - return $content; - } } - diff --git a/dev/tests/integration/testsuite/Mage/Core/Model/Resource/Db/Collection/AbstractTest.php b/dev/tests/integration/testsuite/Mage/Core/Model/Resource/Db/Collection/AbstractTest.php new file mode 100644 index 0000000000000..60d33cf7eaa22 --- /dev/null +++ b/dev/tests/integration/testsuite/Mage/Core/Model/Resource/Db/Collection/AbstractTest.php @@ -0,0 +1,69 @@ +getMockForAbstractClass('Mage_Core_Model_Resource_Db_Abstract', + array(), '', true, true, true, array('getMainTable', 'getIdFieldName') + ); + + $resource->expects($this->any()) + ->method('getMainTable') + ->will($this->returnValue($resource->getTable('core_website'))); + $resource->expects($this->any()) + ->method('getIdFieldName') + ->will($this->returnValue('website_id')); + + $this->_model = $this->getMockForAbstractClass( + 'Mage_Core_Model_Resource_Db_Collection_Abstract', + array($resource) + ); + } + + protected function tearDown() + { + $this->_model = null; + } + + public function testGetAllIds() + { + $allIds = $this->_model->getAllIds(); + sort($allIds); + $this->assertEquals(array('0', '1'), $allIds); + } + + public function testGetAllIdsWithBind() + { + $this->_model->getSelect()->where('code = :code'); + $this->_model->addBindParam('code', 'admin'); + $this->assertEquals(array('0'), $this->_model->getAllIds()); + } +} diff --git a/dev/tests/integration/testsuite/Mage/DesignEditor/Model/History/CompactTest.php b/dev/tests/integration/testsuite/Mage/DesignEditor/Model/History/CompactTest.php new file mode 100644 index 0000000000000..11d8f4a21915e --- /dev/null +++ b/dev/tests/integration/testsuite/Mage/DesignEditor/Model/History/CompactTest.php @@ -0,0 +1,135 @@ +_historyObject = Mage::getModel('Mage_DesignEditor_Model_History'); + } + + /** + * Test compact + * + * @dataProvider getChanges + */ + public function testCompact($changes, $compactResult) + { + /** @var $historyCompactModel Mage_DesignEditor_Model_History_Compact */ + $historyCompactModel = Mage::getModel('Mage_DesignEditor_Model_History_Compact'); + /** @var $collection Mage_DesignEditor_Model_Change_Collection */ + $collection = $this->_historyObject->setChanges($changes)->getChanges(); + + $historyCompactModel->compact($collection); + + $this->assertEquals($compactResult, $collection->toArray()); + } + + /** + * Get changes + * + * @return array + */ + public function getChanges() + { + return array(array( + array( + array( + 'handle' => 'catalog_category_view', + 'type' => 'layout', + 'element_name' => 'category.products', + 'action_name' => 'move', + 'destination_container' => 'content', + 'destination_order' => '-', + 'origin_container' => 'top.menu', + 'origin_order' => '-' + ), + array( + 'handle' => 'catalog_category_view', + 'type' => 'layout', + 'element_name' => 'category.products', + 'action_name' => 'move', + 'destination_container' => 'right', + 'destination_order' => '-', + 'origin_container' => 'content', + 'origin_order' => '-' + ), + array( + 'handle' => 'customer_account', + 'type' => 'layout', + 'element_name' => 'customer_account_navigation', + 'action_name' => 'move', + 'destination_container' => 'content', + 'destination_order' => '-', + 'origin_container' => 'right', + 'origin_order' => '-' + ), + array( + 'handle' => 'customer_account', + 'type' => 'layout', + 'element_name' => 'customer_account_navigation', + 'action_name' => 'remove', + ), + array( + 'handle' => 'customer_account', + 'type' => 'layout', + 'element_name' => 'customer_account_navigation', + 'action_name' => 'remove', + ), + ), + /** Expected result for compact */ + array( + array( + 'handle' => 'catalog_category_view', + 'type' => 'layout', + 'element_name' => 'category.products', + 'action_name' => 'move', + 'destination_container' => 'right', + 'destination_order' => '-', + 'origin_container' => 'content', + 'origin_order' => '-' + ), + array( + 'handle' => 'customer_account', + 'type' => 'layout', + 'element_name' => 'customer_account_navigation', + 'action_name' => 'remove', + ), + ) + )); + } +} diff --git a/dev/tests/integration/testsuite/Mage/DesignEditor/Model/HistoryTest.php b/dev/tests/integration/testsuite/Mage/DesignEditor/Model/HistoryTest.php index 3de267e5c6ee7..fbb1ae6070cbb 100644 --- a/dev/tests/integration/testsuite/Mage/DesignEditor/Model/HistoryTest.php +++ b/dev/tests/integration/testsuite/Mage/DesignEditor/Model/HistoryTest.php @@ -32,147 +32,163 @@ class Mage_DesignEditor_Model_HistoryTest extends PHPUnit_Framework_TestCase */ protected $_historyObject; - public function setUp() + /** + * Get clear history model + * + * @return Mage_DesignEditor_Model_History + */ + protected function getClearHistoryModel() + { + return $this->_historyObject = Mage::getModel('Mage_DesignEditor_Model_History'); + } + + /** + * Add change test + * + * @dataProvider getChange + */ + public function testAddChange($change) { - $this->_historyObject = Mage::getModel('Mage_DesignEditor_Model_History'); + $historyModel = $this->getClearHistoryModel(); + $collection = $historyModel->addChange($change)->getChanges(); + + $this->assertEquals(array($change), $collection->toArray()); } /** - * @dataProvider getChangeLogData + * Add change with invalid data test + * + * @dataProvider getInvalidChange + * @expectedException Magento_Exception */ - public function testGetCompactLog($changes) + public function testAddChangeWithInvalidData($change) { - $historyObject = $this->_historyObject; - $historyObject->setChangeLog($changes); - $this->assertEquals($this->getCompactedChangeLogData(), $historyObject->getCompactLog()); + $historyModel = $this->getClearHistoryModel(); + $historyModel->addChange($change)->getChanges(); } /** - * @dataProvider getInvalidChangeLogData - * @expectedException Mage_DesignEditor_Exception + * Set changes test + * + * @dataProvider getChanges */ - public function testGetCompactLogInvalidData($changes) + public function testSetChanges($changes) { - $historyObject = $this->_historyObject; - $historyObject->setChangeLog($changes); - $historyObject->getCompactLog(); + $historyModel = $this->getClearHistoryModel(); + $collection = $historyModel->setChanges($changes)->getChanges(); + + $this->assertEquals($changes, $collection->toArray()); } /** - * @dataProvider getChangeLogData + * Test output(renderer) + * + * @dataProvider getChanges */ - public function testGetCompactXml($changes) + public function testOutput($changes) { - $historyObject = $this->_historyObject; - $historyObject->setChangeLog($changes); + $historyModel = $this->getClearHistoryModel(); + /** @var $layoutRenderer Mage_DesignEditor_Model_History_Renderer_LayoutUpdate */ + $layoutRenderer = Mage::getModel('Mage_DesignEditor_Model_History_Renderer_LayoutUpdate'); + + /** @var $collection Mage_DesignEditor_Model_Change_Collection */ + $collection = $historyModel->setChanges($changes)->getChanges(); + + /** @var $historyCompactModel Mage_DesignEditor_Model_History_Compact */ + $historyCompactModel = Mage::getModel('Mage_DesignEditor_Model_History_Compact'); + $historyCompactModel->compact($collection); + $this->assertXmlStringEqualsXmlFile( - realpath(__DIR__) . '/../_files/history/compact_log.xml', $historyObject->getCompactXml() + realpath(__DIR__) . '/../_files/history/layout_renderer.xml', $historyModel->output($layoutRenderer) ); } /** - * @dataProvider getInvalidChangeLogData - * @expectedException Mage_DesignEditor_Exception + * Get change + * + * @return array */ - public function testGetCompactXmlInvalidData($changes) + public function getChange() { - $historyObject = $this->_historyObject; - $historyObject->setChangeLog($changes); - $historyObject->getCompactXml(); + return array(array( + array( + 'handle' => 'customer_account', + 'type' => 'layout', + 'element_name' => 'customer_account_navigation', + 'action_name' => 'move', + 'destination_container' => 'content', + 'destination_order' => '-', + 'origin_container' => 'top.menu', + 'origin_order' => '-' + ), + )); } - public function getChangeLogData() + /** + * Get invalid change + * + * @return array + */ + public function getInvalidChange() { return array(array( array( - array( - 'handle' => 'catalog_category_view', - 'change_type' => 'layout', - 'element_name' => 'category.products', - 'action_name' => 'move', - 'action_data' => array( - 'destination_container' => 'content', - 'after' => '-', - ), - ), - array( - 'handle' => 'catalog_category_view', - 'change_type' => 'layout', - 'element_name' => 'category.products', - 'action_name' => 'remove', - 'action_data' => array(), - ), - array( - 'handle' => 'customer_account', - 'change_type' => 'layout', - 'element_name' => 'customer_account_navigation', - 'action_name' => 'move', - 'action_data' => array( - 'destination_container' => 'content', - 'after' => '-', - 'as' => 'customer_account_navigation_alias', - ), - ), - array( - 'handle' => 'customer_account', - 'change_type' => 'layout', - 'element_name' => 'customer_account_navigation', - 'action_name' => 'move', - 'action_data' => array( - 'destination_container' => 'top.menu', - 'after' => '-', - 'as' => 'customer_account_navigation_alias', - ), - ), + 'handle' => 'customer_account', + 'type' => '', + 'element_name' => '', + 'action_name' => 'move', + 'destination_container' => 'content', + 'destination_order' => '-', + 'origin_container' => 'top.menu', + 'origin_order' => '-' ), )); } - public function getCompactedChangeLogData() + /** + * Get changes + * + * @return array + */ + public function getChanges() { - return array( + return array(array(array( array( - 'handle' => 'catalog_category_view', - 'change_type' => 'layout', - 'element_name' => 'category.products', - 'action_name' => 'remove', - 'action_data' => array(), + 'handle' => 'customer_account', + 'type' => 'layout', + 'element_name' => 'customer_account_navigation', + 'action_name' => 'move', + 'destination_container' => 'content', + 'destination_order' => '-', + 'origin_container' => 'top.menu', + 'origin_order' => '-' ), array( - 'handle' => 'customer_account', - 'change_type' => 'layout', - 'element_name' => 'customer_account_navigation', - 'action_name' => 'move', - 'action_data' => array( - 'destination_container' => 'top.menu', - 'after' => '-', - 'as' => 'customer_account_navigation_alias', - ), + 'handle' => 'customer_account', + 'type' => 'layout', + 'element_name' => 'customer_account_navigation', + 'action_name' => 'move', + 'destination_container' => 'right', + 'destination_order' => '-', + 'origin_container' => 'content', + 'origin_order' => '-' ), - ); - } - - public function getInvalidChangeLogData() - { - return array(array( array( - array( - 'handle' => 'catalog_category_view', - 'change_type' => 'layout', - 'element_name' => 'category.products', - 'action_name' => 'move', - 'action_data' => array( - 'destination_container' => 'content', - 'after' => '-', - ), - ), - array( - 'handle' => '', - 'change_type' => '', - 'element_name' => '', - 'action_name' => '', - ), + 'handle' => 'catalog_category_view', + 'type' => 'layout', + 'element_name' => 'category.products', + 'action_name' => 'move', + 'destination_container' => 'content', + 'destination_order' => '-', + 'origin_container' => 'right', + 'origin_order' => '-' ), - )); + array( + 'handle' => 'catalog_category_view', + 'type' => 'layout', + 'element_name' => 'category.products', + 'action_name' => 'remove', + ), + ))); } } diff --git a/dev/tests/integration/testsuite/Mage/DesignEditor/_files/history/compact_log.xml b/dev/tests/integration/testsuite/Mage/DesignEditor/_files/history/layout_renderer.xml similarity index 90% rename from dev/tests/integration/testsuite/Mage/DesignEditor/_files/history/compact_log.xml rename to dev/tests/integration/testsuite/Mage/DesignEditor/_files/history/layout_renderer.xml index 90e4508c24588..cb845ff88ab96 100644 --- a/dev/tests/integration/testsuite/Mage/DesignEditor/_files/history/compact_log.xml +++ b/dev/tests/integration/testsuite/Mage/DesignEditor/_files/history/layout_renderer.xml @@ -27,10 +27,10 @@ */ --> + + + - - - diff --git a/dev/tests/static/testsuite/Integrity/ConfigTest.php b/dev/tests/static/testsuite/Integrity/ConfigTest.php index acc9a656b0aab..f445309c62dcf 100644 --- a/dev/tests/static/testsuite/Integrity/ConfigTest.php +++ b/dev/tests/static/testsuite/Integrity/ConfigTest.php @@ -37,14 +37,8 @@ class Integrity_ConfigTest extends PHPUnit_Framework_TestCase */ public function testDeclaredLocales() { - $configFiles = Utility_Files::init()->getConfigFiles('config.xml', array(), false); $verifiedFiles = array(); - foreach ($configFiles as $configFile) { - preg_match('/\/([^\/]+?\/[^\/]+?)\/etc\/config\.xml$/', $configFile, $moduleName); - $moduleName = str_replace('/', '_', $moduleName[1]); - if (in_array($moduleName, self::$_brokenModules)) { - continue; - } + foreach ($this->_getConfigFilesPerModule() as $configFile => $moduleName) { $config = simplexml_load_file($configFile); $nodes = $config->xpath("/config/*/translate/modules/{$moduleName}/files/*") ?: array(); foreach ($nodes as $node) { @@ -78,4 +72,49 @@ public function testExistingFilesDeclared($verifiedFiles) 'Translation files exist, but not declared in configuration:' . "\n" . var_export($failures, 1) ); } + + /** + * Verify whether all payment methods are declared in appropriate modules + * + * @dataProvider paymentMethodsDataProvider + */ + public function testPaymentMethods($configFile, $moduleName) + { + $config = simplexml_load_file($configFile); + $nodes = $config->xpath('/config/default/payment/*/model') ?: array(); + foreach ($nodes as $node) { + $this->assertStringStartsWith($moduleName . '_Model_', (string)$node, + "'$node' payment method is declared in '$configFile' module, but doesn't belong to '$moduleName' module" + ); + } + } + + public function paymentMethodsDataProvider() + { + $data = array(); + foreach ($this->_getConfigFilesPerModule() as $configFile => $moduleName) { + $data[] = array($configFile, $moduleName); + } + return $data; + } + + /** + * Get list of configuration files associated with modules + * + * @return array + */ + protected function _getConfigFilesPerModule() + { + $configFiles = Utility_Files::init()->getConfigFiles('config.xml', array(), false); + $data = array(); + foreach ($configFiles as $configFile) { + preg_match('#/([^/]+?/[^/]+?)/etc/config\.xml$#', $configFile, $moduleName); + $moduleName = str_replace('/', '_', $moduleName[1]); + if (in_array($moduleName, self::$_brokenModules)) { + continue; + } + $data[$configFile] = $moduleName; + } + return $data; + } } diff --git a/dev/tests/static/testsuite/Php/_files/whitelist/core.txt b/dev/tests/static/testsuite/Php/_files/whitelist/core.txt index 70dbef97cb694..c250c47478bca 100644 --- a/dev/tests/static/testsuite/Php/_files/whitelist/core.txt +++ b/dev/tests/static/testsuite/Php/_files/whitelist/core.txt @@ -1,12 +1,14 @@ app/bootstrap.php app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Popup/Grid.php app/code/core/Mage/Adminhtml/Block/Catalog/Product/Options/Ajax.php +app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php app/code/core/Mage/Adminhtml/Model/Observer.php app/code/core/Mage/Adminhtml/Block/Urlrewrite app/code/core/Mage/Adminhtml/Block/controllers/UrlrewriteController.php app/code/core/Mage/Adminhtml/Block/Page/System/Config/Robots/Reset.php app/code/core/Mage/Adminhtml/Block/System/Store/Edit app/code/core/Mage/Adminhtml/Block/System/Store/Edit.php +app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field.php app/code/core/Mage/Core/Block/Abstract.php app/code/core/Mage/Centinel/Model/State/Jcb.php app/code/core/Mage/Core/Model/Config/Module.php diff --git a/dev/tests/unit/framework/bootstrap.php b/dev/tests/unit/framework/bootstrap.php index 43cdc0f962b45..58d56cead947c 100755 --- a/dev/tests/unit/framework/bootstrap.php +++ b/dev/tests/unit/framework/bootstrap.php @@ -24,6 +24,8 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +require __DIR__ . '/../../../../app/code/core/Mage/Core/functions.php'; + define('TESTS_TEMP_DIR', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'tmp'); $includePaths = array( diff --git a/dev/tests/unit/testsuite/Mage/Adminhtml/Model/ConfigTest.php b/dev/tests/unit/testsuite/Mage/Adminhtml/Model/ConfigTest.php new file mode 100644 index 0000000000000..6ce3aab4e7b78 --- /dev/null +++ b/dev/tests/unit/testsuite/Mage/Adminhtml/Model/ConfigTest.php @@ -0,0 +1,82 @@ +getMock('Mage_Core_Model_App', array('isSingleStoreMode'), array(), '', true); + $app->expects($this->any()) + ->method('isSingleStoreMode') + ->will($this->returnValue($isSingleStoreMode)); + + $config = new Mage_Adminhtml_Model_Config(array( + 'data' => $xmlData, + 'app' => $app, + )); + $result = $config->hasChildren($node, $website, $store); + $this->assertEquals($expectedResult, $result, $message); + } + + public function addItemFilterDataProvider() + { + $data = file_get_contents(__DIR__ . '/_files/system.xml'); + $xmlData = new Varien_Simplexml_Element($data); + return array( + array($xmlData, false, $xmlData->sections->dev, null, null, true, 'Case 1'), + array($xmlData, false, $xmlData->sections->dev->groups->css, null, null, true, 'Case 2'), + array($xmlData, false, $xmlData->sections->dev->groups->css, 'base', null, true, 'Case 3'), + array($xmlData, false, $xmlData->sections->dev->groups->css, 'base', 'default', true, 'Case 4'), + array($xmlData, false, $xmlData->sections->dev->groups->debug, null, null, false, 'Case 5'), + array($xmlData, false, $xmlData->sections->dev->groups->debug, 'base', null, true, 'Case 6'), + array($xmlData, false, $xmlData->sections->dev->groups->debug, 'base', 'default', true, 'Case 7'), + array($xmlData, false, $xmlData->sections->dev->groups->js, null, null, false, 'Case 8'), + array($xmlData, false, $xmlData->sections->dev->groups->js, 'base', null, false, 'Case 9'), + array($xmlData, false, $xmlData->sections->dev->groups->js, 'base', 'default', true, 'Case 10'), + array($xmlData, true, $xmlData->sections->dev->groups->debug, null, null, true, 'Case 11'), + array($xmlData, true, $xmlData->sections->dev->groups->debug, 'base', null, true, 'Case 12'), + array($xmlData, true, $xmlData->sections->dev->groups->debug, 'base', 'default', true, 'Case 13'), + array($xmlData, true, $xmlData->sections->dev->groups->js, null, null, true, 'Case 14'), + array($xmlData, true, $xmlData->sections->dev->groups->js, 'base', null, true, 'Case 15'), + array($xmlData, true, $xmlData->sections->dev->groups->js, 'base', 'default', true, 'Case 16'), + array($xmlData, true, $xmlData->sections->dev->groups->price, null, null, false, 'Case 17'), + array($xmlData, true, $xmlData->sections->dev->groups->price, 'base', null, false, 'Case 17'), + array($xmlData, true, $xmlData->sections->dev->groups->price, 'base', 'default', false, 'Case 17'), + ); + } +} diff --git a/dev/tests/unit/testsuite/Mage/Adminhtml/Model/_files/system.xml b/dev/tests/unit/testsuite/Mage/Adminhtml/Model/_files/system.xml new file mode 100644 index 0000000000000..dc3b24fe8c6c6 --- /dev/null +++ b/dev/tests/unit/testsuite/Mage/Adminhtml/Model/_files/system.xml @@ -0,0 +1,143 @@ + + + + + + + 100 + + + + 99999 + + + + 999999 + + + + + + advanced + text + 920 + 1 + 1 + 1 + Mage_Adminhtml::dev + + + + text + 20 + 1 + 1 + 1 + + + + select + Mage_Adminhtml_Model_System_Config_Source_Yesno + 20 + 0 + 1 + 1 + + + + select + Mage_Adminhtml_Model_System_Config_Source_Yesno + 21 + 0 + 1 + 1 + + + + + + text + 110 + 1 + 1 + 1 + + + + select + Mage_Adminhtml_Model_System_Config_Source_Yesno + 10 + 1 + 1 + 1 + + + + + + text + 100 + 1 + 1 + 1 + + + + select + Mage_Adminhtml_Model_System_Config_Source_Yesno + 10 + 0 + 0 + 1 + + + + + + text + 100 + 1 + 1 + 1 + + + + select + Mage_Adminhtml_Model_System_Config_Source_Yesno + 10 + 1 + 0 + 0 + 1 + + + + + + + diff --git a/dev/tests/unit/testsuite/Mage/Backend/Model/Menu/ConfigTest.php b/dev/tests/unit/testsuite/Mage/Backend/Model/Menu/ConfigTest.php index 6df98c2f5d477..4f7a4319ffd29 100644 --- a/dev/tests/unit/testsuite/Mage/Backend/Model/Menu/ConfigTest.php +++ b/dev/tests/unit/testsuite/Mage/Backend/Model/Menu/ConfigTest.php @@ -56,7 +56,7 @@ class Mage_Backend_Model_Menu_ConfigTest extends PHPUnit_Framework_TestCase /** * @var Mage_Backend_Model_Menu_Builder */ - protected $_builderMock; + protected $_menuFactoryMock; /** * @var PHPUnit_Framework_MockObject_MockObject @@ -68,6 +68,16 @@ class Mage_Backend_Model_Menu_ConfigTest extends PHPUnit_Framework_TestCase */ protected $_itemFactoryMock; + /** + * @var PHPUnit_Framework_MockObject_MockObject + */ + protected $_menuMock; + + /** + * @var PHPUnit_Framework_MockObject_MockObject + */ + protected $_menuBuilderMock; + /** * @var PHPUnit_Framework_MockObject_MockObject */ @@ -89,7 +99,7 @@ public function setUp() $this->_directorDomMock = $this->getMock('Mage_Backend_Model_Menu_Director_Dom', array(), array(), '', false); - $this->_builderMock = $this->getMock('Mage_Backend_Model_Menu_Builder', array(), array(), '', false); + $this->_menuFactoryMock = $this->getMock('Mage_Backend_Model_Menu_Factory', array(), array(), '', false); $this->_configMenuMock = $this->getMock('Mage_Backend_Model_Menu_Config_Menu', array(), array(), '', false); @@ -99,11 +109,19 @@ public function setUp() $this->_logger = $this->getMock('Mage_Backend_Model_Menu_Logger'); + $this->_menuMock = $this->getMock('Mage_Backend_Model_Menu', array(), array(), '', false); + + $this->_menuBuilderMock = $this->getMock('Mage_Backend_Model_Menu_Builder', array(), array(), '', false); + + $this->_menuFactoryMock->expects($this->any()) + ->method('getMenuInstance') + ->will($this->returnValue($this->_menuMock)); + $this->_model = new Mage_Backend_Model_Menu_Config(array( 'appConfig' => $this->_appConfigMock, 'cache' => $this->_cacheInstanceMock, 'eventManager' => $this->_eventManagerMock, - 'menuBuilder' => $this->_builderMock, + 'menuFactory' => $this->_menuFactoryMock, 'logger' => $this->_logger )); } @@ -120,6 +138,52 @@ public function testGetMenuConfigurationFiles() $this->assertNotEmpty($this->_model->getMenuConfigurationFiles()); } + public function testGetMenuWithCachedObjectReturnsUnserializedObject() + { + $this->_cacheInstanceMock->expects($this->once()) + ->method('canUse') + ->with($this->equalTo('config')) + ->will($this->returnValue(true)); + + $this->_cacheInstanceMock->expects($this->once()) + ->method('load') + ->with($this->equalTo(Mage_Backend_Model_Menu_Config::CACHE_MENU_OBJECT)) + ->will($this->returnValue('menu_cache')); + + $this->_menuMock->expects($this->once()) + ->method('unserialize') + ->with('menu_cache'); + + $this->assertEquals($this->_menuMock, $this->_model->getMenu()); + } + + public function testGetMenuWithNotCachedObjectBuidlsObject() + { + $this->_cacheInstanceMock->expects($this->any()) + ->method('canUse') + ->with($this->equalTo('config')) + ->will($this->returnValue(true)); + + $this->_cacheInstanceMock->expects($this->at(1)) + ->method('load') + ->with($this->equalTo(Mage_Backend_Model_Menu_Config::CACHE_MENU_OBJECT)) + ->will($this->returnValue(false)); + + $this->_configMenuMock->expects($this->exactly(1)) + ->method('getMergedConfig') + ->will($this->returnValue($this->_domDocumentMock)); + + $this->_domDocumentMock->expects($this->exactly(1)) + ->method('saveXML') + ->will($this->returnValue('')); + + $this->_menuBuilderMock->expects($this->exactly(1)) + ->method('getResult') + ->will($this->returnValue($this->_menuMock)); + + $this->assertEquals($this->_menuMock, $this->_model->getMenu()); + } + /** * @covers Mage_Backend_Model_Menu_Config::getMenu */ @@ -127,12 +191,11 @@ public function testGetMenuWhenEnabledCache() { $xmlString = ''; - $this->_cacheInstanceMock->expects($this->any()) - ->method('canUse') - ->with($this->equalTo('config')) - ->will($this->returnValue(true)); + $this->_cacheInstanceMock->expects($this->at(1)) + ->method('load') + ->will($this->returnValue(false)); - $this->_cacheInstanceMock->expects($this->exactly(1)) + $this->_cacheInstanceMock->expects($this->at(1)) ->method('load') ->will($this->returnValue($xmlString)); @@ -140,9 +203,17 @@ public function testGetMenuWhenEnabledCache() ->method('buildMenu') ->with($this->isInstanceOf('Mage_Backend_Model_Menu_Builder')); - $this->_builderMock->expects($this->exactly(1)) + $this->_configMenuMock->expects($this->exactly(1)) + ->method('getMergedConfig') + ->will($this->returnValue($this->_domDocumentMock)); + + $this->_domDocumentMock->expects($this->exactly(1)) + ->method('saveXML') + ->will($this->returnValue('')); + + $this->_menuBuilderMock->expects($this->exactly(1)) ->method('getResult') - ->will($this->returnValue($this->getMock('Mage_Backend_Model_Menu', array(), array(), '', false))); + ->will($this->returnValue($this->_menuMock)); $this->_model->getMenu(); @@ -169,6 +240,10 @@ public function testGetMenuWhenDisabledCache() ->method('saveXML') ->will($this->returnValue('')); + $this->_menuBuilderMock->expects($this->exactly(1)) + ->method('getResult') + ->will($this->returnValue($this->_menuMock)); + $this->_model->getMenu(); } @@ -187,7 +262,7 @@ public function testGetMenuWhenCacheEnabledAndCleaned() ->method('canUse') ->will($this->returnValue(true)); - $this->_cacheInstanceMock->expects($this->exactly(1)) + $this->_cacheInstanceMock->expects($this->any()) ->method('load') ->will($this->returnValue(null)); @@ -199,28 +274,35 @@ public function testGetMenuWhenCacheEnabledAndCleaned() ->method('getMergedConfig') ->will($this->returnValue($this->_domDocumentMock)); - $this->_cacheInstanceMock->expects($this->exactly(1)) + $this->_cacheInstanceMock->expects($this->at(5)) ->method('save') ->with($this->equalTo($xmlString)); + $this->_cacheInstanceMock->expects($this->at(7)) + ->method('save') + ->with($this->equalTo($this->_menuMock->serialize())); + + $this->_menuBuilderMock->expects($this->exactly(1)) + ->method('getResult') + ->will($this->returnValue($this->_menuMock)); + $this->_model->getMenu(); } public function testGetMenuTriggersEventOnlyOnceAfterMenuIsCreated() { - $menuMock = new Varien_Object(); $this->_eventManagerMock->expects($this->once()) ->method('dispatch') - ->with($this->equalTo('backend_menu_load_after'), $this->equalTo(array('menu' => $menuMock))); - - $this->_builderMock->expects($this->once()) - ->method('getResult') - ->will($this->returnValue($menuMock)); + ->with($this->equalTo('backend_menu_load_after'), $this->equalTo(array('menu' => $this->_menuMock))); $this->_configMenuMock->expects($this->once()) ->method('getMergedConfig') ->will($this->returnValue($this->_domDocumentMock)); + $this->_menuBuilderMock->expects($this->exactly(1)) + ->method('getResult') + ->will($this->returnValue($this->_menuMock)); + $this->_model->getMenu(); $this->_model->getMenu(); } @@ -237,7 +319,7 @@ public function testGetMenuInvalidArgumentExceptionLogged() $this->_logger->expects($this->exactly(1))->method('logException') ->with($this->isInstanceOf('InvalidArgumentException')); - $this->_builderMock->expects($this->exactly(1)) + $this->_menuBuilderMock->expects($this->exactly(1)) ->method('getResult') ->will($this->throwException(new InvalidArgumentException())); @@ -252,7 +334,7 @@ public function testGetMenuGenericExceptionIsNotLogged() $this->_logger->expects($this->never())->method('logException'); - $this->_builderMock->expects($this->exactly(1)) + $this->_menuBuilderMock->expects($this->exactly(1)) ->method('getResult') ->will($this->throwException(new Exception())); try { @@ -276,6 +358,8 @@ public function getModelInstance($model, $arguments) return $this->_directorDomMock; } elseif ($model == 'Mage_Backend_Model_Menu_Config_Menu') { return $this->_configMenuMock; + } elseif ($model == 'Mage_Backend_Model_Menu_Builder') { + return $this->_menuBuilderMock; } else { return $this->getMock($model, array(), $arguments, '', false); } diff --git a/dev/tests/unit/testsuite/Mage/Catalog/Model/Category/Attribute/Backend/SortbyTest.php b/dev/tests/unit/testsuite/Mage/Catalog/Model/Category/Attribute/Backend/SortbyTest.php new file mode 100644 index 0000000000000..647377f88a7c2 --- /dev/null +++ b/dev/tests/unit/testsuite/Mage/Catalog/Model/Category/Attribute/Backend/SortbyTest.php @@ -0,0 +1,81 @@ +_model = new Mage_Catalog_Model_Category_Attribute_Backend_Sortby(); + $attribute = $this->getMockForAbstractClass('Mage_Eav_Model_Entity_Attribute_Abstract', + array(), '', false, true, true, array('getName') + ); + $attribute->expects($this->any()) + ->method('getName') + ->will($this->returnValue(self::DEFAULT_ATTRIBUTE_CODE)); + $this->_model->setAttribute($attribute); + } + + protected function tearDown() + { + $this->_model = null; + } + + /** + * @param $data + * @param $expected + * @dataProvider beforeSaveDataProvider + */ + public function testBeforeSave($data, $expected) + { + $object = new Varien_Object($data); + $this->_model->beforeSave($object); + $this->assertTrue($object->hasData(self::DEFAULT_ATTRIBUTE_CODE)); + $this->assertSame($expected, $object->getData(self::DEFAULT_ATTRIBUTE_CODE)); + } + + public function beforeSaveDataProvider() + { + return array( + 'attribute with specified value' => array( + array(self::DEFAULT_ATTRIBUTE_CODE => 'test_value'), + 'test_value', + ), + 'attribute with default value' => array( + array(self::DEFAULT_ATTRIBUTE_CODE => null), + null, + ), + 'attribute does not exist' => array( + array(), + false, + ), + ); + } +} diff --git a/dev/tests/unit/testsuite/Mage/Core/Model/CacheTest.php b/dev/tests/unit/testsuite/Mage/Core/Model/CacheTest.php new file mode 100644 index 0000000000000..b57ebabe257ef --- /dev/null +++ b/dev/tests/unit/testsuite/Mage/Core/Model/CacheTest.php @@ -0,0 +1,455 @@ +_config = new Mage_Core_Model_Config(<< + + + + + + This is Tag One + tag_one + + + + These are Tags One and Two + tag_one,tag_two + + + + + +XML + ); + $this->_helper = $this->getMock('Mage_Core_Helper_Data', array('__')); + $this->_helper + ->expects($this->any()) + ->method('__') + ->will($this->returnArgument(0)) + ; + $this->_config->setOptions(array( + 'cache_dir' => __DIR__, + 'etc_dir' => __DIR__, + )); + $this->_cacheFrontend = $this->getMock( + 'Zend_Cache_Core', array('load', 'test', 'save', 'remove', 'clean', '_getHelper') + ); + $this->_requestProcessor = $this->getMock('stdClass', array('extractContent')); + $this->_model = new Mage_Core_Model_Cache(array( + 'config' => $this->_config, + 'helper' => $this->_helper, + 'frontend' => $this->_cacheFrontend, + 'backend' => 'BlackHole', + 'request_processors' => array($this->_requestProcessor), + )); + } + + public function tearDown() + { + $this->_config = null; + $this->_cacheFrontend = null; + $this->_model = null; + } + + /** + * Force to load desired cache type options + * + * @param array $cacheTypeOptions + */ + protected function _emulateCacheTypeOptions(array $cacheTypeOptions = array('config' => true)) + { + $this->_cacheFrontend + ->expects($this->any()) + ->method('load') + ->with(strtoupper(Mage_Core_Model_Cache::OPTIONS_CACHE_ID)) + ->will($this->returnValue(serialize($cacheTypeOptions))) + ; + } + + /** + * @dataProvider constructorDataProvider + * @param array $options + * @param string $expectedBackendClass + */ + public function testConstructor(array $options, $expectedBackendClass) + { + $options += array('config' => $this->_config, 'helper' => $this->_helper); + $model = new Mage_Core_Model_Cache($options); + + $backend = $model->getFrontend()->getBackend(); + $this->assertInstanceOf($expectedBackendClass, $backend); + } + + /** + * @return array + */ + public function constructorDataProvider() + { + return array( + array(array(), 'Zend_Cache_Backend_File'), + array(array('backend' => 'File'), 'Zend_Cache_Backend_File'), + array(array('backend' => 'File', 'backend_options' => array()), 'Zend_Cache_Backend_File'), + ); + } + + public function testGetFrontend() + { + $frontend = $this->_model->getFrontend(); + $this->assertSame($this->_cacheFrontend, $frontend); + } + + public function testLoad() + { + $this->_cacheFrontend + ->expects($this->once()) + ->method('load') + ->with('TEST_ID') + ->will($this->returnValue('test_data')) + ; + $this->assertEquals('test_data', $this->_model->load('test_id')); + } + + /** + * @dataProvider saveDataProvider + * @param string|mixed $inputData + * @param string $inputId + * @param array $inputTags + * @param string $expectedData + * @param string $expectedId + * @param array $expectedTags + */ + public function testSave($inputData, $inputId, $inputTags, $expectedData, $expectedId, $expectedTags) + { + $this->_cacheFrontend + ->expects($this->once()) + ->method('save') + ->with($this->identicalTo($expectedData), $expectedId, $expectedTags) + ; + $this->_model->save($inputData, $inputId, $inputTags); + } + + public function saveDataProvider() + { + $configTag = Mage_Core_Model_Config::CACHE_TAG; + $appTag = Mage_Core_Model_App::CACHE_TAG; + return array( + 'default tags' => array( + 'test_data', 'test_id', array(), 'test_data', 'TEST_ID', array($appTag) + ), + 'config tags' => array( + 'test_data', 'test_id', array($configTag), 'test_data', 'TEST_ID', array($configTag) + ), + 'lowercase tags' => array( + 'test_data', 'test_id', array('test_tag'), 'test_data', 'TEST_ID', array('TEST_TAG', $appTag) + ), + 'non-string data' => array( + 1234567890, 'test_id', array(), '1234567890', 'TEST_ID', array(Mage_Core_Model_App::CACHE_TAG) + ), + ); + } + + public function testSaveDisallowed() + { + $model = new Mage_Core_Model_Cache(array( + 'config' => $this->_config, + 'helper' => $this->_helper, + 'frontend' => $this->_cacheFrontend, + 'backend' => 'BlackHole', + 'disallow_save' => true + )); + $this->_cacheFrontend + ->expects($this->never()) + ->method('save') + ; + $model->save('test_data', 'test_id'); + } + + /** + * @dataProvider successFailureDataProvider + * @param bool $result + */ + public function testRemove($result) + { + $this->_cacheFrontend + ->expects($this->once()) + ->method('remove') + ->with('TEST_ID') + ->will($this->returnValue($result)) + ; + $this->assertEquals($result, $this->_model->remove('test_ID')); + } + + public function successFailureDataProvider() + { + return array( + 'success' => array(true), + 'failure' => array(false), + ); + } + + /** + * @dataProvider cleanDataProvider + * @param array $inputTags + * @param array $expectedTags + */ + public function testClean(array $inputTags, array $expectedTags) + { + $this->_cacheFrontend + ->expects($this->once()) + ->method('clean') + ->with(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, $expectedTags) + ->will($this->returnValue(false)) + ; + $this->_model->clean($inputTags); + } + + public function cleanDataProvider() + { + return array( + 'default tags' => array(array(), array(Mage_Core_Model_App::CACHE_TAG)), + 'custom tags' => array(array('test_tag'), array('TEST_TAG')), + ); + } + + public function testCleanByConfig() + { + $this->_cacheFrontend + ->expects($this->at(0)) + ->method('clean') + ->with(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array(Mage_Core_Model_App::CACHE_TAG)) + ->will($this->returnValue(true)) + ; + $this->_cacheFrontend + ->expects($this->at(1)) + ->method('clean') + ->with(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array(Mage_Core_Model_Config::CACHE_TAG)) + ->will($this->returnValue(true)) + ; + $this->_model->clean(); + } + + /** + * @dataProvider successFailureDataProvider + * @param bool $result + */ + public function testFlush($result) + { + $this->_cacheFrontend + ->expects($this->once()) + ->method('clean') + ->will($this->returnValue($result)) + ; + $this->assertEquals($result, $this->_model->flush()); + } + + /** + * @return Mage_Core_Model_Cache + */ + public function testCanUse() + { + $this->_emulateCacheTypeOptions(); + $this->assertEquals(array('config' => true), $this->_model->canUse('')); + $this->assertTrue($this->_model->canUse('config')); + return $this->_model; + } + + /** + * @depends testCanUse + * @param Mage_Core_Model_Cache $model + * @return Mage_Core_Model_CacheTest + */ + public function testBanUse(Mage_Core_Model_Cache $model) + { + $this->_emulateCacheTypeOptions(); + $this->assertTrue($model->canUse('config')); + $model->banUse('config'); + $this->assertFalse($model->canUse('config')); + return $model; + } + + /** + * @depends testBanUse + * @param Mage_Core_Model_Cache $model + */ + public function testAllowUse(Mage_Core_Model_Cache $model) + { + $this->_emulateCacheTypeOptions(); + $this->assertFalse($model->canUse('config')); + $model->allowUse('config'); + $this->assertTrue($model->canUse('config')); + } + + /** + * @dataProvider getTagsByTypeDataProvider + */ + public function testGetTagsByType($cacheType, $expectedTags) + { + $actualTags = $this->_model->getTagsByType($cacheType); + $this->assertEquals($expectedTags, $actualTags); + } + + public function getTagsByTypeDataProvider() + { + return array( + 'single tag' => array('single_tag', array('tag_one')), + 'multiple tags' => array('multiple_tags', array('tag_one', 'tag_two')), + 'non-existing' => array('non-existing', false), + ); + } + + public function testGetTypes() + { + $expectedCacheTypes = array( + 'single_tag' => array( + 'id' => 'single_tag', + 'cache_type' => 'Tag One', + 'description' => 'This is Tag One', + 'tags' => 'TAG_ONE', + 'status' => 0, + ), + 'multiple_tags' => array( + 'id' => 'multiple_tags', + 'cache_type' => 'Tags One and Two', + 'description' => 'These are Tags One and Two', + 'tags' => 'TAG_ONE,TAG_TWO', + 'status' => 0, + ), + ); + $actualCacheTypes = $this->_model->getTypes(); + $this->assertInternalType('array', $actualCacheTypes); + $this->assertEquals(array_keys($expectedCacheTypes), array_keys($actualCacheTypes)); + foreach ($actualCacheTypes as $cacheId => $cacheTypeData) { + /** @var $cacheTypeData Varien_Object */ + $this->assertInstanceOf('Varien_Object', $cacheTypeData); + $this->assertEquals($expectedCacheTypes[$cacheId], $cacheTypeData->getData()); + } + } + + public function testGetInvalidatedTypes() + { + $this->_model->allowUse('single_tag'); + $this->_cacheFrontend + ->expects($this->once()) + ->method('load') + ->with(strtoupper(Mage_Core_Model_Cache::INVALIDATED_TYPES)) + ->will($this->returnValue(serialize(array('single_tag' => 1, 'non_existing_type' => 1)))) + ; + $actualResult = $this->_model->getInvalidatedTypes(); + $this->assertInternalType('array', $actualResult); + $this->assertCount(1, $actualResult); + $this->assertArrayHasKey('single_tag', $actualResult); + $this->assertInstanceOf('Varien_Object', $actualResult['single_tag']); + } + + public function testInvalidateType() + { + $this->_cacheFrontend + ->expects($this->once()) + ->method('save') + ->with(serialize(array('test' => 1)), strtoupper(Mage_Core_Model_Cache::INVALIDATED_TYPES)) + ; + $this->_model->invalidateType('test'); + } + + public function testCleanType() + { + $this->_model->allowUse('single_tag'); + $this->_model->allowUse('multiple_tags'); + $this->_cacheFrontend + ->expects($this->at(0)) + ->method('clean') + ->with(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('TAG_ONE', 'TAG_TWO')) + ; + $this->_cacheFrontend + ->expects($this->at(1)) + ->method('load') + ->with(strtoupper(Mage_Core_Model_Cache::INVALIDATED_TYPES)) + ->will($this->returnValue(serialize(array('single_tag' => 1, 'multiple_tags' => 1)))) + ; + $this->_cacheFrontend + ->expects($this->at(2)) + ->method('save') + ->with(serialize(array('single_tag' => 1)), strtoupper(Mage_Core_Model_Cache::INVALIDATED_TYPES)) + ; + $this->_model->cleanType('multiple_tags'); + } + + public function testProcessRequestFalse() + { + $response = new Zend_Controller_Response_Http(); + $this->_model = new Mage_Core_Model_Cache(array( + 'config' => $this->_config, + 'helper' => $this->_helper, + 'frontend' => $this->_cacheFrontend, + 'backend' => 'BlackHole', + )); + $this->assertFalse($this->_model->processRequest($response)); + } + + public function testProcessRequestTrue() + { + $response = new Zend_Controller_Response_Http(); + $response->setBody('Initial response body.'); + $this->_requestProcessor + ->expects($this->any()) + ->method('extractContent') + ->will($this->returnValue('Additional response text.')) + ; + $this->assertTrue($this->_model->processRequest($response)); + $this->assertEquals('Initial response body.Additional response text.', $response->getBody()); + } +} diff --git a/dev/tests/unit/testsuite/Mage/Core/Model/Config/OptionsTest.php b/dev/tests/unit/testsuite/Mage/Core/Model/Config/OptionsTest.php new file mode 100644 index 0000000000000..7b5fa56cfda2b --- /dev/null +++ b/dev/tests/unit/testsuite/Mage/Core/Model/Config/OptionsTest.php @@ -0,0 +1,141 @@ +getMock('Varien_Io_File', array('checkAndCreateFolder')); + $this->_sourceData = array( + 'app_dir' => $rootDir . DIRECTORY_SEPARATOR . 'app', + 'io' => $ioModel, + ); + $this->_varDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'var'; + } + + public function testGetVarDir() + { + $this->_sourceData['io']->expects($this->once()) + ->method('checkAndCreateFolder') + ->with($this->equalTo($this->_varDir)) + ->will($this->returnValue(true)); + + $this->_model = new Mage_Core_Model_Config_Options($this->_sourceData); + $result = $this->_model->getVarDir(); + $this->assertEquals($this->_varDir, $result); + } + + public function testGetVarDirSysTmpDir() + { + $sysVarDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'magento' . DIRECTORY_SEPARATOR . 'var'; + + $this->_sourceData['io']->expects($this->at(0)) + ->method('checkAndCreateFolder') + ->with($this->equalTo($this->_varDir)) + ->will($this->throwException(new Exception)); + + $this->_sourceData['io']->expects($this->at(1)) + ->method('checkAndCreateFolder') + ->with($this->equalTo($sysVarDir)) + ->will($this->returnValue(true)); + + $this->_model = new Mage_Core_Model_Config_Options($this->_sourceData); + $result = $this->_model->getVarDir(); + $this->assertEquals($sysVarDir, $result); + } + + /** + * @expectedException Mage_Core_Exception + */ + public function testGetVarDirWithException() + { + $sysVarDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'magento' . DIRECTORY_SEPARATOR . 'var'; + $this->_sourceData['io']->expects($this->at(0)) + ->method('checkAndCreateFolder') + ->with($this->equalTo($this->_varDir)) + ->will($this->throwException(new Exception)); + + $this->_sourceData['io']->expects($this->at(1)) + ->method('checkAndCreateFolder') + ->with($this->equalTo($sysVarDir)) + ->will($this->throwException(new Exception)); + + $this->_model = new Mage_Core_Model_Config_Options($this->_sourceData); + } + + public function testCreateDirIfNotExists() + { + $checkDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test'; + $this->_sourceData['io']->expects($this->at(0)) + ->method('checkAndCreateFolder') + ->with($this->equalTo($this->_varDir)) + ->will($this->returnValue(true)); + + $this->_sourceData['io']->expects($this->at(1)) + ->method('checkAndCreateFolder') + ->with($this->equalTo($checkDir)) + ->will($this->returnValue(true)); + + $this->_model = new Mage_Core_Model_Config_Options($this->_sourceData); + + $result = $this->_model->createDirIfNotExists($checkDir); + $this->assertEquals(true, $result); + } + + public function testCreateDirIfNotExistsNegativeResult() + { + $checkDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'dirNotExists'; + $this->_sourceData['io']->expects($this->at(0)) + ->method('checkAndCreateFolder') + ->with($this->equalTo($this->_varDir)) + ->will($this->returnValue(true)); + + $this->_sourceData['io']->expects($this->at(1)) + ->method('checkAndCreateFolder') + ->will($this->throwException(new Exception)); + + $this->_model = new Mage_Core_Model_Config_Options($this->_sourceData); + $result = $this->_model->createDirIfNotExists($checkDir); + $this->assertEquals(false, $result); + } +} \ No newline at end of file diff --git a/dev/tests/unit/testsuite/Mage/Core/Model/ConfigTest.php b/dev/tests/unit/testsuite/Mage/Core/Model/ConfigTest.php new file mode 100644 index 0000000000000..90cd647caff05 --- /dev/null +++ b/dev/tests/unit/testsuite/Mage/Core/Model/ConfigTest.php @@ -0,0 +1,53 @@ +_model = new Mage_Core_Model_Config($data); + $this->assertInstanceOf('Mage_Core_Model_Config_Options', $this->_model->getOptions()); + } + + public function constructorDataProvider() + { + return array( + array('data' => null), + array('data' => array()), + array('data' => new Varien_Simplexml_Element('')), + ); + } + +} \ No newline at end of file diff --git a/dev/tests/unit/testsuite/Mage/Core/Model/Resource/Setup/MigrationTest.php b/dev/tests/unit/testsuite/Mage/Core/Model/Resource/Setup/MigrationTest.php index 1e97d7fb6342d..0c1e1399a6668 100644 --- a/dev/tests/unit/testsuite/Mage/Core/Model/Resource/Setup/MigrationTest.php +++ b/dev/tests/unit/testsuite/Mage/Core/Model/Resource/Setup/MigrationTest.php @@ -217,6 +217,7 @@ public function testDoUpdateClassAliases($replaceRules, $tableData, $expected, $ 'core_setup', $this->_getModelDependencies($tableRowsCount, $tableData, $aliasesMap) ); + $setupModel->setTable('table', 'table'); foreach ($replaceRules as $replaceRule) { call_user_func_array(array($setupModel, 'appendClassAliasReplace'), $replaceRule); diff --git a/dev/tests/unit/testsuite/Mage/DesignEditor/Model/Change/CollectionTest.php b/dev/tests/unit/testsuite/Mage/DesignEditor/Model/Change/CollectionTest.php new file mode 100644 index 0000000000000..b4d113be367ff --- /dev/null +++ b/dev/tests/unit/testsuite/Mage/DesignEditor/Model/Change/CollectionTest.php @@ -0,0 +1,60 @@ +_model = new Mage_DesignEditor_Model_Change_Collection; + } + + /** + * @covers Mage_DesignEditor_Model_Change_Collection::getItemClass + */ + public function testGetItemClass() + { + $this->assertEquals('Mage_DesignEditor_Model_ChangeAbstract', $this->_model->getItemClass()); + } + + /** + * Test toArray method + * + * @covers Mage_DesignEditor_Model_Change_Collection::toArray + */ + public function testToArray() + { + $this->assertInternalType('array', $this->_model->toArray()); + } +} diff --git a/dev/tests/unit/testsuite/Mage/DesignEditor/Model/History/Compact/LayoutTest.php b/dev/tests/unit/testsuite/Mage/DesignEditor/Model/History/Compact/LayoutTest.php new file mode 100644 index 0000000000000..6eeb63c6bf89f --- /dev/null +++ b/dev/tests/unit/testsuite/Mage/DesignEditor/Model/History/Compact/LayoutTest.php @@ -0,0 +1,141 @@ +_layout = new Mage_DesignEditor_Model_History_Compact_Layout; + } + + /** + * Get mocked object of collection + * + * @param array $data + * @return Mage_DesignEditor_Model_Change_Collection|PHPUnit_Framework_MockObject_MockObject + */ + protected function _mockCollection(array $data) + { + /** @var $collectionMock Mage_DesignEditor_Model_Change_Collection */ + $collectionMock = $this->getMock( + 'Mage_DesignEditor_Model_Change_Collection', array('_init'), array(), '', true + ); + foreach ($data as $item) { + $changeClassName = Mage_DesignEditor_Model_Change_Factory::getClass($item); + /** @var $itemMock Mage_DesignEditor_Model_Change_LayoutAbstract */ + $itemMock = $this->getMock( + $changeClassName, array('getLayoutUpdateData', 'getLayoutDirective'), array(), '', false + ); + $itemMock->setData($item); + $collectionMock->addItem($itemMock); + } + return $collectionMock; + } + + /** + * Test compact logic with wrong collection + * + * @expectedException Magento_Exception + * @expectedExceptionMessage Compact collection is missed + */ + public function testBrokenCompactCollection() + { + $this->_layout->compact(); + } + + /** + * Test compact logic + * + * @param array $data + * @param array $expectedData + * @dataProvider removeDataSamples + */ + public function testCompact($data, $expectedData) + { + $collection = $this->_mockCollection($data); + $this->_layout->compact($collection); + + $compactedData = array(); + /** @var $change Mage_DesignEditor_Model_Change_LayoutAbstract */ + foreach ($collection as $change) { + $compactedData[] = $change->getData(); + } + $this->assertEquals($expectedData, $compactedData); + } + + /** + * DataProvider with remove directives + * + * @return array + */ + public function removeDataSamples() + { + return array( + array(array( + array('type' => 'layout', 'action_name' => 'remove', 'element_name' => 'head'), + array('type' => 'layout', 'action_name' => 'move', 'element_name' => 'head', + 'origin_container' => 'root', 'destination_container' => 'footer'), + array('type' => 'layout', 'action_name' => 'remove', 'element_name' => 'page.pools'), + array('type' => 'layout', 'action_name' => 'remove', 'element_name' => 'head'), + array('type' => 'layout', 'action_name' => 'remove', 'element_name' => 'page.pools'), + array('type' => 'layout', 'action_name' => 'remove', 'element_name' => 'page.pools'), + array('type' => 'layout', 'action_name' => 'remove', 'element_name' => 'head') + ), array( + array('type' => 'layout', 'action_name' => 'remove', 'element_name' => 'page.pools'), + array('type' => 'layout', 'action_name' => 'remove', 'element_name' => 'head'), + )), + array(array( + array('type' => 'layout', 'action_name' => 'move', 'element_name' => 'head', 'origin_order' => 0, + 'origin_container' => 'root', 'destination_container' => 'footer', 'destination_order' => 1), + array('type' => 'layout', 'action_name' => 'move', 'element_name' => 'head', 'origin_order' => 1, + 'origin_container' => 'footer', 'destination_container' => 'page.pools', 'destination_order' => 2), + array('type' => 'layout', 'action_name' => 'move', 'element_name' => 'head', 'origin_order' => 2, + 'origin_container' => 'page.pools', 'destination_container' => 'footer', 'destination_order' => 3), + ), array( + array('type' => 'layout', 'action_name' => 'move', 'element_name' => 'head', 'origin_order' => 2, + 'origin_container' => 'page.pools', 'destination_container' => 'footer', 'destination_order' => 3) + )), + array(array( + array('type' => 'layout', 'action_name' => 'move', 'element_name' => 'head', 'origin_order' => 0, + 'origin_container' => 'root', 'destination_container' => 'footer', 'destination_order' => 1), + array('type' => 'layout', 'action_name' => 'move', 'element_name' => 'head', 'origin_order' => 1, + 'origin_container' => 'footer', 'destination_container' => 'root', 'destination_order' => 0), + ), array( + )), + ); + } +} diff --git a/dev/tests/unit/testsuite/Mage/DesignEditor/Model/History/Renderer/LayoutUpdateTest.php b/dev/tests/unit/testsuite/Mage/DesignEditor/Model/History/Renderer/LayoutUpdateTest.php new file mode 100644 index 0000000000000..1feba86c6bea3 --- /dev/null +++ b/dev/tests/unit/testsuite/Mage/DesignEditor/Model/History/Renderer/LayoutUpdateTest.php @@ -0,0 +1,113 @@ +_layoutRenderer = new Mage_DesignEditor_Model_History_Renderer_LayoutUpdate; + } + + /** + * Test renderer + * + * @param array $changes + * @dataProvider getChanges + */ + public function testRenderer($changes) + { + $collection = $this->_mockCollection($changes); + + $this->assertXmlStringEqualsXmlFile( + realpath(__DIR__) . '/../../_files/history/layout_renderer.xml', $this->_layoutRenderer->render($collection) + ); + } + + /** + * Get mocked object of collection + * + * @param array $data + * @return Mage_DesignEditor_Model_Change_Collection|PHPUnit_Framework_MockObject_MockObject + */ + protected function _mockCollection(array $data) + { + /** @var $collectionMock Mage_DesignEditor_Model_Change_Collection */ + $collectionMock = $this->getMock( + 'Mage_DesignEditor_Model_Change_Collection', array('_init'), array(), '', true + ); + foreach ($data as $item) { + $changeClassName = Mage_DesignEditor_Model_Change_Factory::getClass($item); + /** @var $itemMock Mage_DesignEditor_Model_Change_LayoutAbstract */ + $itemMock = $this->getMock($changeClassName, array('getLayoutDirective'), array(), '', false); + + $itemMock->expects($this->any()) + ->method('getLayoutDirective') + ->will($this->returnValue($item['action_name'])); + + $itemMock->setData($item); + $collectionMock->addItem($itemMock); + } + return $collectionMock; + } + + /** + * Get changes + * + * @return array + */ + public function getChanges() + { + return array(array(array( + array( + 'handle' => 'catalog_category_view', + 'type' => 'layout', + 'element_name' => 'category.products', + 'action_name' => 'move', + 'destination_container' => 'right', + 'destination_order' => '-', + 'origin_container' => 'content', + 'origin_order' => '-' + ), + array( + 'handle' => 'customer_account', + 'type' => 'layout', + 'element_name' => 'customer_account_navigation', + 'action_name' => 'remove', + ), + ))); + } +} diff --git a/dev/tests/unit/testsuite/Mage/DesignEditor/Model/HistoryTest.php b/dev/tests/unit/testsuite/Mage/DesignEditor/Model/HistoryTest.php deleted file mode 100644 index c1fa74fc4287d..0000000000000 --- a/dev/tests/unit/testsuite/Mage/DesignEditor/Model/HistoryTest.php +++ /dev/null @@ -1,226 +0,0 @@ -getMock('Mage_DesignEditor_Model_History', $methods, array(), '', false); - - $methods = array('getHistoryLog', 'addChange'); - /** @var $managerMock Mage_DesignEditor_Model_History_Manager */ - $managerMock = $this->getMock('Mage_DesignEditor_Model_History_Manager', $methods, array(), '', false); - - $historyMock->expects($this->exactly(2)) - ->method('_getManagerModel') - ->will($this->returnValue($managerMock)); - - $managerMock->expects($this->exactly(4)) - ->method('addChange') - ->will($this->returnValue($managerMock)); - - $managerMock->expects($this->once()) - ->method('getHistoryLog') - ->will($this->returnValue(array())); - - $historyMock->setChangeLog($this->_getChangeLogData())->getCompactLog(); - } - - /** - * @covers Mage_DesignEditor_Model_History::getCompactLog - * @expectedException Mage_DesignEditor_Exception - */ - public function testGetCompactLogWithInvalidData() - { - $this->_mockTranslationHelper(); - - $methods = array('_getManagerModel'); - /** @var $historyMock Mage_DesignEditor_Model_History */ - $historyMock = $this->getMock('Mage_DesignEditor_Model_History', $methods, array(), '', false); - - $methods = array('addChange'); - /** @var $managerMock Mage_DesignEditor_Model_History_Manager */ - $managerMock = $this->getMock('Mage_DesignEditor_Model_History_Manager', $methods, array(), '', false); - - $historyMock->expects($this->exactly(1)) - ->method('_getManagerModel') - ->will($this->returnValue($managerMock)); - - $managerMock->expects($this->exactly(1)) - ->method('addChange') - ->will($this->returnValue($managerMock)); - - $historyMock->setChangeLog($this->_getInvalidChangeLogData())->getCompactLog(); - } - - /** - * @covers Mage_DesignEditor_Model_History::getCompactXml - */ - public function testGetCompactXml() - { - $methods = array('_getManagerModel'); - /** @var $historyMock Mage_DesignEditor_Model_History */ - $historyMock = $this->getMock('Mage_DesignEditor_Model_History', $methods, array(), '', false); - - $methods = array('getXml', 'addChange'); - /** @var $managerMock Mage_DesignEditor_Model_History_Manager */ - $managerMock = $this->getMock('Mage_DesignEditor_Model_History_Manager', $methods, array(), '', false); - - $historyMock->expects($this->exactly(2)) - ->method('_getManagerModel') - ->will($this->returnValue($managerMock)); - - $managerMock->expects($this->exactly(4)) - ->method('addChange') - ->will($this->returnValue($managerMock)); - - $managerMock->expects($this->once()) - ->method('getXml') - ->will($this->returnValue(array())); - - $historyMock->setChangeLog($this->_getChangeLogData())->getCompactXml(); - } - - /** - * @covers Mage_DesignEditor_Model_History::getCompactXml - * @expectedException Mage_DesignEditor_Exception - */ - public function testGetCompactXmlWithInvalidData() - { - $this->_mockTranslationHelper(); - - $methods = array('_getManagerModel'); - /** @var $historyMock Mage_DesignEditor_Model_History */ - $historyMock = $this->getMock('Mage_DesignEditor_Model_History', $methods, array(), '', false); - - $methods = array('addChange'); - /** @var $managerMock Mage_DesignEditor_Model_History_Manager */ - $managerMock = $this->getMock('Mage_DesignEditor_Model_History_Manager', $methods, array(), '', false); - - $historyMock->expects($this->exactly(1)) - ->method('_getManagerModel') - ->will($this->returnValue($managerMock)); - - $managerMock->expects($this->exactly(1)) - ->method('addChange') - ->will($this->returnValue($managerMock)); - - $historyMock->setChangeLog($this->_getInvalidChangeLogData())->getCompactXml(); - } - - protected function _getChangeLogData() - { - return array( - array( - 'handle' => 'checkout_cart_index', - 'change_type' => 'layout', - 'element_name' => 'checkout.cart', - 'action_name' => 'move', - 'action_data' => array( - 'destination_container' => 'content', - 'after' => '-', - ), - ), - array( - 'handle' => 'checkout_cart_index', - 'change_type' => 'layout', - 'element_name' => 'checkout.cart', - 'action_name' => 'remove', - 'action_data' => array(), - ), - array( - 'handle' => 'customer_account', - 'change_type' => 'layout', - 'element_name' => 'customer_account_navigation', - 'action_name' => 'move', - 'action_data' => array( - 'destination_container' => 'content', - 'after' => '-', - 'as' => 'customer_account_navigation_alias', - ), - ), - array( - 'handle' => 'customer_account', - 'change_type' => 'layout', - 'element_name' => 'customer_account_navigation', - 'action_name' => 'move', - 'action_data' => array( - 'destination_container' => 'top.menu', - 'after' => '-', - 'as' => 'customer_account_navigation_alias', - ), - ), - ); - } - - protected function _getInvalidChangeLogData() - { - return array( - array( - 'handle' => 'checkout_cart_index', - 'change_type' => 'layout', - 'element_name' => 'checkout.cart', - 'action_name' => 'move', - 'action_data' => array( - 'destination_container' => 'content', - 'after' => '-', - ), - ), - array( - 'handle' => '', - 'change_type' => '', - 'element_name' => '', - 'action_name' => '', - ), - ); - } - - /** - * Add/remove mock for translation helper - * - * @param bool $add - * @return void - */ - protected function _mockTranslationHelper($add = true) - { - Mage::unregister('_helper/Mage_DesignEditor_Helper_Data'); - if ($add) { - $helper = $this->getMock('stdClass', array('__')); - $helper->expects($this->any())->method('__')->will($this->returnArgument(0)); - Mage::register('_helper/Mage_DesignEditor_Helper_Data', $helper); - } - } -} - -class Mage_DesignEditor_Model_HistoryTest_Exception extends Exception -{ -} diff --git a/dev/tests/unit/testsuite/Mage/DesignEditor/Model/Manager/Adapter/LayoutTest.php b/dev/tests/unit/testsuite/Mage/DesignEditor/Model/Manager/Adapter/LayoutTest.php deleted file mode 100644 index 69575262cfebe..0000000000000 --- a/dev/tests/unit/testsuite/Mage/DesignEditor/Model/Manager/Adapter/LayoutTest.php +++ /dev/null @@ -1,105 +0,0 @@ -getMock( - 'Mage_DesignEditor_Model_History_Manager_Adapter_Layout', null, array(), '', false - ); - $layoutMock->setHandle($handle)->setType($type)->setName($name)->addAction($action, $data); - - $this->assertEquals($this->expectedMoveActionData(), $layoutMock->getData()); - } - - /** - * @cove Mage_DesignEditor_Model_History_Manager_Adapter_Layout::render - * @dataProvider changeData - */ - public function testRenderRemove($expectedXml, $name, $handle, $type, $action, $data) - { - /** @var $layoutMock Mage_DesignEditor_Model_History_Manager_Adapter_Layout */ - $layoutMock = $this->getMock( - 'Mage_DesignEditor_Model_History_Manager_Adapter_Layout', null, array(), '', false - ); - $xmlObject = new Varien_Simplexml_Element(''); - $layoutMock->setHandle($handle)->setHandleObject($xmlObject)->setType($type)->setName($name) - ->addAction($action, $data)->render(); - - $this->assertXmlStringEqualsXmlFile( - realpath(__DIR__) . '/../../_files/history/layout/' . $expectedXml, $xmlObject->asNiceXml() - ); - } - - public function changeData() - { - return array( - array( - 'move.xml', 'customer_account_navigation', 'customer_account', 'layout', 'move', array( - 'destination_container' => 'top.menu', - 'after' => '-', - 'as' => 'customer_account_navigation_alias', - ) - ), - array( - 'remove.xml', 'customer_account_navigation', 'customer_account', 'layout', 'remove', array() - ), - ); - } - - public function moveChangeData() - { - return array( - array('customer_account_navigation', 'customer_account', 'layout', 'move', array( - 'destination_container' => 'top.menu', - 'after' => '-', - 'as' => 'customer_account_navigation_alias', - ))); - } - - public function expectedMoveActionData() - { - return array( - 'actions' => array( - 'move' => array( - 'destination_container' => 'top.menu', - 'after' => '-', - 'as' => 'customer_account_navigation_alias', - ) - ), - 'handle' => 'customer_account', - 'name' => 'customer_account_navigation', - 'type' => 'layout' - ); - } -} diff --git a/dev/tests/unit/testsuite/Mage/DesignEditor/Model/_files/history/layout/remove.xml b/dev/tests/unit/testsuite/Mage/DesignEditor/Model/_files/history/layout/remove.xml deleted file mode 100644 index 46a9cf4cddde8..0000000000000 --- a/dev/tests/unit/testsuite/Mage/DesignEditor/Model/_files/history/layout/remove.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - diff --git a/dev/tests/unit/testsuite/Mage/DesignEditor/Model/_files/history/layout/move.xml b/dev/tests/unit/testsuite/Mage/DesignEditor/Model/_files/history/layout_renderer.xml similarity index 82% rename from dev/tests/unit/testsuite/Mage/DesignEditor/Model/_files/history/layout/move.xml rename to dev/tests/unit/testsuite/Mage/DesignEditor/Model/_files/history/layout_renderer.xml index 90a778d14f156..b167c84b02d1b 100644 --- a/dev/tests/unit/testsuite/Mage/DesignEditor/Model/_files/history/layout/move.xml +++ b/dev/tests/unit/testsuite/Mage/DesignEditor/Model/_files/history/layout_renderer.xml @@ -27,5 +27,11 @@ */ --> - + + + + + + + diff --git a/lib/Varien/Data/Form/Element/Editor.php b/lib/Varien/Data/Form/Element/Editor.php index 3c09a52dafff4..35ef45b4b2747 100644 --- a/lib/Varien/Data/Form/Element/Editor.php +++ b/lib/Varien/Data/Form/Element/Editor.php @@ -192,8 +192,9 @@ protected function _getToggleButtonHtml($visible = true) protected function _getPluginButtonsHtml($visible = true) { $buttonsHtml = ''; + // Button to widget insertion window - if (1 || $this->getConfig('add_widgets')) { + if ($this->getConfig('add_widgets')) { $buttonsHtml .= $this->_getButtonHtml(array( 'title' => $this->translate('Insert Widget...'), 'onclick' => "widgetTools.openDialog('" . $this->getConfig('widget_window_url') . "widget_target_id/"