diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 10079683604ce1a09da3c7ba87ef9ba0573829c0..23939da93d8fd599ebd6e211443ccf270727b2f0 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 520c7140fdaa4ad775ef8d12cd987531c2b4bc10..7d482e5736afa4b11a3b6b9686dacf4ad9a34433 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 @@ abstract class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Price_Group_Abstrac */ 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 144944b1bcaf4fd64f43bb33975169a1df9f69bb..d284df373a402f910a0e0b91f4c00e0bfb2cac59 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 @@ class Mage_Adminhtml_Block_Catalog_Search_Edit_Form extends Mage_Adminhtml_Block '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 04e804cad71ec273c1c9f879864e2db94aa9b751..658432f17b7a41d852e9ae8d6efa336d264e2074 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 @@ class Mage_Adminhtml_Block_Checkout_Agreement_Edit_Form extends Mage_Adminhtml_B ), )); - 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 fa9066433738bc815a504cafd6f9cad7e119ae17..6024338e9f97c65575e53207149b429c4dee5aa1 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 @@ class Mage_Adminhtml_Block_Customer_Edit_Tab_Account extends Mage_Adminhtml_Bloc $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( - '<script type="text/javascript">' - . " - var {$prefix}_websites = " . Mage::helper('Mage_Core_Helper_Data')->jsonEncode($websites) ."; - Validation.add( - 'validate-website-has-store', - '" . Mage::helper('Mage_Customer_Helper_Data')->__('Please select a website which contains store view') . "', - function(v, elem){ - return {$prefix}_websites[elem.value] == true; - } - ); - Element.observe('{$prefix}website_id', 'change', function(){ - Validation.validate($('{$prefix}website_id')) - }.bind($('{$prefix}website_id'))); - " - . '</script>' - ); - } - $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 @@ class Mage_Adminhtml_Block_Customer_Edit_Tab_Account extends Mage_Adminhtml_Bloc if ($customer->getId()) { $prefixField->addElementValues($customer->getPrefix()); } - } } @@ -162,80 +112,95 @@ class Mage_Adminhtml_Block_Customer_Edit_Tab_Account extends Mage_Adminhtml_Bloc } 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 @@ class Mage_Adminhtml_Block_Customer_Edit_Tab_Account extends Mage_Adminhtml_Bloc . '</script>' ); } + } - 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( + '<script type="text/javascript">' + . " + var {$prefix}_websites = " . Mage::helper('Mage_Core_Helper_Data')->jsonEncode($websites) ."; + Validation.add( + 'validate-website-has-store', + '" . $note . "', + function(v, elem){ + return {$prefix}_websites[elem.value] == true; + } + ); + Element.observe('{$prefix}website_id', 'change', function(){ + Validation.validate($('{$prefix}website_id')) + }.bind($('{$prefix}website_id'))); + " + . '</script>' + ); + $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 62cb9a7560a4b0edf82ac4eb7046a1996ed37f28..87caf5f07d400327fdbe937f05d17bf16204bb30 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 @@ class Mage_Adminhtml_Block_Newsletter_Queue_Edit_Form extends Mage_Adminhtml_Blo '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 @@ class Mage_Adminhtml_Block_Newsletter_Queue_Edit_Form extends Mage_Adminhtml_Blo '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 044465586215d90a1178db758df3ca5c237fef61..39c73d05bcbd5bfe5ec9cb8975d087ee2c66dafe 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 @@ class Mage_Adminhtml_Block_Newsletter_Subscriber_Grid extends Mage_Adminhtml_Blo ) )); - $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 b050057767e741d7df21d21470bdb73cad5f3c78..a6fb89495679bcea026346641050b1709602cbe9 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 @@ class Mage_Adminhtml_Block_Promo_Catalog_Edit_Tab_Main ), )); - 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 361689760f588b3a6ad12f0166f7de604ba4eb6b..6f46171ffbed41fb3d103838e42ab7b1f1d48a9c 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 @@ class Mage_Adminhtml_Block_Promo_Quote_Edit_Tab_Labels '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 @@ class Mage_Adminhtml_Block_Promo_Quote_Edit_Tab_Labels '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 @@ class Mage_Adminhtml_Block_Promo_Quote_Edit_Tab_Labels 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 7d934dc3835111a06662a6034cf715bd64c04ad7..eb6ad64f779af0d4240a0a72b18ae2fc0be44c71 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 @@ class Mage_Adminhtml_Block_Promo_Quote_Edit_Tab_Main $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 2cde99ee2dd48deb1a6b819fc3f620714a7b44b6..ec94f36ddbf1bdd0497f6e850f508f4eccbcb2cd 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 @@ class Mage_Adminhtml_Block_Rating_Edit_Tab_Form extends Mage_Adminhtml_Block_Wid $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 @@ class Mage_Adminhtml_Block_Rating_Edit_Tab_Form extends Mage_Adminhtml_Block_Wid 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 6ed76c6e97b172a552c0e7ae8f78dd3ea43047ea..b1e09e4e923e2799776ba713a9f9f1e4e830ac3e 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 @@ class Mage_Adminhtml_Block_Rating_Grid extends Mage_Adminhtml_Block_Widget_Grid '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 0dcdb9f2b115680e558543ff6ad4c39504c00b1a..7da5bbcd2b88b483445952936525a757a9854cef 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 @@ class Mage_Adminhtml_Block_Review_Edit_Form extends Mage_Adminhtml_Block_Widget_ /** * 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 6f14ada7cc90b648707ae03336ec906990f3b6e0..e2f21e47fae986f9e87f53014c5e7ac5e707d37e 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 @@ class Mage_Adminhtml_Block_Review_Rating_Detailed extends Mage_Adminhtml_Block_T ->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 2d4c12470618c1b72075dd9b44e2468ec677b1d6..d8cc4e7f950779a83ed6fd6226a73111a9f5f00e 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 @@ class Mage_Adminhtml_Block_Sales_Order_Status_New_Form extends Mage_Adminhtml_Bl */ 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 @@ class Mage_Adminhtml_Block_Sales_Order_Status_New_Form extends Mage_Adminhtml_Bl 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 2853e7aa2247332487686d37ba5c5f47b7b019c1..2643fb99a167b79dd4c0e1b300ee36361f6bd31d 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 @@ class Mage_Adminhtml_Block_Sitemap_Edit_Form extends Mage_Adminhtml_Block_Widget '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 e7d3032a4a5d008fb6fe1e1afa83311d1064ff9b..01e60ab889ddfbafb3701fc12b9833c59378911d 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 @@ class Mage_Adminhtml_Block_System_Config_Form extends Mage_Adminhtml_Block_Widge 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 989a7cbac3651989ffda77481ca540e48599e8ae..585921cd6bfc273688c49e15653125dc1fb90726 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 <core@magentocommerce.com> + * @author Magento Core Team <core@magentocommerce.com> */ 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 @@ class Mage_Adminhtml_Block_System_Config_Form_Field } /** - * 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 = '<tr id="row_' . $id . '">' - . '<td class="label"><label for="'.$id.'">'.$element->getLabel().'</label></td>'; + $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 = '<tr id="row_' . $htmlId . '">'; + $html .= '<td class="label"><label for="' . $htmlId . '">' . $element->getLabel() . '</label></td>'; + $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 .= '</tr>'; + return $html; + } - $html.= '<td class="value">'; - $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 = '<td class="value">'; + $html .= $this->_getElementHtml($element); if ($element->getComment()) { - $html.= '<p class="note"><span>'.$element->getComment().'</span></p>'; + $html .= '<p class="note"><span>' . $element->getComment() . '</span></p>'; } - $html.= '</td>'; - - 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.= '<td class="use-default">'; - //$html.= '<input id="'.$id.'_inherit" name="'.$namePrefix.'[inherit]" type="checkbox" value="1" class="input-checkbox config-inherit" '.$inherit.' onclick="$(\''.$id.'\').disabled = this.checked">'; - $html.= '<input id="'.$id.'_inherit" name="'.$namePrefix.'[inherit]" type="checkbox" value="1" class="checkbox config-inherit" '.$inherit.' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> '; - $html.= '<label for="'.$id.'_inherit" class="inherit" title="'.htmlspecialchars($defText).'">'.$checkboxLabel.'</label>'; - $html.= '</td>'; + $html .= '</td>'; + 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 = '<td class="use-default">'; + $html .= '<input id="' . $htmlId . '_inherit" name="' . $namePrefix . '[inherit]" type="checkbox" value="1"' + . ' class="checkbox config-inherit" ' . $checkedHtml + . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> '; + $html .= '<label for="' . $htmlId . '_inherit" class="inherit">' . $this->_getInheritCheckboxLabel($element) + . '</label>'; + $html .= '</td>'; + + 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.= '<td class="scope-label">'; - 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 = '<td class="scope-label">'; + if ($element->getScope() && !Mage::app()->isSingleStoreMode()) { $html .= $element->getScopeLabel(); } - $html.= '</td>'; + $html .= '</td>'; + return $html; + } - $html.= '<td class="">'; + /** + * Render field hint + * + * @param Varien_Data_Form_Element_Abstract $element + * @return string + */ + protected function _renderHint(Varien_Data_Form_Element_Abstract $element) + { + $html = '<td class="">'; if ($element->getHint()) { - $html.= '<div class="hint" >'; - $html.= '<div style="display: none;">' . $element->getHint() . '</div>'; - $html.= '</div>'; + $html .= '<div class="hint"><div style="display: none;">' . $element->getHint() . '</div></div>'; } - $html.= '</td>'; - - $html.= '</tr>'; + $html .= '</td>'; 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 4f65191a2ec1b108b2f1705e949639bc361f5897..bf17114054380a2dcb41b38238e915a6aff28f7c 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 @@ class Mage_Adminhtml_Block_System_Config_Switcher extends Mage_Adminhtml_Block_T { 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 7ee9844ce2b9bcf5c59ea702fff393b8f947bc29..8806f90ae396f2006c79fec13583fdabd6a1f190 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 @@ class Mage_Adminhtml_Block_Tax_Rate_Form extends Mage_Adminhtml_Block_Widget_For $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 2e3c77b911881b917207835d67400f1c5a381dd9..ee3f282e9744f84bd79863268687bba39e93c5c8 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 @@ class Mage_Adminhtml_Block_Urlrewrite_Edit_Form extends Mage_Adminhtml_Block_Wid 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 9517f4b700154f580a2f0cd14d443e923f42911c..14d6489512a97e6ea5f7bf1ab713dc34323a1527 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 @@ class Mage_Adminhtml_Model_Config extends Varien_Simplexml_Config } /** - * 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 01b8cb121e4820330a9a6da4a096403ceca9fd35..b3a7de03b9662538f0bc54c5106d92c496990471 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 @@ class Mage_Adminhtml_Model_Config_Data extends Varien_Object /** * 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 @@ class Mage_Adminhtml_Model_Config_Data extends Varien_Object 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 @@ class Mage_Adminhtml_Model_Config_Data extends Varien_Object } 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 @@ class Mage_Adminhtml_Model_Config_Data extends Varien_Object ->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 @@ class Mage_Adminhtml_Model_Config_Data extends Varien_Object */ if (!$inherit) { $saveTransaction->addObject($dataObject); - } - else { + } else { $deleteTransaction->addObject($dataObject); } - } - elseif (!$inherit) { + } elseif (!$inherit) { $dataObject->unsConfigId(); $saveTransaction->addObject($dataObject); } @@ -303,4 +303,25 @@ class Mage_Adminhtml_Model_Config_Data extends Varien_Object } 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 8ff13b2d3f57ac03c676c8a636b5523b7adf47b8..a0873a1cd92f12a83b7dc8268d4228aed0921593 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 d4e7439ed7f438f31aa22f26f363632ec1c42c8f..7cda96758f3a4dc80423169735d98aa05ed45254 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 @@ class Mage_Adminhtml_Catalog_CategoryController extends Mage_Adminhtml_Controlle '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 @@ class Mage_Adminhtml_Catalog_CategoryController extends Mage_Adminhtml_Controlle } } - /** - * 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 0e0d74dfed0a404f1558d95c6903f36fbbd80943..c0c8379c771dad36a906fdf635a277c5232f9d5f 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 @@ class Mage_Adminhtml_Catalog_Product_ReviewController extends Mage_Adminhtml_Con $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 a918412713aad271d840146cfeb8bdaf5efc3610..df4759b3e904abad24cc73dafe622173151d2ff4 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 @@ class Mage_Adminhtml_Catalog_ProductController extends Mage_Adminhtml_Controller $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 ce540fc28aa29bd900fb14956b452783534516ed..821190b376c2615a9ff4b30ec4132a051ee1ec24 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 @@ class Mage_Adminhtml_Newsletter_QueueController extends Mage_Adminhtml_Controlle } $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 458c8ffc0de62ee905f27b76586d5c207c421bb2..206962e484ad267cf0df40b2c9e79893b38bab53 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 @@ class Mage_Adminhtml_Newsletter_TemplateController extends Mage_Adminhtml_Contro 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 @@ class Mage_Adminhtml_Newsletter_TemplateController extends Mage_Adminhtml_Contro 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 dabb71e938691dc0a36ded53f30887c7c4257252..59da19f559b8ce46db1f17d53aed03576ae3e1f3 100644 --- a/app/code/core/Mage/Adminhtml/controllers/RatingController.php +++ b/app/code/core/Mage/Adminhtml/controllers/RatingController.php @@ -85,11 +85,13 @@ class Mage_Adminhtml_RatingController extends Mage_Adminhtml_Controller_Action $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 3ab79a2dd9cfc396f203fc3c5247a81bc96203e8..7482625ab6a824037218ad994e40dd539f8ea437 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 @@ <table cellspacing="0" class="data"> <thead> <tr class="headings"> - <th><?php echo Mage::helper('Mage_Customer_Helper_Data')->__('Website') ?></th> - <th><?php echo Mage::helper('Mage_Customer_Helper_Data')->__('Store') ?></th> - <th><?php echo Mage::helper('Mage_Customer_Helper_Data')->__('Store View') ?></th> + <?php if (!Mage::app()->isSingleStoreMode()): ?> + <th><?php echo Mage::helper('Mage_Customer_Helper_Data')->__('Website') ?></th> + <th><?php echo Mage::helper('Mage_Customer_Helper_Data')->__('Store') ?></th> + <th><?php echo Mage::helper('Mage_Customer_Helper_Data')->__('Store View') ?></th> + <?php endif; ?> <th><?php echo Mage::helper('Mage_Customer_Helper_Data')->__('Lifetime Sales') ?></th> <th><?php echo Mage::helper('Mage_Customer_Helper_Data')->__('Average Sale') ?></th> </tr> </thead> - <tfoot> - <tr> - <td colspan="3" class="label"><strong><big><?php echo Mage::helper('Mage_Customer_Helper_Data')->__('All Store Views') ?></big></strong></td> - <td class="emph"><strong><big><?php echo $this->formatCurrency($this->getTotals()->getBaseLifetime()) ?></big></strong></td> - <td class="emph"><strong><big><?php echo $this->formatCurrency($this->getTotals()->getAvgsale()) ?></big></strong></td> - </tr> - </tfoot> + <?php if (!Mage::app()->isSingleStoreMode()): ?> + <tfoot> + <tr> + <td colspan="3" class="label"><strong><big><?php echo Mage::helper('Mage_Customer_Helper_Data')->__('All Store Views') ?></big></strong></td> + <td class="emph"><strong><big><?php echo $this->formatCurrency($this->getTotals()->getBaseLifetime()) ?></big></strong></td> + <td class="emph"><strong><big><?php echo $this->formatCurrency($this->getTotals()->getAvgsale()) ?></big></strong></td> + </tr> + </tfoot> + <?php endif; ?> <?php if ($this->getRows()): ?> <tbody> <?php $_i = 0; ?> @@ -52,30 +56,34 @@ <?php foreach ($_groups as $_groupId => $_stores): ?> <?php $_groupRow = false; ?> <?php foreach ($_stores as $_row): ?> - <?php if ($_row->getStoreId() == 0): ?> - <td colspan="3" class="label"><?php echo $_row->getStoreName() ?></td> - <?php else: ?> - <tr<?php echo ($_i++ % 2 ? ' class="even"' : '') ?>> - <?php if (!$_websiteRow): ?> - <td rowspan="<?php echo $this->getWebsiteCount($_websiteId) ?>"><?php echo $_row->getWebsiteName() ?></td> - <?php $_websiteRow = true; ?> - <?php endif; ?> - <?php if (!$_groupRow): ?> - <td rowspan="<?php echo count($_stores) ?>"><?php echo $_row->getGroupName() ?></td> - <?php $_groupRow = true; ?> - <?php endif; ?> - <td class="label"><?php echo $_row->getStoreName() ?></td> - <?php endif; ?> - <td><?php echo $this->formatCurrency($_row->getLifetime(), $_row->getWebsiteId()) ?></td> - <td><?php echo $this->formatCurrency($_row->getAvgsale(), $_row->getWebsiteId()) ?></td> - </tr> + <?php if (!Mage::app()->isSingleStoreMode()): ?> + <?php if ($_row->getStoreId() == 0): ?> + <td colspan="3" class="label"><?php echo $_row->getStoreName() ?></td> + <?php else: ?> + <tr<?php echo ($_i++ % 2 ? ' class="even"' : '') ?>> + <?php if (!$_websiteRow): ?> + <td rowspan="<?php echo $this->getWebsiteCount($_websiteId) ?>"><?php echo $_row->getWebsiteName() ?></td> + <?php $_websiteRow = true; ?> + <?php endif; ?> + <?php if (!$_groupRow): ?> + <td rowspan="<?php echo count($_stores) ?>"><?php echo $_row->getGroupName() ?></td> + <?php $_groupRow = true; ?> + <?php endif; ?> + <td class="label"><?php echo $_row->getStoreName() ?></td> + <?php endif; ?> + <?php else: ?> + <tr> + <?php endif; ?> + <td><?php echo $this->formatCurrency($_row->getLifetime(), $_row->getWebsiteId()) ?></td> + <td><?php echo $this->formatCurrency($_row->getAvgsale(), $_row->getWebsiteId()) ?></td> + </tr> <?php endforeach; ?> <?php endforeach; ?> <?php endforeach; ?> </tbody> <?php else: ?> <tbody> - <tr class="no-display"><td colspan="5"></td></tr> + <tr class="no-display"><td colspan="<?php echo !Mage::app()->isSingleStoreMode() ? '5' : '2'; ?>"></td></tr> </tbody> <?php endif; ?> </table> 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 024f86c5782403d8ca8c33a680705c60062a0902..be84f623646f4732312e9ed48aeccda6d6bb9290 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', <td class="label"><label><?php echo Mage::helper('Mage_Sales_Helper_Data')->__('Order Status') ?></label></td> <td class="value"><strong><span id="order_status"><?php echo $_order->getStatusLabel() ?></span></strong></td> </tr> + <?php if (Mage::app()->isSingleStoreMode() == false):?> <tr> <td class="label"><label><?php echo Mage::helper('Mage_Sales_Helper_Data')->__('Purchased From') ?></label></td> <td class="value"><strong><?php echo $this->getOrderStoreName() ?></strong></td> </tr> + <?php endif; ?> <?php if($_order->getRelationChildId()): ?> <tr> <td class="label"><label><?php echo Mage::helper('Mage_Sales_Helper_Data')->__('Link to the New Order') ?></label></td> diff --git a/app/code/core/Mage/Backend/Block/Menu.php b/app/code/core/Mage/Backend/Block/Menu.php index 4ebacfbebb84fdaa761bf47f933eeea7703f0799..f568476d7945340d86d4e6d98995ae2e96dc15af 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 @@ class Mage_Backend_Block_Menu extends Mage_Backend_Block_Template } /** - * 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 '<a href="' . $menuItem->getUrl() . '" ' . $this->_renderItemAnchorTitle($menuItem) + . $this->_renderItemOnclickFunction($menuItem) + . ' class="' . $this->_renderAnchorCssClass($menuItem, $level) . '">' + . '<span>' . $this->_getAnchorLabel($menuItem) . '</span>' + . '</a>'; + } + + /** + * 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 @@ class Mage_Backend_Block_Menu extends Mage_Backend_Block_Template } /** - * 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 = '<ul ' . (0 == $level ? 'id="nav"' : '') . ' >'; - /** - * Set item renderer block name - * @param string $renderer - * @return Mage_Backend_Block_Menu - */ - public function setItemRendererBlock($renderer) - { - $this->_itemRendererBlock = $renderer; - return $this; - } + /** @var $menuItem Mage_Backend_Model_Menu_Item */ + foreach ($this->_getMenuIterator($menu) as $menuItem) { + $output .= '<li ' . $this->_renderMouseEvent($menuItem) + . ' class="' . $this->_renderItemCssClass($menuItem, $level) . '">'; - /** - * Get item renderer block name - * @return string - */ - public function getItemRendererBlock() - { - return $this->_itemRendererBlock; + $output .= $this->_renderAnchor($menuItem, $level); + + if ($menuItem->hasChildren()) { + $output .= $this->renderMenu($menuItem->getChildren(), $level + 1); + } + $output .='</li>'; + } + $output .= '</ul>'; + + 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 9b7ba884a71ac0af9bcb2f4f89f56b41c38af8d9..0000000000000000000000000000000000000000 --- a/app/code/core/Mage/Backend/Block/Menu/Container.php +++ /dev/null @@ -1,99 +0,0 @@ -<?php -/** - * Magento - * - * NOTICE OF LICENSE - * - * This source file is subject to the Open Software License (OSL 3.0) - * that is bundled with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://opensource.org/licenses/osl-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_Backend - * @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) - */ - -/** - * Backend menu item block - * - * @category Mage - * @package Mage_Backend - * @author Magento Core Team <core@magentocommerce.com> - */ -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 68c7bc943184c2b52a91a78a4863fe74f5470b2e..0000000000000000000000000000000000000000 --- a/app/code/core/Mage/Backend/Block/Menu/Item.php +++ /dev/null @@ -1,115 +0,0 @@ -<?php -/** - * Magento - * - * NOTICE OF LICENSE - * - * This source file is subject to the Open Software License (OSL 3.0) - * that is bundled with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://opensource.org/licenses/osl-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_Backend - * @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) - */ - -/** - * Backend menu item block - * - * @category Mage - * @package Mage_Backend - * @author Magento Core Team <core@magentocommerce.com> - */ -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 573ac181931f93f6de7fb5a1eb281a4f6edde4ff..b0e561e67208b23cb3ced98af104858b1dac83a5 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 @@ class Mage_Backend_Model_Menu_Builder } // 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 e676ab50d702305020160f9a5d460280c6d82160..a26fa64ecd2df848bce4b21115b92470406fa353 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 @@ class Mage_Backend_Model_Menu_Builder_Command_Add extends Mage_Backend_Model_Men */ 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 d97e8162d8adf0a4075cd971639130f24e1b6fc5..f1e01a763e9087627ebc09694708435cd9f0e333 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 b3c56f3c741bb9909a49fcb876ae1b406889a2b5..449a38218abafaf8a09d14f1a022fc5922d2830d 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 @@ class Mage_Backend_Model_Menu_Config ? $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 @@ class Mage_Backend_Model_Menu_Config 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 @@ class Mage_Backend_Model_Menu_Config '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 5d38d46701bccfe41c904a9a0d26c96d801b26fc..ca9c6431f798f7710ce71176752f3e2b8b78b044 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 @@ class Mage_Backend_Model_Menu_Config_Menu extends Magento_Config_XmlAbstract /** * 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 0f97f112f7e501ae716e99554c1e316e6927cbfc..139795ad21aef9728e5bd82f9c7ec055cc7c6d41 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 @@ class Mage_Backend_Model_Menu_Item /** * Retrieve item click callback * - * @return bool + * @return string */ public function getClickCallback() { @@ -434,4 +441,34 @@ class Mage_Backend_Model_Menu_Item 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 2975b5a63a40a427c3bbf00e495fcd21aa88e0e5..c65b3108b7938af60b04e59a66bf8c0e5fbaa5f6 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 @@ class Mage_Backend_Model_Menu_Item_Validator $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 c4cedbbc5cbccd0eb42da2e992904c130b887767..6edf9e92058e39d9d8ec789362bc051086526170 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 @@ class Mage_Backend_Model_Menu_Logger extends Mage_Core_Model_Logger /** * 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 d06896a6ca19fab8357ac25e868ca109934c5220..e29edd8b97b1b5fa2da37df2694bb6d6407a91c0 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 @@ <layout> <default> <reference name="root" after="header"> - <block type="Mage_Backend_Block_Menu" name="menu" as="menu" template="Mage_Backend::menu.phtml"> - <block type="Mage_Backend_Block_Menu_Container" name="menu_container_renderer" template="Mage_Backend::menu/container.phtml" /> - <block type="Mage_Backend_Block_Menu_Item" name="menu_item_renderer" template="Mage_Backend::menu/item.phtml" /> - <action method="setContainerRendererBlock"><renderer>menu_container_renderer</renderer></action> - <action method="setItemRendererBlock"><renderer>menu_item_renderer</renderer></action> - </block> + <block type="Mage_Backend_Block_Menu" name="menu" as="menu" template="Mage_Backend::menu.phtml" /> </reference> </default> diff --git a/app/code/core/Mage/Backend/view/adminhtml/menu.phtml b/app/code/core/Mage/Backend/view/adminhtml/menu.phtml index c3ff88c590386c78d484f9d97ab861b015ab5b9b..d2b696694377f4fc4563c588801c32b5b486dba8 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 @@ ?> <div class="nav-bar"> - <?php echo $this->renderMenuContainer($this->getMenuModel()); ?> + <?php echo $this->renderMenu($this->getMenuModel()); ?> <a id="page-help-link" href="<?php echo Mage::helper('Mage_Backend_Helper_Data')->getPageHelpUrl() ?>"><?php echo $this->__('Get help for this page') ?></a> <script type="text/javascript">$('page-help-link').target = 'magento_page_help'</script> </div> 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 6947fadefabc020a2de95e4ad327c509c00214a3..0000000000000000000000000000000000000000 --- a/app/code/core/Mage/Backend/view/adminhtml/menu/container.phtml +++ /dev/null @@ -1,32 +0,0 @@ -<?php -/** - * 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 design - * @package default_default - * @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) - */ -?> - -<ul <?php echo (!$this->getLevel() ? 'id="nav"' : '') ?>> - <?php foreach ($this->getMenuIterator() as $menuItem) : ?> - <?php echo $this->renderMenuItem($menuItem); ?> - <?php endforeach; ?> -</ul> 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 3a1c0d3e7452a7b3a3ea33a4c8baaa455732201e..0000000000000000000000000000000000000000 --- a/app/code/core/Mage/Backend/view/adminhtml/menu/item.phtml +++ /dev/null @@ -1,37 +0,0 @@ -<?php -/** - * 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 design - * @package default_default - * @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) - */ -?> - -<li <?php echo ($this->getMenuItem()->hasChildren() ? 'onmouseover="Element.addClassName(this,\'over\')" onmouseout="Element.removeClassName(this,\'over\')"' : ''); ?> - class="<?php echo ($this->isItemActive($this->getMenuItem()) ? 'active' : '') . ' ' . ($this->getMenuItem()->hasChildren() ? 'parent' : '') . ' ' . ($this->isLast() ? 'last' : '') . ' ' . ('level' . $this->getLevel()); ?>"> - <a href="<?php echo $this->getMenuItem()->getUrl(); ?>" <?php echo ($this->getMenuItem()->hasTooltip() ? 'title="' . $this->getMenuItem()->getModuleHelper()->__($this->getMenuItem()->getTooltip()) . '"' : '') . ($this->getMenuItem()->hasClickCallback() ? ' onclick="' . $this->getMenuItem()->getClickCallback() . '"' : ''); ?> class="<?php echo ($this->isItemActive($this->getMenuItem()) ? 'active' : ''); ?>"> - <span><?php echo $this->escapeHtml($this->getMenuItem()->getModuleHelper()->__($this->getMenuItem()->getTitle())); ?></span> - </a> - <?php if ($this->getMenuItem()->hasChildren()) : ?> - <?php echo $this->getContainerRenderer()->renderMenuContainer($this->getMenuItem()->getChildren(), $this->getLevel() + 1); ?> - <?php endif; ?> -</li> - 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 0e4c36209ae1a5ac56339c804915ecbd95a0ce67..20042d90b6d00274a27b254543e3fab0987a5988 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 @@ class Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Bundle_Option extends 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 eff796a98f84b2d7a5a0782aa8c0456b086347f4..f679b3e3fc0f742530b0119db5f55bac89729c01 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 @@ abstract class Mage_Catalog_Model_Api2_Product_Rest extends Mage_Catalog_Model_A // 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 a2d9b5bbfb1d53e854cfa0936192bf7de6027c3c..a28cc47aecf26dc594adac494c9239ae57b3ce80 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 @@ class Mage_Catalog_Model_Category_Attribute_Backend_Sortby * @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 @@ class Mage_Catalog_Model_Category_Attribute_Backend_Sortby } $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 4c7100b1583e7ee0fd1c08b97e813b7a5849de59..7f46e3596a227f31c479b793b66820f5300b227d 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 @@ class Mage_Catalog_Model_Convert_Adapter_Product /** * 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 @@ class Mage_Catalog_Model_Convert_Adapter_Product /** * 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 1c798bf40e06de0de08e8e05b2a1e7b134463159..4ab7f02b0fb5314055c8a6b7d9d57d4737baf707 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 @@ class Mage_Catalog_Model_Product_Api extends Mage_Catalog_Model_Api_Resource $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 91a07177f32f9e781ac336d834de6b7511abc1a6..1e19a50f0c288e508c7e3fa3fa3921ad80b48233 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 @@ class Mage_Catalog_Model_Product_Api_V2 extends Mage_Catalog_Model_Product_Api $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 decfb5b910f9d529ca7b5c5f4595813370e4e4cd..3616a387a72cd49a76604d1ce12f370fb1c05862 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 @@ abstract class Mage_Catalog_Model_Resource_Abstract extends Mage_Eav_Model_Entit * 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 @@ abstract class Mage_Catalog_Model_Resource_Abstract extends Mage_Eav_Model_Entit * 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 b70409fbc1c66de2eff7fb39d53a79a6505bfc68..d6b6e780592addd1a88c961969edbd9697f03c55 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 4b563a99eb68efde044cfa318585c8b6734c6738..01bb855893a0d2b63bb0788c5cc8ac1fb25b040d 100644 --- a/app/code/core/Mage/Catalog/etc/system.xml +++ b/app/code/core/Mage/Catalog/etc/system.xml @@ -276,6 +276,7 @@ <show_in_default>1</show_in_default> <show_in_website>0</show_in_website> <show_in_store>0</show_in_store> + <hide_in_single_store_mode>1</hide_in_single_store_mode> </scope> </fields> </price> 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 0782b76065638c01e24246fd62ef9ad06687b658..150af420663a31c9486af443f33ede596573ff74 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 5f77a3e3b35f91897545878292bd149c5557b4a8..bcb0409954dda8e57ea9af8d41015db2a3e874d4 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 @@ class Mage_Cms_Model_Resource_Block extends Mage_Core_Model_Resource_Db_Abstract */ 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 3d38d8db22e58b2848cdbbb2130f11331f23ac45..57c4c62c86b7b9cd795df3c8adafcb6dc37b482b 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 @@ class Mage_Cms_Model_Resource_Page extends Mage_Core_Model_Resource_Db_Abstract */ 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 fcdcb606a1fe0a032517a642b001ed2c80c37fa5..8fbcd4e794e694120e7199209028c250f7d8cbe6 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 af14a4b960ca7885fea7dcf10bbed52f32a9794a..2295e630252c48fd65b19b1d2a1153b70f81faef 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 @@ XML; { 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 1b4d7370c92575134974e0452f48f4391cbea0bd..94c3cc9588148a7164336262f8e60940da31a662 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 @@ class Mage_Core_Model_App 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 @@ class Mage_Core_Model_App ->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 @@ class Mage_Core_Model_App } /** - * 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 @@ class Mage_Core_Model_App 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 301c22607a0ffbae3a505e527d32d2b4394ec508..f7a789a2c445e948a3e4fe99177b120953e6a305 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 @@ class Mage_Core_Model_Cache $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 @@ class Mage_Core_Model_Cache $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 @@ class Mage_Core_Model_Cache $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 @@ class Mage_Core_Model_Cache 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 @@ class Mage_Core_Model_Cache 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 @@ class Mage_Core_Model_Cache /** * 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 @@ class Mage_Core_Model_Cache } if ($content) { - Mage::app()->getResponse()->appendBody($content); + $response->appendBody($content); return true; } return false; @@ -686,10 +701,15 @@ class Mage_Core_Model_Cache /** * 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 5601fce66f79a1342fccb951e91a3b2b0a66381e..2040fdbe8df241247470f293dc4b4b134e1ea92f 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 e4526d7a8bc06ec8e6630297357401ce6f095672..77bd7b66372f917c684a1549fe0da0d1e81f06dc 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 @@ class Mage_Core_Model_Config_Options extends Varien_Object * 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 @@ class Mage_Core_Model_Config_Options extends Varien_Object 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 8f60118e3a5764189ae82cb41587409ad1b12dbb..9c0d65582aeff7e0836591b14033189a9c271193 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 @@ abstract class Mage_Core_Model_Resource_Db_Collection_Abstract extends Varien_Da $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 3e2211a89d06f254f42d6e8faeecdd0ab8b6847a..a54d36b617c05c244cfdcbeab67e63b00d8d5159 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 @@ class Mage_Core_Model_Resource_Setup_Migration extends Mage_Core_Model_Resource_ $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 @@ class Mage_Core_Model_Resource_Setup_Migration extends Mage_Core_Model_Resource_ $where[$adapter->quoteIdentifier($whereFieldName) . ' = ?'] = $value; } $adapter->update( - $adapter->getTableName($tableName), + $this->getTable($tableName), array($fieldName => $fieldReplacement['to']), $where ); @@ -387,7 +387,7 @@ class Mage_Core_Model_Resource_Setup_Migration extends Mage_Core_Model_Resource_ $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 db8334862dcce00264ee967a00ca5943b8b4762e..5ab51faf4e8d014d498d1bdadb4575f3bfe851ce 100644 --- a/app/code/core/Mage/Core/Model/Url.php +++ b/app/code/core/Mage/Core/Model/Url.php @@ -664,7 +664,7 @@ class Mage_Core_Model_Url extends Varien_Object 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 36e88c5accd4a128db483d2a2500e697738865e2..6bd1a5cd1e4779c76186ee0150138aea8a259136 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 32ca68e3a69d3a8b65afe8e38d8f5ab56832732c..0ecb7be29bf0cb29dc043b293e16703484c2455d 100644 --- a/app/code/core/Mage/Core/etc/config.xml +++ b/app/code/core/Mage/Core/etc/config.xml @@ -338,6 +338,9 @@ </protected> </public_files_valid_paths> </file> + <single_store_mode> + <enabled>0</enabled> + </single_store_mode> </general> <dev> <image> diff --git a/app/code/core/Mage/Core/etc/system.xml b/app/code/core/Mage/Core/etc/system.xml index 7be3d7970174eac8b3346423a227b679c35fd68c..3f9c66c40e191304f8168afe0b80ea95ece3e92b 100644 --- a/app/code/core/Mage/Core/etc/system.xml +++ b/app/code/core/Mage/Core/etc/system.xml @@ -757,6 +757,26 @@ </address> </fields> </store_information> + <single_store_mode translate="label"> + <label>Single-Store Mode</label> + <frontend_type>text</frontend_type> + <sort_order>150</sort_order> + <show_in_default>1</show_in_default> + <show_in_website>0</show_in_website> + <show_in_store>0</show_in_store> + <fields> + <enabled translate="label comment"> + <label>Enable Single-Store Mode</label> + <frontend_type>select</frontend_type> + <source_model>Mage_Adminhtml_Model_System_Config_Source_Yesno</source_model> + <sort_order>10</sort_order> + <show_in_default>1</show_in_default> + <show_in_website>0</show_in_website> + <show_in_store>0</show_in_store> + <comment>This setting will not be taken into account if system has more than one store view.</comment> + </enabled> + </fields> + </single_store_mode> </groups> </general> <system translate="label" module="Mage_Core"> 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 1829ab6adc0fd02ba58136af9b7466376a307931..7e1eb9cf39976ffa9287dd41fbfd09303cdc10ca 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 3a83eadb10e6285a5eb1725a4ea8dd5a75d89f6d..6ce36278dba59d3e9832e14f4e5fb53ed49313fe 100644 --- a/app/code/core/Mage/Customer/etc/system.xml +++ b/app/code/core/Mage/Customer/etc/system.xml @@ -50,6 +50,7 @@ <show_in_default>1</show_in_default> <show_in_website>0</show_in_website> <show_in_store>0</show_in_store> + <hide_in_single_store_mode>1</hide_in_single_store_mode> <fields> <scope translate="label"> <label>Share Customer Accounts</label> 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 286889a126e9622219b25bd361d0ceae169f5ef9..85cc22984bb0f32c2109cdee2effa6cc5d2d1310 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 @@ class Mage_DesignEditor_Block_Adminhtml_Launcher_Form extends Mage_Adminhtml_Blo '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 f3ce386f2e4f4d6184f74defb60af0b68067faa0..db09ca2e5a9cc5a478415fd33fc44e4ccb9fe22b 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 @@ class Mage_DesignEditor_Block_Toolbar_Buttons extends Mage_Core_Block_Template */ 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 b421dfe24b559b2c86e7e46c947e7b561fb131f9..a1dbf793d04dfe737f80d53a97823e6bce394a17 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 0000000000000000000000000000000000000000..34f08262a19b4c7a8c60aafa905534982ca82856 --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/Change/Factory.php @@ -0,0 +1,115 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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/osl-3.0.php Open Software License (OSL 3.0) + */ + +/** + * Changes factory model. Creates right Change instance by given type. + */ +class Mage_DesignEditor_Model_Change_Factory +{ + /** + * Create instance of change by given type + * + * @static + * @param Varien_Object|array $change + * @throws Magento_Exception + * @return Mage_DesignEditor_Model_ChangeAbstract + */ + public static function getInstance($change) + { + $class = self::getClass($change); + $model = Mage::getModel($class, $change); + if (!$model instanceof Mage_DesignEditor_Model_ChangeAbstract) { + throw new Magento_Exception(sprintf('Invalid change class "%s"', $class)); + } + return $model; + } + + /** + * Build change class using given type + * + * @static + * @param Varien_Object|array $change + * @return string + */ + public static function getClass($change) + { + $type = self::_getChangeType($change); + if ($type == Mage_DesignEditor_Model_Change_LayoutAbstract::CHANGE_TYPE) { + $directive = self::_getChangeLayoutDirective($change); + $class = 'Mage_DesignEditor_Model_Change_' . ucfirst($type) . '_' . ucfirst($directive); + } else { + $class = 'Mage_DesignEditor_Model_Change_' . ucfirst($type); + } + + return $class; + } + + /** + * Get change type + * + * @param Varien_Object|array $change + * @throws Magento_Exception + * @return string + */ + protected static function _getChangeType($change) + { + $type = null; + if (is_array($change)) { + $type = isset($change['type']) ? $change['type'] : null; + } elseif ($change instanceof Varien_Object) { + $type = $change->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 1e1384270e762fa68338d8a1cf605f954adbdb65..18e4bbc27078b3c7a18266a21015e688d173b2aa 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 0000000000000000000000000000000000000000..c24ca20f62286c7c4da730808ba6cb9c086ccc69 --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/Change/Layout/Remove.php @@ -0,0 +1,56 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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/osl-3.0.php Open Software License (OSL 3.0) + */ + +/** + * Layout remove change model + */ +class Mage_DesignEditor_Model_Change_Layout_Remove extends Mage_DesignEditor_Model_Change_LayoutAbstract +{ + /** + * Layout directive associated with this change + */ + const LAYOUT_DIRECTIVE_REMOVE = 'remove'; + + /** + * Get data to render layout update directive + * + * @return array + */ + public function getLayoutUpdateData() + { + return array('name' => $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 0000000000000000000000000000000000000000..d9c4989fdc525ab03985754e39186cec3a07d6b6 --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/Change/LayoutAbstract.php @@ -0,0 +1,82 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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/osl-3.0.php Open Software License (OSL 3.0) + */ + +/** + * Layout change model + */ +abstract class Mage_DesignEditor_Model_Change_LayoutAbstract extends Mage_DesignEditor_Model_ChangeAbstract +{ + /** + * Layout change type identifier + */ + const CHANGE_TYPE = 'layout'; + + /** + * Validate layout move change data passed to constructor + * + * @throws Mage_Core_Exception + * @return Mage_DesignEditor_Model_Change_LayoutAbstract + */ + protected function _validate() + { + $errors = array(); + foreach ($this->_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 0000000000000000000000000000000000000000..1fa6c7c5e342a71fbe1224b5589c7f758ac73636 --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/ChangeAbstract.php @@ -0,0 +1,51 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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/osl-3.0.php Open Software License (OSL 3.0) + */ + +/** + * Changes factory model. Creates right Change instance by given type. + */ +abstract class Mage_DesignEditor_Model_ChangeAbstract extends Varien_Object +{ + /** + * Generic constructor of change instance + * + * @param array $data + */ + public function __construct(array $data = array()) + { + parent::__construct($data); + $this->_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 381429137c2d7a6ec44709c90f2582d1e6585a3e..d21d2c80e8ee8126866426d87dbdf7d3c68e75cc 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 0000000000000000000000000000000000000000..dda3011265af0ebfe635d9662e58fb9fcb6b9379 --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/History/Compact.php @@ -0,0 +1,95 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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/osl-3.0.php Open Software License (OSL 3.0) + */ + +/** + * History compaction model + */ +class Mage_DesignEditor_Model_History_Compact +{ + /** + * Configuration for compact model + * + * @var array + */ + protected $_config = array('Mage_DesignEditor_Model_History_Compact_Layout'); + + /** + * Storage of compact strategies + * + * @var array + */ + protected $_compactModels = array(); + + /** + * Compact collection of changes + * + * @param Mage_DesignEditor_Model_Change_Collection $collection + * @throws Mage_Core_Exception + * @return Mage_DesignEditor_Model_History_Compact + */ + public function compact(Mage_DesignEditor_Model_Change_Collection $collection) + { + $itemType = $collection->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 0000000000000000000000000000000000000000..9a381a073494c2cf07cf6bf992a4d757a9078714 --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/History/Compact/Diff.php @@ -0,0 +1,44 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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/osl-3.0.php Open Software License (OSL 3.0) + */ + +/** + * History compaction strategy to compact file changes + */ +class Mage_DesignEditor_Model_History_Compact_Diff implements Mage_DesignEditor_Model_History_CompactInterface +{ + /** + * Run compact strategy on given collection + * + * @param Mage_DesignEditor_Model_Change_Collection $collection + * @return Mage_DesignEditor_Model_History_Compact_Layout|Mage_DesignEditor_Model_History_CompactInterface + */ + public function compact(Mage_DesignEditor_Model_Change_Collection $collection) + { + //@TODO compact strategies for file changes are not determined yet + + return $this; + } +} diff --git a/app/code/core/Mage/DesignEditor/Model/History/Compact/Layout.php b/app/code/core/Mage/DesignEditor/Model/History/Compact/Layout.php new file mode 100644 index 0000000000000000000000000000000000000000..b50f3729fbe5448c3cf1a21433ef47eb7d6bac15 --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/History/Compact/Layout.php @@ -0,0 +1,161 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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/osl-3.0.php Open Software License (OSL 3.0) + */ + +/** + * History compaction strategy to compact layout changes + */ +class Mage_DesignEditor_Model_History_Compact_Layout extends Mage_DesignEditor_Model_History_CompactAbstract +{ + /** + * Scheduled move actions + * + * @var array + */ + protected $_scheduledMoves = array(); + + /** + * Scheduled remove actions + * + * @var array + */ + protected $_scheduledRemoves = array(); + + /** + * Run compact strategy on given collection + * + * @param Mage_DesignEditor_Model_Change_Collection $collection + * @return Mage_DesignEditor_Model_History_Compact_Layout + */ + public function compact($collection = null) + { + parent::compact($collection)->_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 0000000000000000000000000000000000000000..077afd7a5b8a3ddae240f1817ec5b32e07d6da69 --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/History/CompactAbstract.php @@ -0,0 +1,78 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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/osl-3.0.php Open Software License (OSL 3.0) + */ + +/** + * Compaction model abstract + */ +abstract class Mage_DesignEditor_Model_History_CompactAbstract + implements Mage_DesignEditor_Model_History_CompactInterface +{ + /** + * Changes collection + * + * @var Mage_DesignEditor_Model_Change_Collection + */ + protected $_changesCollection; + + /** + * Set change collection + * + * @param Mage_DesignEditor_Model_Change_Collection $collection + * @return Mage_DesignEditor_Model_History_Compact_Layout + */ + public function setChangesCollection(Mage_DesignEditor_Model_Change_Collection $collection) + { + $this->_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 0000000000000000000000000000000000000000..1d14158798f0872fe10c861858f5eb3eb3532d45 --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/History/CompactInterface.php @@ -0,0 +1,55 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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/osl-3.0.php Open Software License (OSL 3.0) + */ + +/** + * History compaction strategies interface + */ +interface Mage_DesignEditor_Model_History_CompactInterface +{ + /** + * Set change collection + * + * @param Mage_DesignEditor_Model_Change_Collection $collection + * @return Mage_DesignEditor_Model_History_Compact_Layout + */ + public function setChangesCollection(Mage_DesignEditor_Model_Change_Collection $collection); + + /** + * Get change collection + * + * @return Mage_DesignEditor_Model_Change_Collection + */ + public function getChangesCollection(); + + /** + * Signature of compact method to implement in subclasses + * + * @param Mage_DesignEditor_Model_Change_Collection|null $collection + * @throws Magento_Exception + * @return Mage_DesignEditor_Model_History_CompactInterface + */ + public function compact($collection = null); +} diff --git a/app/code/core/Mage/DesignEditor/Model/History/Manager/Adapter/Abstract.php b/app/code/core/Mage/DesignEditor/Model/History/Manager/Adapter/Abstract.php deleted file mode 100644 index 48a550aee06e9ef4243b5fab0dc13f8adca75658..0000000000000000000000000000000000000000 --- a/app/code/core/Mage/DesignEditor/Model/History/Manager/Adapter/Abstract.php +++ /dev/null @@ -1,76 +0,0 @@ -<?php -/** - * Magento - * - * NOTICE OF LICENSE - * - * This source file is subject to the Open Software License (OSL 3.0) - * that is bundled with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://opensource.org/licenses/osl-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/osl-3.0.php Open Software License (OSL 3.0) - */ - -/** - * Visual design editor adapter abstract - * - * @method string getName() - * @method string getHandle() - * @method string getType() - * @method array getActions() - */ -abstract class Mage_DesignEditor_Model_History_Manager_Adapter_Abstract extends Mage_Core_Model_Abstract -{ - /** - * Add action to element - * - * @abstract - * @param string $action - * @param array $data - * @return Mage_DesignEditor_Model_History_Manager_Adapter_Abstract - */ - abstract public function addAction($action, $data); - - /** - * Render element data - * - * @abstract - * @return mixed - */ - abstract public function render(); - - /** - * Convert element to history log - * - * @return array - */ - public function toHistoryLog() - { - $resultData = array(); - - foreach ($this->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 5371ecc62aa64d8d395143a0e480c02595e7734e..0000000000000000000000000000000000000000 --- a/app/code/core/Mage/DesignEditor/Model/History/Manager/Adapter/Layout.php +++ /dev/null @@ -1,187 +0,0 @@ -<?php -/** - * Magento - * - * NOTICE OF LICENSE - * - * This source file is subject to the Open Software License (OSL 3.0) - * that is bundled with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://opensource.org/licenses/osl-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/osl-3.0.php Open Software License (OSL 3.0) - */ - -/** - * Visual design editor layout model - * - * @method bool getRemoveFlag() - * @method Varien_Simplexml_Element getHandleObject() - * @method Mage_DesignEditor_Model_History_Manager_Adapter_Layout setHandleObject() - * @method Mage_DesignEditor_Model_History_Manager_Adapter_Layout setRemoveFlag() - * @method Mage_DesignEditor_Model_History_Manager_Adapter_Layout setActions() - */ -class Mage_DesignEditor_Model_History_Manager_Adapter_Layout - extends Mage_DesignEditor_Model_History_Manager_Adapter_Abstract -{ - /** - * Type add - */ - const TYPE_ADD = 'Add'; - - /** - * Type render - */ - const TYPE_RENDER = 'Render'; - - /** - * Action move - */ - const ACTION_MOVE = 'move'; - - /** - * Action remove - */ - const ACTION_REMOVE = 'remove'; - - /** - * Add action to element - * - * @param string $action - * @param array $data - * @return Mage_DesignEditor_Model_History_Manager_Adapter_Layout - */ - public function addAction($action, $data) - { - $this->_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></move>'); - $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></remove>'); - $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 cdba8065498245cd409c8f47fc1155e049e9c5b2..0000000000000000000000000000000000000000 --- a/app/code/core/Mage/DesignEditor/Model/History/Manager/Collection.php +++ /dev/null @@ -1,166 +0,0 @@ -<?php -/** - * Magento - * - * NOTICE OF LICENSE - * - * This source file is subject to the Open Software License (OSL 3.0) - * that is bundled with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://opensource.org/licenses/osl-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/osl-3.0.php Open Software License (OSL 3.0) - */ - -/** - * Visual design editor element collection - */ -class Mage_DesignEditor_Model_History_Manager_Collection -{ - /** - * Elements collection - * - * @var array - */ - protected $_elements = array(); - - /** - * Xml types - * - * @var array - */ - protected $_xmlTypes = array('layout'); - - /** - * Get types - * - * @return array - */ - protected function _getElements() - { - return $this->_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('<layout></layout>'); - - 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 0000000000000000000000000000000000000000..a546a367857f4469b365394f4919b9e71c2827ae --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/History/Renderer/LayoutUpdate.php @@ -0,0 +1,102 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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/osl-3.0.php Open Software License (OSL 3.0) + */ + +/** + * History output renderer to get layout update + */ +class Mage_DesignEditor_Model_History_Renderer_LayoutUpdate implements Mage_DesignEditor_Model_History_RendererInterface +{ + /** + * Get Layout update out of collection of changes + * + * @param Mage_DesignEditor_Model_Change_Collection $collection + * @return string + */ + public function render(Mage_DesignEditor_Model_Change_Collection $collection) + { + $dom = new DOMDocument(); + $dom->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 '<?xml version="1.0" encoding="UTF-8"?><layout></layout>'; + } + + /** + * 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 0000000000000000000000000000000000000000..a2ae9eb790c33feb87f7e750d970216d44e6400a --- /dev/null +++ b/app/code/core/Mage/DesignEditor/Model/History/RendererInterface.php @@ -0,0 +1,40 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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/osl-3.0.php Open Software License (OSL 3.0) + */ + +/** + * History output renderer interface + */ +interface Mage_DesignEditor_Model_History_RendererInterface +{ + /** + * Signature of compact method to implement in subclasses + * + * @abstract + * @param Mage_DesignEditor_Model_Change_Collection $collection + * @return string + */ + public function render(Mage_DesignEditor_Model_Change_Collection $collection); +} diff --git a/app/code/core/Mage/DesignEditor/controllers/Adminhtml/System/Design/EditorController.php b/app/code/core/Mage/DesignEditor/controllers/Adminhtml/System/Design/EditorController.php index 186b0e0d758825ac97cda35ef1e1d480212b65c3..b72aa188f9d68c33e12df8d3d5fdb42f04b99118 100644 --- a/app/code/core/Mage/DesignEditor/controllers/Adminhtml/System/Design/EditorController.php +++ b/app/code/core/Mage/DesignEditor/controllers/Adminhtml/System/Design/EditorController.php @@ -50,7 +50,7 @@ class Mage_DesignEditor_Adminhtml_System_Design_EditorController extends Mage_Ad $session->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 65281c21e563437771fc48d7e7f64a10eb63e45f..fd729d4fce7b1f41c08768577f0dce53cc7f549a 100644 --- a/app/code/core/Mage/DesignEditor/controllers/EditorController.php +++ b/app/code/core/Mage/DesignEditor/controllers/EditorController.php @@ -142,30 +142,50 @@ class Mage_DesignEditor_EditorController extends Mage_Core_Controller_Front_Acti { $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 @@ class Mage_DesignEditor_EditorController extends Mage_Core_Controller_Front_Acti 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 a84e9ecc49860ad407da6391c40602d1176aa311..0000000000000000000000000000000000000000 --- 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 7c970f34d43875820cba1d81db699df692270963..bad19fc6b17fa4f3ccef6fe599726de37279baed 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 d1a599b962280c8ffbf89b082701658c1fa0f108..487818ed10998635d83b6617cd234ebbf8c8156a 100644 --- a/app/code/core/Mage/Directory/etc/system.xml +++ b/app/code/core/Mage/Directory/etc/system.xml @@ -50,7 +50,7 @@ <source_model>Mage_Adminhtml_Model_System_Config_Source_Currency</source_model> <backend_model>Mage_Adminhtml_Model_System_Config_Backend_Currency_Base</backend_model> <sort_order>1</sort_order> - <comment><![CDATA[Base currency is used for all online payment transactions. Scope is defined by the catalog price scope ("Catalog" > "Price" > "Catalog Price Scope").]]></comment> + <comment><![CDATA[Base currency is used for all online payment transactions. If you have more than one store view, the base currency scope is defined by the catalog price scope ("Catalog" > "Price" > "Catalog Price Scope").]]></comment> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> 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 121778192c738adc054736e83c561505b9f2723b..6414b8e21d59c869175a9f64e7cb5b62b35544fc 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 a06805c6f0cd1feb350b40b548ecdd3456f80a76..5d54ff850ede23a153507795601c3a887a29f53a 100644 --- a/app/code/core/Mage/GoogleCheckout/etc/config.xml +++ b/app/code/core/Mage/GoogleCheckout/etc/config.xml @@ -131,6 +131,7 @@ <googlecheckout> <active>1</active> <model>Mage_GoogleCheckout_Model_Payment</model> + <title>Google Checkout</title> </googlecheckout> </payment> <google> 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 4c96f6552f9c50817dc378fcc8f706764c6f60cf..cca7ad84ec1f24d19cd05dba2c726cfb4e11cf21 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 @@ class Mage_GoogleOptimizer_Block_Adminhtml_Catalog_Category_Edit_Tab_Googleoptim ) ); //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 72a4bc53721174c3676f8ac9b25df418f13e335b..2a6dfb3a3c3ce5316cb9c6b65b68d83a11a0c14f 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 @@ class Mage_GoogleOptimizer_Block_Adminhtml_Catalog_Product_Edit_Tab_Googleoptimi ) ); - 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 3990d09f2b4c43688680f9680e9fac382dda00b9..8b6940ea66fa4485128f0dad4d94c7b97cdfb9ff 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 @@ class Mage_GoogleOptimizer_Block_Adminhtml_Cms_Page_Edit_Tab_Googleoptimizer ) ); - 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 82135e659901cedfd57a12bcdcab57fb1ddcdb3f..a0933ffea4019c9afd9930c6583309e6bcc26f0c 100644 --- a/app/code/core/Mage/GoogleOptimizer/Helper/Data.php +++ b/app/code/core/Mage/GoogleOptimizer/Helper/Data.php @@ -194,7 +194,7 @@ class Mage_GoogleOptimizer_Helper_Data extends Mage_Core_Helper_Abstract $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 88ab540dbc9533deae2aca4cb67e1271eab8ca3b..9ff4848516c592bd729c376d86fcccda20d6c098 100644 --- a/app/code/core/Mage/Newsletter/Model/Template.php +++ b/app/code/core/Mage/Newsletter/Model/Template.php @@ -188,7 +188,7 @@ class Mage_Newsletter_Model_Template extends Mage_Core_Model_Template $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 ab53fbadfcf5d46178e16fdca85382336c5c8743..ac0a3a3b53224396c95e1d802f715c4405334893 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 71bea5f3ff628a18672f2eceda8d6ec5caaa3694..4837b8db90be03afd4e271bde64dea672405c5bb 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 @@ class Mage_Rating_Model_Resource_Rating extends Mage_Core_Model_Resource_Db_Abst 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 7786852f078458616acdae585e5b6200d979f82e..57458a06a627c1602192a55eed42a48738c65b26 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 @@ class Mage_Rating_Model_Resource_Rating_Collection extends Mage_Core_Model_Resou */ 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 @@ class Mage_Rating_Model_Resource_Rating_Collection extends Mage_Core_Model_Resou ->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 @@ class Mage_Rating_Model_Resource_Rating_Collection extends Mage_Core_Model_Resou ->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 @@ class Mage_Rating_Model_Resource_Rating_Collection extends Mage_Core_Model_Resou */ public function addStoresToCollection() { + if ($this->_app->isSingleStoreMode()) { + return $this; + } if (!$this->_isCollectionLoaded) { return $this; } @@ -257,4 +293,16 @@ class Mage_Rating_Model_Resource_Rating_Collection extends Mage_Core_Model_Resou } 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 54d71ddb620c5c48e54cbcafc488f3ac1bc159ef..740937d055197b4580340794008fed982908befb 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 @@ class Mage_Rating_Model_Resource_Rating_Option_Vote_Collection extends Mage_Core */ 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 @@ class Mage_Rating_Model_Resource_Rating_Option_Vote_Collection extends Mage_Core $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 c123024ef55e5031ca5f8813a0653421fcfe37e8..0beefa33f085b54afdab527d302297d1b0019613 100644 --- a/app/code/core/Mage/Rating/etc/config.xml +++ b/app/code/core/Mage/Rating/etc/config.xml @@ -28,7 +28,7 @@ <config> <modules> <Mage_Rating> - <version>1.6.0.0</version> + <version>1.6.0.1</version> <active>true</active> <codePool>core</codePool> <depends> 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 0000000000000000000000000000000000000000..1b26623b71fa2b4dc4fbcb0fc8d9706a94bedf95 --- /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 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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_Rating + * @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 $installer Mage_Core_Model_Resource_Setup */ +$installer = $this; + +$installer->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 457fa81525a3c0a064e2287c8574316ac8a09c2f..09358d180450f2c2a5118fd44d605647266b90ee 100644 --- a/app/code/core/Mage/Reports/etc/system.xml +++ b/app/code/core/Mage/Reports/etc/system.xml @@ -45,6 +45,7 @@ <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> + <hide_in_single_store_mode>1</hide_in_single_store_mode> </scope> <viewed_count translate="label"> <label>Default Recently Viewed Products Count</label> diff --git a/app/code/core/Mage/Review/Block/Form.php b/app/code/core/Mage/Review/Block/Form.php index f81d3f988fee11e8a77241c37eec8cf0ff0a1015..ae81850b1e534e24cd1edc924c7b0452cdb08484 100644 --- a/app/code/core/Mage/Review/Block/Form.php +++ b/app/code/core/Mage/Review/Block/Form.php @@ -90,6 +90,7 @@ class Mage_Review_Block_Form extends Mage_Core_Block_Template ->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 c35f5a5c7df32a5036b8538a80545af991e859c5..4bd14848ac1a9961640b0ca6f71a47e8c3ef403b 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 @@ class Mage_Review_Model_Resource_Review extends Mage_Core_Model_Resource_Db_Abst ->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 b0d62cf8035801eba811063182dcad469ed77708..46f3ac39b4c5e623f5fa6fe573c16326cef87cbc 100644 --- a/app/code/core/Mage/Sales/etc/config.xml +++ b/app/code/core/Mage/Sales/etc/config.xml @@ -573,13 +573,6 @@ </events> </adminhtml> <default> - <payment> - <googlecheckout> - <active>1</active> - <model>Mage_GoogleCheckout_Model_Payment</model> - <title>Google Checkout</title> - </googlecheckout> - </payment> <sales> <totals_sort> <discount>20</discount> 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 710278c4c36c7bc0f93b3077b3c2b69acc291eda..103d0129e987e58dc591969597e82571d59d8244 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 a4559043cc6cb89b4c4ddc0c0c7cea537f92bd2a..c4f48df0a54872d5510b58e6df6cf00c97aa8abb 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 @@ class Mage_Weee_Block_Renderer_Weee_Tax extends Mage_Adminhtml_Block_Widget impl public function isMultiWebsites() { - return !Mage::app()->isSingleStoreMode(); + return !Mage::app()->hasSingleStore(); } public function getCountries() @@ -120,7 +120,7 @@ class Mage_Weee_Block_Renderer_Weee_Tax extends Mage_Adminhtml_Block_Widget impl '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 1fa45b2bdb12f4bfb4d220fb77f81a54ad8b5c29..2ac0c6f6fdf1ea8952e2df02a7d9f00e5b6f5a87 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 6fe6f11607bcb78aaa9bd64551f50f800e6022b6..f2ef239cac6376c8d0efe469afa086b2bdee5325 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 @@ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_General /** * 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 e155bbaf82b19aad7170ebf1800ce4b99759ee19..e24253db4e8226472f2308121b3b85d74f83ea80 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 @@ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Payment /** * 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 a1aa5eed28b5cb052f9dd52d6310a6a299852610..01e42e182ab51d0bc0c550f412c4893f9b3f9edd 100755 --- a/app/code/core/Mage/XmlConnect/Model/Queue.php +++ b/app/code/core/Mage/XmlConnect/Model/Queue.php @@ -173,7 +173,7 @@ class Mage_XmlConnect_Model_Queue extends Mage_Core_Model_Template $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 017f1c890721e0ebcb706f9c1fafa884dbfb9293..16b79133d7f74b2106ed33cb9a8cba3187dbf3b8 100755 --- a/app/code/core/Mage/XmlConnect/Model/Template.php +++ b/app/code/core/Mage/XmlConnect/Model/Template.php @@ -85,7 +85,7 @@ class Mage_XmlConnect_Model_Template extends Mage_Core_Model_Template $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 56bbe9e18b5f4070660be610aceb3bd5a3d78cb1..c5499ddcfabb0c2da4421e4aba9baa988d97e4f9 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 9f5317211f463e1c1435c09788c54f23f76ca9a0..5e8f1f0824dc8ba23fcca18df4512469f3521df7 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 @@ class Mage_Adminhtml_Block_System_Config_FormTest extends PHPUnit_Framework_Test '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 0000000000000000000000000000000000000000..aa78d1b0b5f2d01ef84f2d8394266b91558da6a6 --- /dev/null +++ b/dev/tests/integration/testsuite/Mage/Adminhtml/Model/Config/DataTest.php @@ -0,0 +1,74 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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 Magento + * @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) + */ + +/** + * @group module:Mage_Adminhtml + */ +class Mage_Adminhtml_Model_Config_DataTest extends PHPUnit_Framework_TestCase +{ + /** + * @param array $groups + * @magentoDbIsolation enabled + * @dataProvider saveDataProvider + * @magentoConfigFixture current_store general/single_store_mode/enabled 1 + */ + public function testSaveWithSingleStoreModeEnabled($groups) + { + $_configDataObject = new Mage_Adminhtml_Model_Config_Data(); + $_configData = $_configDataObject->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 df3de47429e30ac71a03cb1f1c34d58063e9e23e..6c3e40e64a846b3730766e0eaac02602b2ab7799 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 0000000000000000000000000000000000000000..cac290623ed28d3b5510bc8158586371e71276f8 --- /dev/null +++ b/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/Catalog/CategoryControllerTest.php @@ -0,0 +1,208 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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. + * + * @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_Adminhtml_Catalog_CategoryControllerTest extends Mage_Adminhtml_Utility_Controller +{ + /** + * @magentoDataFixture Mage/Core/_files/store.php + * @magentoDbIsolation enabled + * @dataProvider saveActionDataProvider + * @param array $inputData + * @param array $defaultAttributes + * @param array $attributesSaved + */ + public function testSaveAction($inputData, $defaultAttributes, $attributesSaved = array()) + { + $store = new Mage_Core_Model_Store(); + $store->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 0000000000000000000000000000000000000000..54b58f672466aac2a94b102b098ac2ed731c26a9 --- /dev/null +++ b/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/NewsletterQueueControllerTest.php @@ -0,0 +1,77 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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_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_Adminhtml_Newsletter_QueueControllerTest extends Mage_Adminhtml_Utility_Controller +{ + /** + * @var Mage_Newsletter_Model_Template + */ + protected $_model; + + public function setUp() + { + parent::setUp(); + $this->_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 0000000000000000000000000000000000000000..97d5a20adf5f5e9fdb5c889c97b30d2b7dcbef6d --- /dev/null +++ b/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/NewsletterTemplateControllerTest.php @@ -0,0 +1,152 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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_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_Adminhtml_Newsletter_TemplateControllerTest extends Mage_Adminhtml_Utility_Controller +{ + /** + * @var Mage_Newsletter_Model_Template + */ + protected $_model; + + public function setUp() + { + parent::setUp(); + $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->_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 1369a4e26cf5a3f85190174f4600c3489f6703c1..cfb9c811b0907c0edd7a78b1d8adee57f6ec2feb 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 2c996be2fe9d7520331d9cad815c16ca35bd2a72..1b475f54052d8e55f4056fd47df7cdd5d9c130cf 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 @@ class Mage_Core_Model_AppTest extends PHPUnit_Framework_TestCase $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 4959e062b8496a8d8c9f932ce70427afa74bb671..ce98f907af42f4d59bee521f09caa3df5aac1d52 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 @@ class Mage_Core_Model_CacheTest extends PHPUnit_Framework_TestCase /** * @return array */ - public function backendTwoLevelsDataProvider() + public function constructorBackendTwoLevelsDataProvider() { return array( array('Memcached', 'memcached'), @@ -100,242 +78,8 @@ class Mage_Core_Model_CacheTest extends PHPUnit_Framework_TestCase ); } - 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 0000000000000000000000000000000000000000..60d33cf7eaa2208f21218ee25a9c25280a96a9c4 --- /dev/null +++ b/dev/tests/integration/testsuite/Mage/Core/Model/Resource/Db/Collection/AbstractTest.php @@ -0,0 +1,69 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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. + * + * @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_Model_Resource_Db_Collection_AbstractTest extends PHPUnit_Framework_TestCase +{ + /** + * @var Mage_Core_Model_Resource_Db_Collection_Abstract + */ + protected $_model = null; + + protected function setUp() + { + $resource = $this->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 0000000000000000000000000000000000000000..11d8f4a21915e067866225a1483b8f3d5263f1db --- /dev/null +++ b/dev/tests/integration/testsuite/Mage/DesignEditor/Model/History/CompactTest.php @@ -0,0 +1,135 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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 Magento + * @package Mage_DesignEditor + * @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_DesignEditor_Model_History_CompactTest extends PHPUnit_Framework_TestCase +{ + /** + * @var Mage_DesignEditor_Model_History + */ + protected $_historyObject; + + /** + * Prepare history object + * + * @return Mage_Core_Model_Abstract + */ + public function setUp() + { + return $this->_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 3de267e5c6ee7d8c0485a41f675a89752dcd5195..fbb1ae6070cbb17854f4e57fd0ae0aeb3f6d303a 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 90e4508c24588adb1db018bc05dfc4c2672fdcf2..cb845ff88ab9683e50d49baa7f2d4e63f0563412 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 @@ */ --> <layout> + <customer_account> + <move element="customer_account_navigation" after="-" destination="right"/> + </customer_account> <catalog_category_view> <remove name="category.products"/> </catalog_category_view> - <customer_account> - <move element="customer_account_navigation" as="customer_account_navigation_alias" destination="top.menu" after="-"/> - </customer_account> </layout> diff --git a/dev/tests/static/testsuite/Integrity/ConfigTest.php b/dev/tests/static/testsuite/Integrity/ConfigTest.php index acc9a656b0aab7a46ab98c69cdd0d1172adf575f..f445309c62dcf76d3f005d5a9689ae41d821536e 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 @@ class Integrity_ConfigTest extends PHPUnit_Framework_TestCase '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 70dbef97cb694ba535bf2b3b91603b6d9735d122..c250c47478bcae286a7c156de9bde1091cf82324 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 43cdc0f962b45510d7e5ae0708d393eaabb94c3a..58d56cead947c89cb002bb246abbd02c602e79d5 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 0000000000000000000000000000000000000000..6ce3aab4e7b78beb845fee17858df5abd6ae95d0 --- /dev/null +++ b/dev/tests/unit/testsuite/Mage/Adminhtml/Model/ConfigTest.php @@ -0,0 +1,82 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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 Magento + * @package Mage_Adminhtml + * @subpackage unit_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_Adminhtml_Model_ConfigTest extends PHPUnit_Framework_TestCase +{ + + /** + * @param Varien_Simplexml_Element $xmlData + * @param boolean $isSingleStoreMode + * @param Varien_Simplexml_Element $node + * @param string $website + * @param string $store + * @param mixed $expectedResult + * @param string $message + * @dataProvider addItemFilterDataProvider + */ + public function testHasChildren($xmlData, $isSingleStoreMode, $node, $website, $store, $expectedResult, $message) + { + $app = $this->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 0000000000000000000000000000000000000000..dc3b24fe8c6c6318468ff5f25bbe576b8a9f0cb9 --- /dev/null +++ b/dev/tests/unit/testsuite/Mage/Adminhtml/Model/_files/system.xml @@ -0,0 +1,143 @@ +<?xml version="1.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_Core + * @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) + */ +--> +<config> + <tabs> + <general translate="label" module="Mage_Core"> + <label>General</label> + <sort_order>100</sort_order> + </general> + <service translate="label" module="Mage_Core"> + <label>Services</label> + <sort_order>99999</sort_order> + </service> + <advanced translate="label" module="Mage_Core"> + <label>Advanced</label> + <sort_order>999999</sort_order> + </advanced> + </tabs> + <sections> + <dev translate="label" module="Mage_Core"> + <label>Developer</label> + <tab>advanced</tab> + <frontend_type>text</frontend_type> + <sort_order>920</sort_order> + <show_in_default>1</show_in_default> + <show_in_website>1</show_in_website> + <show_in_store>1</show_in_store> + <resource>Mage_Adminhtml::dev</resource> + <groups> + <debug translate="label"> + <label>Debug</label> + <frontend_type>text</frontend_type> + <sort_order>20</sort_order> + <show_in_default>1</show_in_default> + <show_in_website>1</show_in_website> + <show_in_store>1</show_in_store> + <fields> + <template_hints translate="label"> + <label>Template Path Hints</label> + <frontend_type>select</frontend_type> + <source_model>Mage_Adminhtml_Model_System_Config_Source_Yesno</source_model> + <sort_order>20</sort_order> + <show_in_default>0</show_in_default> + <show_in_website>1</show_in_website> + <show_in_store>1</show_in_store> + </template_hints> + <template_hints_blocks translate="label"> + <label>Add Block Names to Hints</label> + <frontend_type>select</frontend_type> + <source_model>Mage_Adminhtml_Model_System_Config_Source_Yesno</source_model> + <sort_order>21</sort_order> + <show_in_default>0</show_in_default> + <show_in_website>1</show_in_website> + <show_in_store>1</show_in_store> + </template_hints_blocks> + </fields> + </debug> + <css translate="label"> + <label>CSS Settings</label> + <frontend_type>text</frontend_type> + <sort_order>110</sort_order> + <show_in_default>1</show_in_default> + <show_in_website>1</show_in_website> + <show_in_store>1</show_in_store> + <fields> + <merge_css_files translate="label"> + <label>Merge CSS Files</label> + <frontend_type>select</frontend_type> + <source_model>Mage_Adminhtml_Model_System_Config_Source_Yesno</source_model> + <sort_order>10</sort_order> + <show_in_default>1</show_in_default> + <show_in_website>1</show_in_website> + <show_in_store>1</show_in_store> + </merge_css_files> + </fields> + </css> + <js translate="label"> + <label>JavaScript Settings</label> + <frontend_type>text</frontend_type> + <sort_order>100</sort_order> + <show_in_default>1</show_in_default> + <show_in_website>1</show_in_website> + <show_in_store>1</show_in_store> + <fields> + <merge_files translate="label"> + <label>Merge JavaScript Files</label> + <frontend_type>select</frontend_type> + <source_model>Mage_Adminhtml_Model_System_Config_Source_Yesno</source_model> + <sort_order>10</sort_order> + <show_in_default>0</show_in_default> + <show_in_website>0</show_in_website> + <show_in_store>1</show_in_store> + </merge_files> + </fields> + </js> + <price translate="label"> + <label>Price Settings</label> + <frontend_type>text</frontend_type> + <sort_order>100</sort_order> + <show_in_default>1</show_in_default> + <show_in_website>1</show_in_website> + <show_in_store>1</show_in_store> + <fields> + <price_files translate="label"> + <label>Price Files</label> + <frontend_type>select</frontend_type> + <source_model>Mage_Adminhtml_Model_System_Config_Source_Yesno</source_model> + <sort_order>10</sort_order> + <show_in_default>1</show_in_default> + <show_in_website>0</show_in_website> + <show_in_store>0</show_in_store> + <hide_in_single_store_mode>1</hide_in_single_store_mode> + </price_files> + </fields> + </price> + </groups> + </dev> + </sections> +</config> 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 6df98c2f5d477009aa101b3acd4887c896c1d60f..4f7a4319ffd298b6c5d5dc616c3175a48d82d467 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 @@ class Mage_Backend_Model_Menu_ConfigTest extends PHPUnit_Framework_TestCase $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 @@ class Mage_Backend_Model_Menu_ConfigTest extends PHPUnit_Framework_TestCase $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 @@ class Mage_Backend_Model_Menu_ConfigTest extends PHPUnit_Framework_TestCase $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('<?xml version="1.0" encoding="utf-8"?><config><menu></menu></config>')); + + $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 @@ class Mage_Backend_Model_Menu_ConfigTest extends PHPUnit_Framework_TestCase { $xmlString = '<?xml version="1.0" encoding="utf-8"?><config><menu></menu></config>'; - $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 @@ class Mage_Backend_Model_Menu_ConfigTest extends PHPUnit_Framework_TestCase ->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('<?xml version="1.0" encoding="utf-8"?><config><menu></menu></config>')); + + $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 @@ class Mage_Backend_Model_Menu_ConfigTest extends PHPUnit_Framework_TestCase ->method('saveXML') ->will($this->returnValue('<?xml version="1.0" encoding="utf-8"?><config><menu></menu></config>')); + $this->_menuBuilderMock->expects($this->exactly(1)) + ->method('getResult') + ->will($this->returnValue($this->_menuMock)); + $this->_model->getMenu(); } @@ -187,7 +262,7 @@ class Mage_Backend_Model_Menu_ConfigTest extends PHPUnit_Framework_TestCase ->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 @@ class Mage_Backend_Model_Menu_ConfigTest extends PHPUnit_Framework_TestCase ->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 @@ class Mage_Backend_Model_Menu_ConfigTest extends PHPUnit_Framework_TestCase $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 @@ class Mage_Backend_Model_Menu_ConfigTest extends PHPUnit_Framework_TestCase $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 @@ class Mage_Backend_Model_Menu_ConfigTest extends PHPUnit_Framework_TestCase 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 0000000000000000000000000000000000000000..647377f88a7c24d203187430baebb1f4a18a4575 --- /dev/null +++ b/dev/tests/unit/testsuite/Mage/Catalog/Model/Category/Attribute/Backend/SortbyTest.php @@ -0,0 +1,81 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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. + * + * @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_Catalog_Model_Category_Attribute_Backend_SortbyTest extends PHPUnit_Framework_TestCase +{ + const DEFAULT_ATTRIBUTE_CODE = 'attribute_name'; + + /** + * @var Mage_Catalog_Model_Category_Attribute_Backend_Sortby + */ + protected $_model; + + protected function setUp() + { + $this->_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 0000000000000000000000000000000000000000..b57ebabe257ef0f050ab9020495759241a05eede --- /dev/null +++ b/dev/tests/unit/testsuite/Mage/Core/Model/CacheTest.php @@ -0,0 +1,455 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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 Magento + * @package Mage_Core + * @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_Model_CacheTest extends PHPUnit_Framework_TestCase +{ + /** + * @var Mage_Core_Model_Cache + */ + protected $_model; + + /** + * @var Mage_Core_Model_Config + */ + protected $_config; + + /** + * @var Mage_Core_Helper_Abstract + */ + protected $_helper; + + /** + * @var Zend_Cache_Backend|PHPUnit_Framework_MockObject_MockObject + */ + protected $_cacheFrontend; + + /** + * @var stdClass|PHPUnit_Framework_MockObject_MockObject + */ + protected $_requestProcessor; + + public function setUp() + { + $this->_config = new Mage_Core_Model_Config(<<<XML + <config> + <global> + <cache> + <types> + <single_tag> + <label>Tag One</label> + <description>This is Tag One</description> + <tags>tag_one</tags> + </single_tag> + <multiple_tags> + <label>Tags One and Two</label> + <description>These are Tags One and Two</description> + <tags>tag_one,tag_two</tags> + </multiple_tags> + </types> + </cache> + </global> + </config> +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 0000000000000000000000000000000000000000..7b5fa56cfda2b977c2907a663844a9dec775ab1f --- /dev/null +++ b/dev/tests/unit/testsuite/Mage/Core/Model/Config/OptionsTest.php @@ -0,0 +1,141 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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 Magento + * @package Mage_Core + * @subpackage unit_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_Model_Config_OptionsTest extends PHPUnit_Framework_TestCase +{ + /** + * @var Mage_Core_Model_Config_Options + */ + protected $_model; + + /** + * @var array + */ + protected $_sourceData; + + /** + * @var array + */ + protected $_varDir; + + protected function setUp() + { + $rootDir = dirname(__FILE__); + $ioModel = $this->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 0000000000000000000000000000000000000000..90cd647caff053d6da231f504277ba31d32f5d3b --- /dev/null +++ b/dev/tests/unit/testsuite/Mage/Core/Model/ConfigTest.php @@ -0,0 +1,53 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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 Magento + * @package Mage_Core + * @subpackage unit_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_Model_ConfigTest extends PHPUnit_Framework_TestCase +{ + /** + * @var Mage_Core_Model_Config + */ + protected $_model; + + /** + * @dataProvider constructorDataProvider + */ + public function testConstructor($data) + { + $this->_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('<body></body>')), + ); + } + +} \ 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 1e97d7fb6342d5579b73dd234f37a8d29c24f5d8..0c1e1399a6668ab24a92c7d7fb1dbc11ea8b8520 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 @@ class Mage_Core_Model_Resource_Setup_MigrationTest extends PHPUnit_Framework_Tes '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 0000000000000000000000000000000000000000..b4d113be367ff7369b7397d9b3b23c88438bd400 --- /dev/null +++ b/dev/tests/unit/testsuite/Mage/DesignEditor/Model/Change/CollectionTest.php @@ -0,0 +1,60 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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 Magento + * @package Mage_DesignEditor + * @subpackage unit_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_DesignEditor_Model_Change_CollectionTest extends PHPUnit_Framework_TestCase +{ + /** + * Collection model for testing + * + * @var Mage_DesignEditor_Model_Change_Collection + */ + protected $_model; + + public function setUp() + { + parent::setUp(); + $this->_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 0000000000000000000000000000000000000000..6eeb63c6bf89f964ed18e322b0dd67b19f5f0686 --- /dev/null +++ b/dev/tests/unit/testsuite/Mage/DesignEditor/Model/History/Compact/LayoutTest.php @@ -0,0 +1,141 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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 Magento + * @package Mage_DesignEditor + * @subpackage unit_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_DesignEditor_Model_History_Compact_LayoutTest extends PHPUnit_Framework_TestCase +{ + /** + * Layout object + * + * @var Mage_DesignEditor_Model_History_Compact_Layout + */ + protected $_layout; + + /** + * Init test environment + */ + protected function setUp() + { + $this->_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 0000000000000000000000000000000000000000..1feba86c6bea3ef5d7d1c07765144d3d222384f8 --- /dev/null +++ b/dev/tests/unit/testsuite/Mage/DesignEditor/Model/History/Renderer/LayoutUpdateTest.php @@ -0,0 +1,113 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-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 Magento + * @package Mage_DesignEditor + * @subpackage unit_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_DesignEditor_Model_History_Renderer_LayoutUpdateTest extends PHPUnit_Framework_TestCase +{ + /** + * Layout update renderer + * + * @var null|Mage_DesignEditor_Model_History_Renderer_LayoutUpdate + */ + protected $_layoutRenderer; + + /** + * Init test environment + */ + protected function setUp() + { + $this->_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 c1fa74fc4287dade6a7b20e39df13fa6620fc0fa..0000000000000000000000000000000000000000 --- a/dev/tests/unit/testsuite/Mage/DesignEditor/Model/HistoryTest.php +++ /dev/null @@ -1,226 +0,0 @@ -<?php -/** - * Magento - * - * NOTICE OF LICENSE - * - * This source file is subject to the Open Software License (OSL 3.0) - * that is bundled with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://opensource.org/licenses/osl-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 Magento - * @package Mage_DesignEditor - * @subpackage unit_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_DesignEditor_Model_HistoryTest extends PHPUnit_Framework_TestCase -{ - /** - * @covers Mage_DesignEditor_Model_History::getCompactLog - */ - public function testGetCompactLog() - { - $methods = array('_getManagerModel'); - /** @var $historyMock Mage_DesignEditor_Model_History */ - $historyMock = $this->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 69575262cfebed7dfc62601ed00e2f2b7ba79ef8..0000000000000000000000000000000000000000 --- a/dev/tests/unit/testsuite/Mage/DesignEditor/Model/Manager/Adapter/LayoutTest.php +++ /dev/null @@ -1,105 +0,0 @@ -<?php -/** - * Magento - * - * NOTICE OF LICENSE - * - * This source file is subject to the Open Software License (OSL 3.0) - * that is bundled with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://opensource.org/licenses/osl-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 Magento - * @package Mage_DesignEditor - * @subpackage unit_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_DesignEditor_Model_Manager_LayoutTest extends PHPUnit_Framework_TestCase -{ - /** - * @cove Mage_DesignEditor_Model_History_Manager_Adapter_Layout::addAction - * @dataProvider moveChangeData - */ - public function testAddAction($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 - ); - $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('<layout></layout>'); - $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 46a9cf4cddde8080b293101f70f53e1948915005..0000000000000000000000000000000000000000 --- a/dev/tests/unit/testsuite/Mage/DesignEditor/Model/_files/history/layout/remove.xml +++ /dev/null @@ -1,31 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- -/** - * 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 Magento - * @package Mage_DesignEditor - * @subpackage unit_tests - * @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) - */ ---> -<layout> - <remove name="customer_account_navigation"/> -</layout> 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 90a778d14f156fb4fb530a4a9ff2525cf528b1ae..b167c84b02d1b93767a3883619a11fc21113a21c 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 @@ */ --> <layout> - <move element="customer_account_navigation" as="customer_account_navigation_alias" destination="top.menu" after="-"/> + <catalog_category_view> + <move element="category.products" after="-" destination="right"/> + </catalog_category_view> + <customer_account> + <remove name="customer_account_navigation"/> + </customer_account> </layout> + diff --git a/lib/Varien/Data/Form/Element/Editor.php b/lib/Varien/Data/Form/Element/Editor.php index 3c09a52dafff49431e61b96c57b129b186271cae..35ef45b4b2747d9789fb7a467cb4095e82a06894 100644 --- a/lib/Varien/Data/Form/Element/Editor.php +++ b/lib/Varien/Data/Form/Element/Editor.php @@ -192,8 +192,9 @@ class Varien_Data_Form_Element_Editor extends Varien_Data_Form_Element_Textarea 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/"