From 0f6ce9e24ce36e3507fdbfbce46fe5c0a9cf2cb8 Mon Sep 17 00:00:00 2001 From: Santiago Date: Tue, 25 Jul 2017 16:08:28 -0300 Subject: [PATCH 1/2] Fix missing listId error when deleting store. resolves #407 --- .../Ebizmarts/MailChimp/Helper/Data.php | 20 +++++++++++------ .../Ebizmarts/MailChimp/Helper/DataTest.php | 22 +++++++++++++++++++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index 762e58a55..98e06bc77 100755 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php @@ -618,7 +618,7 @@ public function createStore($listId, $scopeId, $scope) $mailchimpStoreId = md5($this->getMCStoreName($scopeId, $scope) . '_' . $date); //create store in mailchimp try { - $response = Mage::getModel('mailchimp/api_stores')->createMailChimpStore($mailchimpStoreId, $listId, $scopeId, $scope); + $response = $this->getApiStores()->createMailChimpStore($mailchimpStoreId, $listId, $scopeId, $scope); //save in config $configValues = array( array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID, $mailchimpStoreId), @@ -648,13 +648,14 @@ public function deleteStore($scopeId, $scope) $mailchimpStoreId = $this->getMCStoreId($scopeId, $scope); if (!empty($mailchimpStoreId)) { try { - Mage::getModel('mailchimp/api_stores')->deleteMailChimpStore($mailchimpStoreId, $scopeId, $scope); + $this->getApiStores()->deleteMailChimpStore($mailchimpStoreId, $scopeId, $scope); } catch (MailChimp_Error $e) { - Mage::helper('mailchimp')->logError($e->getFriendlyMessage(), $scopeId, $scope); + $this->logError($e->getFriendlyMessage(), $scopeId, $scope); } //delete configured webhook - $this->deleteCurrentWebhook($scopeId, $scope); + $listId = $this->getGeneralList($scopeId, $scope); + $this->deleteCurrentWebhook($scopeId, $scope, $listId); //clear store config values $this->deleteLocalMCStoreData($scopeId, $scope); } @@ -781,7 +782,7 @@ public function changeName($name, $scopeId, $scope) { if ($this->getMCStoreId($scopeId, $scope) && $this->getIfConfigExistsForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID, $scopeId, $scope)) { try { - Mage::getModel('mailchimp/api_stores')->modifyName($name, $scopeId, $scope); + $this->getApiStores()->modifyName($name, $scopeId, $scope); } catch (MailChimp_Error $e) { Mage::helper('mailchimp')->logError($e->getFriendlyMessage(), $scopeId, $scope); } @@ -1062,7 +1063,7 @@ public function getMCJs() if ($this->isEcomSyncDataEnabled($storeId)) { $url = $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_MC_JS_URL, $storeId); if (!$url) { - $url = Mage::getModel('mailchimp/api_stores')->getMCJsUrl($storeId, 'stores'); + $url = $this->getApiStores()->getMCJsUrl($storeId, 'stores'); } $script = ''; } @@ -1448,7 +1449,7 @@ protected function _setIsSyncingInAllStores($syncValue) $mailchimpApi = $this->getApi($storeId); $mailchimpStoreId = $this->getMCStoreId($storeId); if ($mailchimpStoreId) { - Mage::getModel('mailchimp/api_stores')->editIsSyncing($mailchimpApi, $syncValue, $mailchimpStoreId, $storeId); + $this->getApiStores()->editIsSyncing($mailchimpApi, $syncValue, $mailchimpStoreId, $storeId); } } } @@ -1866,4 +1867,9 @@ public function addEntriesToArray($batchArray, $productData, $counter) } return array($batchArray, $counter); } + + protected function getApiStores() + { + return Mage::getModel('mailchimp/api_stores'); + } } diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php index eccf146df..9ea6ceeed 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php @@ -45,4 +45,26 @@ public function testCustomMergeFieldAlreadyExists() $this->assertTrue($helperMock->customMergeFieldAlreadyExists("FNAME", 0, "store")); } + + public function testDeleteStore() + { + $scopeId = 1; + $scope = 'stores'; + $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) + ->disableOriginalConstructor() + ->setMethods(array('getMCStoreId', 'getApiStores', 'getGeneralList', 'deleteCurrentWebhook', 'deleteLocalMCStoreData', 'logError')) + ->getMock(); + $apiStoresMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Api_Stores::class) + ->disableOriginalConstructor() + ->getMock(); + + $helperMock->expects($this->once())->method('getMCStoreId')->with($scopeId, $scope)->willReturn('a18a1a8a1aa7aja1a'); + $helperMock->expects($this->once())->method('getApiStores')->willReturn($apiStoresMock); + $helperMock->expects($this->once())->method('logError')->with('Error message', $scopeId, $scope); + $helperMock->expects($this->once())->method('getGeneralList')->with($scopeId, $scope)->willReturn('listId'); + $helperMock->expects($this->once())->method('deleteCurrentWebhook')->with($scopeId, $scope, 'listId'); + $helperMock->expects($this->once())->method('deleteLocalMCStoreData')->with($scopeId, $scope); + + $helperMock->deleteStore($scopeId, $scope); + } } \ No newline at end of file From 39d027a39e9433d7aac60b595168049aa69a0ac2 Mon Sep 17 00:00:00 2001 From: Santiago Date: Tue, 25 Jul 2017 16:39:35 -0300 Subject: [PATCH 2/2] Test fixes. --- .../tests/app/Ebizmarts/MailChimp/Helper/DataTest.php | 3 +-- .../tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php index 9ea6ceeed..49d0d511b 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php @@ -52,7 +52,7 @@ public function testDeleteStore() $scope = 'stores'; $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) ->disableOriginalConstructor() - ->setMethods(array('getMCStoreId', 'getApiStores', 'getGeneralList', 'deleteCurrentWebhook', 'deleteLocalMCStoreData', 'logError')) + ->setMethods(array('getMCStoreId', 'getApiStores', 'getGeneralList', 'deleteCurrentWebhook', 'deleteLocalMCStoreData')) ->getMock(); $apiStoresMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Api_Stores::class) ->disableOriginalConstructor() @@ -60,7 +60,6 @@ public function testDeleteStore() $helperMock->expects($this->once())->method('getMCStoreId')->with($scopeId, $scope)->willReturn('a18a1a8a1aa7aja1a'); $helperMock->expects($this->once())->method('getApiStores')->willReturn($apiStoresMock); - $helperMock->expects($this->once())->method('logError')->with('Error message', $scopeId, $scope); $helperMock->expects($this->once())->method('getGeneralList')->with($scopeId, $scope)->willReturn('listId'); $helperMock->expects($this->once())->method('deleteCurrentWebhook')->with($scopeId, $scope, 'listId'); $helperMock->expects($this->once())->method('deleteLocalMCStoreData')->with($scopeId, $scope); diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php index 4cbfcbcfb..b2ba14efe 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/BatchesTest.php @@ -28,7 +28,7 @@ public function testSendEcommerceBatch() $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) ->disableOriginalConstructor() - ->setMethods(array('getMCStoreId', 'isMailChimpEnabled', 'isEcomSyncDataEnabled', 'getApi', 'getIsReseted')) + ->setMethods(array('getMCStoreId', 'isMailChimpEnabled', 'isEcomSyncDataEnabled', 'getApi', 'getIsReseted', 'getMCIsSyncing')) ->getMock(); $apiCustomersMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Api_Customers::class) @@ -56,7 +56,7 @@ public function testSendEcommerceBatch() $apiMock = $this->getMockBuilder(Ebizmarts_MailChimp::class) ->disableOriginalConstructor() - // ->setMethods(array('')) +// ->setMethods(array('edit')) ->getMock(); $apiBatchesMock->expects($this->once())->method('getHelper')->willReturn($helperMock); @@ -69,6 +69,7 @@ public function testSendEcommerceBatch() $helperMock->expects($this->once())->method('getMCStoreId')->with(1)->willReturn('b81c3085c51fa593e1d6b0cf59884f3e'); $helperMock->expects($this->once())->method('isMailChimpEnabled')->with(1)->willReturn(1); $helperMock->expects($this->once())->method('isEcomSyncDataEnabled')->with(1)->willReturn(1); + $helperMock->expects($this->once())->method('getMCIsSyncing')->with(1)->willReturn(0); $apiCustomersMock->expects($this->once())->method('createBatchJson')->with('b81c3085c51fa593e1d6b0cf59884f3e', 1); $apiProductsMock->expects($this->once())->method('createBatchJson')->with('b81c3085c51fa593e1d6b0cf59884f3e', 1);