Skip to content

Commit

Permalink
Merge pull request #1255 from mailchimp/issue_1254
Browse files Browse the repository at this point in the history
Fixing tests
  • Loading branch information
roberto-ebizmarts authored Aug 9, 2021
2 parents 9e7b9de + 2de745f commit a4cfb1b
Showing 1 changed file with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ public function testProcessMergeFieldsWithCustomer()
)
->getMock();

$subscriberMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Api_Subscribers::class)
->disableOriginalConstructor()
->setMethods(array('getId', 'setSubscriberFirstname', 'setSubscriberLastname', 'save'))
->getMock();

$helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class)
->disableOriginalConstructor()
->setMethods(
Expand All @@ -208,12 +213,18 @@ public function testProcessMergeFieldsWithCustomer()
)
->getMock();

// Get's into the Subscriber creation/get part.
$helperMock->expects($this->once())
->method('loadListSubscriber')
->with($data['list_id'], $data['email'])
->willReturn($subscriberMock);

$customerMock = $this->getMockBuilder(Mage_Customer_Model_Customer::class)
->disableOriginalConstructor()
->setMethods(array('getFirstName','setFirstName','getLastName','setLastName','save'))
->getMock();

$mailchimpTagsApiMock->expects($this->once())
$mailchimpTagsApiMock->expects($this->exactly(2))
->method('getMailchimpHelper')
->willReturn($helperMock);

Expand Down Expand Up @@ -283,10 +294,10 @@ public function testProcessMergeFieldsWithoutCustomer()

$subscriberMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Api_Subscribers::class)
->disableOriginalConstructor()
->setMethods(array('getId', 'setSubscriberFirstname', 'setSubscriberLastname', 'save'))
->setMethods(array('getId', 'getStatus', 'setSubscriberFirstname', 'setSubscriberLastname', 'save'))
->getMock();

$mailchimpTagsApiMock->expects($this->once())
$mailchimpTagsApiMock->expects($this->exactly(2))
->method('getMailchimpHelper')
->willReturn($helperMock);

Expand Down Expand Up @@ -319,7 +330,7 @@ public function testProcessMergeFieldsWithoutCustomer()
$mailchimpTagsApiMock->expects($this->once())->method('_getFName')->with($data)->willReturn($fname);
$mailchimpTagsApiMock->expects($this->once())->method('_getLName')->with($data)->willReturn($lname);

$subscriberMock->expects($this->once())->method('getId')->willReturn($subscriberMock);
$subscriberMock->expects($this->once())->method('getId')->willReturn(null);
$subscriberMock->expects($this->once())
->method('setSubscriberFirstname')
->with($fname)
Expand All @@ -339,7 +350,6 @@ public function testProcessMergeFieldsWithoutCustomer()

public function testProcessMergeFieldsWithoutCustomerNoSubscriber()
{

$mapFields = $this->_mapFieldsSerialized;
$maps = $this->_mapsFields;
$data = $this->_mergeFields;
Expand Down Expand Up @@ -458,16 +468,29 @@ public function testProcessMergeFieldsInterestGroups()
->setMethods(array('getFirstName','setFirstName','getLastName','setLastName','save'))
->getMock();

$subscriberMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Api_Subscribers::class)
->disableOriginalConstructor()
->setMethods(array('getId', 'getStatus', 'setSubscriberFirstname', 'setSubscriberLastname', 'save'))
->getMock();

$interestGroupHandleMock = $this
->getMockBuilder(Ebizmarts_MailChimp_Model_Api_Subscribers_InterestGroupHandle::class)
->disableOriginalConstructor()
->setMethods(array('setGroupings', 'setListId', 'processGroupsData', 'setCustomer'))
->getMock();

$mailchimpTagsApiMock->expects($this->once())
$mailchimpTagsApiMock->expects($this->exactly(2))
->method('getMailchimpHelper')
->willReturn($helperMock);

// Get's into the Subscriber creation/get part.
$helperMock->expects($this->once())
->method('loadListSubscriber')
->with($data['list_id'], $data['email'])
->willReturn($subscriberMock);

$subscriberMock->expects($this->once())->method('getId')->willReturn(null);

$helperMock->expects($this->once())
->method('getMagentoStoreIdsByListId')
->with($data['list_id'])
Expand Down Expand Up @@ -535,7 +558,6 @@ public function testProcessMergeFieldsInterestGroups()

public function testProcessMergeFieldsSubscribe()
{

$mapFields = $this->_mapFieldsSerialized;
$maps = $this->_mapsFields;
$data = $this->_mergeFields;
Expand Down Expand Up @@ -602,10 +624,6 @@ public function testProcessMergeFieldsSubscribe()
$mailchimpTagsApiMock->expects($this->once())->method('_getLName')->with($data)->willReturn($lname);

$subscriberMock->expects($this->once())->method('getId')->willReturn(null);
$mailchimpTagsApiMock->expects($this->once())
->method('_addSubscriberData')
->with($subscriberMock, $fname, $lname, $data['email'], $data['list_id'])
->willReturn($subscriberMock);

$helperMock->expects($this->once())->method('subscribeMember')->with($subscriberMock);
$subscriberMock->expects($this->once())->method('save')->willReturn($subscriberMock);
Expand Down

0 comments on commit a4cfb1b

Please sign in to comment.