diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index 106145d14..71b19dc30 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); } } } @@ -1867,6 +1868,11 @@ public function addEntriesToArray($batchArray, $productData, $counter) return array($batchArray, $counter); } + protected function getApiStores() + { + return Mage::getModel('mailchimp/api_stores'); + } + public function getCheckoutSubscribeValue($scopeId, $scope = 'stores') { return $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_CHECKOUT_SUBSCRIBE, $scopeId, $scope); 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 fa94208e3..33cfbd922 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php @@ -63,4 +63,25 @@ public function testIsCheckoutSubscribeEnabled() $this->assertTrue($helperMock->isCheckoutSubscribeEnabled(1, "stores")); } + + public function testDeleteStore() + { + $scopeId = 1; + $scope = 'stores'; + $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) + ->disableOriginalConstructor() + ->setMethods(array('getMCStoreId', 'getApiStores', 'getGeneralList', 'deleteCurrentWebhook', 'deleteLocalMCStoreData')) + ->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('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 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);