├── .gitignore
├── .travis.yml
├── CONTRIBUTING.md
├── README.md
├── composer.json
├── phpunit.xml
├── src
├── Mailchimp.php
├── Mailchimp2.php
├── MailchimpAPIException.php
├── MailchimpApiInterface.php
├── MailchimpApiUser.php
├── MailchimpAutomations.php
├── MailchimpCampaigns.php
├── MailchimpConnectedSites.php
├── MailchimpEcommerce.php
├── MailchimpLists.php
├── MailchimpReports.php
├── MailchimpTemplates.php
└── http
│ ├── MailchimpCurlHttpClient.php
│ ├── MailchimpGuzzleHttpClient.php
│ └── MailchimpHttpClientInterface.php
└── tests
├── MailchimpAutomationsTest.php
├── MailchimpCampaignsTest.php
├── MailchimpConnectedSitesTest.php
├── MailchimpEcommerceTest.php
├── MailchimpListsTest.php
├── MailchimpReportsTest.php
├── MailchimpTemplatesTest.php
├── MailchimpTest.php
└── src
├── Client.php
├── Mailchimp.php
├── MailchimpApiUser.php
├── MailchimpAutomations.php
├── MailchimpCampaigns.php
├── MailchimpConnectedSites.php
├── MailchimpEcommerce.php
├── MailchimpLists.php
├── MailchimpReports.php
├── MailchimpTemplates.php
├── MailchimpTestHttpClient.php
└── MailchimpTestHttpResponse.php
/.gitignore:
--------------------------------------------------------------------------------
1 | /composer.lock
2 | /vendor
3 | .idea
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 | before_script:
3 | - composer self-update
4 | - composer install --dev --no-interaction
5 | script:
6 | - vendor/bin/phpunit --coverage-clover clover.xml
7 | after_script:
8 | php:
9 | - 5.4
10 | - 5.5
11 | - 5.6
12 | - 7.0
13 | notifications:
14 | email: false
15 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | Thank you for taking the time to help us develop the MailChimp library!
4 |
5 | We do all our work on GitHub. If you'd like to help, you can create a
6 | [free GitHub account here](https://github.com/join).
7 |
8 | ## Reporting an issue
9 |
10 | For bug reports or feature requests, please [create a new issue](https://github.com/thinkshout/mailchimp-api-php/issues).
11 |
12 | If reporting a bug, please:
13 |
14 | * Let us know what steps we can take to reproduce the bug
15 | * Include any error messages you received
16 |
17 | ## Submitting changes
18 |
19 | The best way to submit a bug fix or improvement is through a [pull request](https://help.github.com/articles/creating-a-pull-request-from-a-fork/).
20 |
21 | * [Fork](https://guides.github.com/activities/forking/), then clone the repository:
22 |
23 | `git clone git@github.com:YOUR-GITHUB-USERNAME/mailchimp-api-php.git`
24 |
25 | * Install the library's dependencies using [Composer](https://getcomposer.org/):
26 |
27 | ```shell
28 | cd mailchimp-api-php
29 | composer install
30 | ```
31 |
32 | * If you are adding new functionality, please add a corresponding test.
33 | See [Testing](#testing) for more information.
34 |
35 | * After making your changes, ensure all tests pass.
36 |
37 | * Commit and push your changes to your fork of the repository.
38 |
39 | * [Submit a pull request](https://github.com/thinkshout/mailchimp-api-php/pulls).
40 |
41 | ## Testing
42 |
43 | This library includes a [PHPUnit](https://phpunit.de/) test suite. Keeping these
44 | tests up to date helps us ensure the library is reliable.
45 |
46 | ### Running PHPUnit tests
47 |
48 | Add Composer's vendor directory to your PATH by adding the following line to
49 | your profile. This is dependent on your system, but on a Linux or Mac OSX system
50 | using Bash, you'll typically find the file at *~/.bash_profile*.
51 |
52 | `export PATH="./vendor/bin:$PATH"`
53 |
54 | Bash example:
55 |
56 | ```shell
57 | echo 'export PATH="./vendor/bin:$PATH"' >> ~/.bash_profile
58 | source ~/.bash_profile
59 | ```
60 |
61 | Then run PHPUnit:
62 |
63 | `phpunit`
64 |
65 | ### Creating new tests
66 |
67 | Tests are located in the *tests* directory and are grouped into PHP files named
68 | after the library component they are testing. For example,
69 | *MailchimpCampaignsTest.php* contains tests for MailChimp Campaigns.
70 |
71 | New tests should contain at least the functionality in this simple test:
72 |
73 | ```php
74 | public function testGetCampaigns() {
75 | $mc = new MailchimpCampaigns();
76 | $mc->getCampaigns();
77 |
78 | $this->assertEquals('GET', $mc->getClient()->method);
79 | $this->assertEquals($mc->getEndpoint() . '/campaigns', $mc->getClient()->uri);
80 | }
81 | ```
82 |
83 | This test checks the request type and request URI are both correct.
84 |
85 | More advanced examples can be found in the *tests* directory.
86 |
87 | ## Additional resources
88 |
89 | * [MailChimp API documentation](http://developer.mailchimp.com/documentation/mailchimp/)
90 | * [MailChimp Drupal module](https://www.drupal.org/project/mailchimp), MailChimp integration for Drupal using this library.
91 | * [MailChimp E-Commerce Drupal module](https://www.drupal.org/project/mailchimp_ecommerce), MailChimp integration for Drupal Commerce using this library.
92 | * [ThinkShout](https://thinkshout.com), the library maintainer.
93 |
94 | ## Want to help build this and other open source projects?
95 |
96 | We're hiring software engineers! Check out our [careers page](https://thinkshout.com/careers/).
97 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PHP library for v3 of the Mailchimp API
2 |
3 | This library provides convenient wrapper functions for Mailchimp's REST API.
4 | The API is [documented here](http://developer.mailchimp.com/documentation/mailchimp/guides/get-started-with-mailchimp-api-3/).
5 |
6 | ## Requirements
7 |
8 | - PHP 5.4.0 or greater (7.0 or greater if you wish to use phpunit)
9 | - [Composer](https://getcomposer.org/)
10 | - [Guzzle](https://github.com/guzzle/guzzle)
11 |
12 | ## Installation
13 |
14 | Dependencies are managed by [Composer](https://getcomposer.org/). After
15 | installing Composer, run the following command from the library root:
16 |
17 | `composer install --no-dev --ignore-platform-reqs`
18 |
19 | Or to install with phpunit:
20 |
21 | `composer install`
22 |
23 | ## Usage
24 |
25 | ### Get your account information
26 |
27 | A basic test to confirm the library is set up and functional.
28 |
29 | ### With OAuth Access token
30 | ```php
31 | 'YOUR_ACCESS_TOKEN',
37 | 'data_center' => 'YOUR_DATA_CENTER',
38 | 'api_user' => 'oauth',
39 | ];
40 |
41 | // Use Mailchimp2 class for OAuth access_token.
42 | $api_class = new Mailchimp2($authentication_settings);
43 |
44 | // Instantiate a MailchimpApiUser or a class that extends it (ie. MailchimpLists, MailchimpSignups, etc..)
45 | $mailchimp = new MailchimpApiUser($api_class);
46 |
47 | // Get the account details of the authenticated user.
48 | $response = $mailchimp->getAccount();
49 |
50 | // Output the account details.
51 | if (!empty($response) && isset($response->account_id)) {
52 | echo "ID: {$response->account_id}\n"
53 | . "Name: {$response->account_name}\n";
54 | }
55 |
56 | ```
57 |
58 | ### With API Key
59 | ```php
60 | require 'PATH_TO_LIBRARY/mailchimp-api-php/vendor/autoload.php';
61 |
62 | // Instantiate MailchimpApiInterface
63 | $authentication_settings = [
64 | 'api_key' => 'YOUR_API_KEY',
65 | 'api_user' => 'api_key',
66 | ];
67 |
68 | // Use Mailchimp class for api_key.
69 | $api_class = new Mailchimp($authentication_settings);
70 |
71 | // Instantiate a MailchimpApiUser or a class that extends it (ie. MailchimpLists, MailchimpSignups, etc..)
72 | $mailchimp = new MailchimpApiUser($api_class);
73 |
74 | // Get the account details of the authenticated user.
75 | $response = $mailchimp->getAccount();
76 |
77 | // Output the account details.
78 | if (!empty($response) && isset($response->account_id)) {
79 | echo "ID: {$response->account_id}\n"
80 | . "Name: {$response->account_name}\n";
81 | }ject = new MailchimpApiUser($api_class, $http_options);
82 | ```
83 |
84 | ### Get lists and their interest categories
85 |
86 | A more complicated example that takes the response from one API call and
87 | uses that data to make another.
88 |
89 | ```php
90 | 'YOUR_ACCESS_TOKEN',
95 | 'data_center' => 'YOUR_DATA_CENTER',
96 | 'api_user' => 'oauth',
97 | ];
98 | $api_class = new Mailchimp2($authentication_settings);
99 |
100 | $mailchimp_lists = new Mailchimp\MailchimpLists($api_class);
101 |
102 | // Get all lists.
103 | $response = $mailchimp_lists->getLists();
104 |
105 | if (!empty($response) && isset($response->lists)) {
106 | foreach ($response->lists as $list) {
107 | // Output the list name.
108 | echo "List name: {$list->name}\n";
109 |
110 | // Get the list's interest categories.
111 | $interests = $mailchimp_lists->getInterestCategories($list->id);
112 |
113 | // Output the names of the list's interest categories.
114 | if (!empty($interests) && isset($interests->categories)) {
115 | foreach ($interests->categories as $category) {
116 | echo "Interest category: {$category->title}\n";
117 | }
118 | }
119 | }
120 | }
121 | ```
122 |
123 | ## Testing
124 |
125 | This library includes a [PHPUnit](https://phpunit.de/) test suite.
126 |
127 | ### Running PHPUnit tests
128 |
129 | Add Composer's vendor directory to your PATH by adding the following line to
130 | your profile. This is dependent on your system, but on a Linux or Mac OSX system
131 | using Bash, you'll typically find the file at *~/.bash_profile*.
132 |
133 | `export PATH="./vendor/bin:$PATH"`
134 |
135 | Bash example:
136 |
137 | ```shell
138 | echo 'export PATH="./vendor/bin:$PATH"' >> ~/.bash_profile
139 | source ~/.bash_profile
140 | ```
141 |
142 | Then run PHPUnit:
143 |
144 | `phpunit`
145 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "thinkshout/mailchimp-api-php",
3 | "type": "library",
4 | "description": "PHP library for v3 of the MailChimp API",
5 | "keywords": ["mailchimp", "mail"],
6 | "homepage": "https://github.com/thinkshout/mailchimp-api-php",
7 | "license": "GPL-2.0-or-later",
8 | "require": {
9 | "php": ">=5.4.0",
10 | "guzzlehttp/guzzle": "^6.5.8|^7.4.5"
11 | },
12 | "require-dev": {
13 | "phpunit/phpunit": "^6.2.2|^7.0|^8.0|^9.0"
14 | },
15 | "autoload": {
16 | "psr-4": {
17 | "Mailchimp\\": "src/",
18 | "Mailchimp\\http\\": "src/http/"
19 | }
20 | },
21 | "autoload-dev": {
22 | "psr-4": {
23 | "Mailchimp\\Tests\\": "tests/src/"
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
The HTML to use for the saved campaign.
', 92 | ]; 93 | 94 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 95 | $mc = new MailchimpCampaigns($api_user); 96 | $mc->setCampaignContent($campaign_id, $parameters); 97 | 98 | $this->assertEquals('PUT', $mc->getClient()->method); 99 | $this->assertEquals($mc->getEndpoint() . '/campaigns/' . $campaign_id . '/content', $mc->getClient()->uri); 100 | 101 | $this->assertNotEmpty($mc->getClient()->options['json']); 102 | 103 | $request_body = $mc->getClient()->options['json']; 104 | 105 | $this->assertEquals($parameters['html'], $request_body->html); 106 | } 107 | 108 | /** 109 | * Tests library functionality for getting a campaign send checklist. 110 | */ 111 | public function testGetSendChecklist() { 112 | $campaign_id = '42694e9e57'; 113 | 114 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 115 | $mc = new MailchimpCampaigns($api_user); 116 | $mc->getSendChecklist($campaign_id); 117 | 118 | $this->assertEquals('GET', $mc->getClient()->method); 119 | $this->assertEquals($mc->getEndpoint() . '/campaigns/' . $campaign_id . '/send-checklist', $mc->getClient()->uri); 120 | } 121 | 122 | /** 123 | * Tests library functionality for updating a campaign. 124 | */ 125 | public function testUpdateCampaign() { 126 | $campaign_id = '3e06f4ec92'; 127 | $type = 'regular'; 128 | $recipients = (object) [ 129 | 'list_id' => '3c307a9f3f', 130 | ]; 131 | $settings = (object) [ 132 | 'subject_line' => 'This is an updated subject line', 133 | 'from_name' => 'Customer Service', 134 | ]; 135 | 136 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 137 | $mc = new MailchimpCampaigns($api_user); 138 | $mc->updateCampaign($campaign_id, $type, $recipients, $settings); 139 | 140 | $this->assertEquals('PATCH', $mc->getClient()->method); 141 | $this->assertEquals($mc->getEndpoint() . '/campaigns/' . $campaign_id, $mc->getClient()->uri); 142 | 143 | $this->assertNotEmpty($mc->getClient()->options['json']); 144 | 145 | $request_body = $mc->getClient()->options['json']; 146 | 147 | $this->assertEquals($type, $request_body->type); 148 | 149 | $this->assertEquals($recipients->list_id, $request_body->recipients->list_id); 150 | $this->assertEquals($settings->subject_line, $request_body->settings->subject_line); 151 | $this->assertEquals($settings->from_name, $request_body->settings->from_name); 152 | } 153 | 154 | /** 155 | * Tests library functionality for sending a test campaign. 156 | */ 157 | public function testSendTest() { 158 | $campaign_id = 'b03bfc273a'; 159 | $emails = [ 160 | 'test@example.com', 161 | ]; 162 | $send_type = 'html'; 163 | 164 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 165 | $mc = new MailchimpCampaigns($api_user); 166 | $mc->sendTest($campaign_id, $emails, $send_type); 167 | 168 | $this->assertEquals('POST', $mc->getClient()->method); 169 | $this->assertEquals($mc->getEndpoint() . '/campaigns/' . $campaign_id . '/actions/test', $mc->getClient()->uri); 170 | } 171 | 172 | /** 173 | * Tests library functionality for scheduling a campaign. 174 | */ 175 | public function testSchedule() { 176 | $campaign_id = 'b03bfc273a'; 177 | $schedule_time = '2017-02-04T19:13:00+00:00'; 178 | $timewarp = FALSE; 179 | $batch_delivery = (object) [ 180 | 'batch_delay' => 5, 181 | 'batch_count' => 100, 182 | ]; 183 | 184 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 185 | $mc = new MailchimpCampaigns($api_user); 186 | $mc->schedule($campaign_id, $schedule_time, $timewarp, $batch_delivery); 187 | 188 | $this->assertEquals('POST', $mc->getClient()->method); 189 | $this->assertEquals($mc->getEndpoint() . '/campaigns/' . $campaign_id . '/actions/schedule', $mc->getClient()->uri); 190 | 191 | $request_body = $mc->getClient()->options['json']; 192 | 193 | $this->assertEquals($schedule_time, $request_body->schedule_time); 194 | $this->assertEquals($timewarp, $request_body->timewarp); 195 | $this->assertEquals($batch_delivery->batch_delay, $request_body->batch_delivery->batch_delay); 196 | $this->assertEquals($batch_delivery->batch_count, $request_body->batch_delivery->batch_count); 197 | } 198 | 199 | /** 200 | * Tests library functionality for unscheduling a campaign. 201 | */ 202 | public function testUnschedule() { 203 | $campaign_id = 'b03bfc273a'; 204 | 205 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 206 | $mc = new MailchimpCampaigns($api_user); 207 | $mc->unschedule($campaign_id); 208 | 209 | $this->assertEquals('POST', $mc->getClient()->method); 210 | $this->assertEquals($mc->getEndpoint() . '/campaigns/' . $campaign_id . '/actions/unschedule', $mc->getClient()->uri); 211 | } 212 | 213 | /** 214 | * Tests library functionality for sending a campaign. 215 | */ 216 | public function testSend() { 217 | $campaign_id = 'b03bfc273a'; 218 | 219 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 220 | $mc = new MailchimpCampaigns($api_user); 221 | $mc->send($campaign_id); 222 | 223 | $this->assertEquals('POST', $mc->getClient()->method); 224 | $this->assertEquals($mc->getEndpoint() . '/campaigns/' . $campaign_id . '/actions/send', $mc->getClient()->uri); 225 | } 226 | 227 | /** 228 | * Tests library functionality for campaigns information. 229 | */ 230 | public function testDelete() { 231 | $campaign_id = '42694e9e57'; 232 | 233 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 234 | $mc = new MailchimpCampaigns($api_user); 235 | $mc->delete($campaign_id); 236 | 237 | $this->assertEquals('DELETE', $mc->getClient()->method); 238 | $this->assertEquals($mc->getEndpoint() . '/campaigns/' . $campaign_id, $mc->getClient()->uri); 239 | } 240 | 241 | } 242 | -------------------------------------------------------------------------------- /tests/MailchimpConnectedSitesTest.php: -------------------------------------------------------------------------------- 1 | null, 'api_key' => null]); 19 | $mc = new MailchimpEcommerce($api_user); 20 | $mc->getStores(); 21 | 22 | $this->assertEquals('GET', $mc->getClient()->method); 23 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores', $mc->getClient()->uri); 24 | } 25 | 26 | /** 27 | * Tests library functionality for store information. 28 | */ 29 | public function testGetStore() { 30 | $store_id = 'MC002'; 31 | 32 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 33 | $mc = new MailchimpEcommerce($api_user); 34 | $mc->getStore($store_id); 35 | 36 | $this->assertEquals('GET', $mc->getClient()->method); 37 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id, $mc->getClient()->uri); 38 | } 39 | 40 | /** 41 | * Tests library function for adding a new store. 42 | */ 43 | public function testAddStore() { 44 | $id = 'MC001'; 45 | $store = [ 46 | 'list_id' => '205d96e6b4', 47 | 'name' => "Freddie's Merchandise", 48 | 'currency_code' => 'USD', 49 | ]; 50 | 51 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 52 | $mc = new MailchimpEcommerce($api_user); 53 | $mc->addStore($id, $store); 54 | 55 | $this->assertEquals('POST', $mc->getClient()->method); 56 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores', $mc->getClient()->uri); 57 | 58 | $this->assertNotEmpty($mc->getClient()->options['json']); 59 | 60 | $request_body = $mc->getClient()->options['json']; 61 | 62 | $this->assertEquals($id, $request_body->id); 63 | $this->assertEquals($store['list_id'], $request_body->list_id); 64 | $this->assertEquals($store['name'], $request_body->name); 65 | $this->assertEquals($store['currency_code'], $request_body->currency_code); 66 | } 67 | 68 | /** 69 | * Tests library functionality for updating a store. 70 | */ 71 | public function testUpdateStore() { 72 | $store_id = 'MC001'; 73 | $name = "Freddie's Merchandise"; 74 | $currency_code = 'USD'; 75 | 76 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 77 | $mc = new MailchimpEcommerce($api_user); 78 | $mc->updateStore($store_id, $name, $currency_code); 79 | 80 | $this->assertEquals('PATCH', $mc->getClient()->method); 81 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id, $mc->getClient()->uri); 82 | 83 | $this->assertNotEmpty($mc->getClient()->options['json']); 84 | 85 | $request_body = $mc->getClient()->options['json']; 86 | 87 | $this->assertEquals($name, $request_body->name); 88 | $this->assertEquals($currency_code, $request_body->currency_code); 89 | } 90 | 91 | /** 92 | * Tests library functionality for deleting stores. 93 | */ 94 | public function testDeleteStore() { 95 | $store_id = 'MC002'; 96 | 97 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 98 | $mc = new MailchimpEcommerce($api_user); 99 | $mc->deleteStore($store_id); 100 | 101 | $this->assertEquals('DELETE', $mc->getClient()->method); 102 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id, $mc->getClient()->uri); 103 | } 104 | 105 | /** 106 | * Tests library functionality for getting information on a store's carts. 107 | */ 108 | public function testGetCarts() { 109 | $store_id = 'MC001'; 110 | 111 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 112 | $mc = new MailchimpEcommerce($api_user); 113 | $mc->getCarts($store_id); 114 | 115 | $this->assertEquals('GET', $mc->getClient()->method); 116 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/carts', $mc->getClient()->uri); 117 | } 118 | 119 | /** 120 | * Tests library functionality for getting information on a specific cart. 121 | */ 122 | public function testGetCart() { 123 | $store_id = 'MC001'; 124 | $cart_id = 'cart0001'; 125 | 126 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 127 | $mc = new MailchimpEcommerce($api_user); 128 | $mc->getCart($store_id, $cart_id); 129 | 130 | $this->assertEquals('GET', $mc->getClient()->method); 131 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/carts/' . $cart_id, $mc->getClient()->uri); 132 | } 133 | 134 | /** 135 | * Tests library function for adding a new cart. 136 | */ 137 | public function testAddCart() { 138 | $store_id = 'MC001'; 139 | $id = 'cart0001'; 140 | $customer = [ 141 | 'id' => 'cust0005', 142 | 'email_address' => 'freddy@freddiesjokes.com', 143 | 'opt_in_status' => TRUE, 144 | ]; 145 | $cart = [ 146 | 'currency_code' => 'USD', 147 | 'order_total' => 12.45, 148 | 'lines' => [ 149 | 'id' => 'LINE001', 150 | 'product_id' => 'PROD001', 151 | 'product_title' => "Freddie's Jokes", 152 | 'product_variant_id' => 'PROD001A', 153 | 'product_variant_title' => "Freddie's Jokes Volume 1", 154 | 'quantity' => 2, 155 | 'price' => 10, 156 | ], 157 | ]; 158 | 159 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 160 | $mc = new MailchimpEcommerce($api_user); 161 | $mc->addCart($store_id, $id, $customer, $cart); 162 | 163 | $this->assertEquals('POST', $mc->getClient()->method); 164 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/carts', $mc->getClient()->uri); 165 | 166 | $this->assertNotEmpty($mc->getClient()->options['json']); 167 | 168 | $request_body = $mc->getClient()->options['json']; 169 | 170 | $this->assertEquals($id, $request_body->id); 171 | $this->assertEquals($customer['id'], $request_body->customer->id); 172 | $this->assertEquals($customer['email_address'], $request_body->customer->email_address); 173 | $this->assertEquals($customer['opt_in_status'], $request_body->customer->opt_in_status); 174 | $this->assertEquals($cart['currency_code'], $request_body->currency_code); 175 | $this->assertEquals($cart['order_total'], $request_body->order_total); 176 | $this->assertEquals($cart['lines'], $request_body->lines); 177 | $this->assertEquals($cart['lines']['id'], $request_body->lines['id']); 178 | $this->assertEquals($cart['lines']['product_id'], $request_body->lines['product_id']); 179 | $this->assertEquals($cart['lines']['product_title'], $request_body->lines['product_title']); 180 | $this->assertEquals($cart['lines']['product_variant_id'], $request_body->lines['product_variant_id']); 181 | $this->assertEquals($cart['lines']['product_variant_title'], $request_body->lines['product_variant_title']); 182 | $this->assertEquals($cart['lines']['quantity'], $request_body->lines['quantity']); 183 | $this->assertEquals($cart['lines']['price'], $request_body->lines['price']); 184 | } 185 | 186 | /** 187 | * Tests library function for updating an existing cart. 188 | */ 189 | public function testUpdateCart() { 190 | $store_id = 'MC001'; 191 | $cart_id = 'cart0001'; 192 | 193 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 194 | $mc = new MailchimpEcommerce($api_user); 195 | $mc->updateCart($store_id, $cart_id); 196 | 197 | $this->assertEquals('PATCH', $mc->getClient()->method); 198 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/carts/' . $cart_id, $mc->getClient()->uri); 199 | } 200 | 201 | /** 202 | * Tests library function for deleting a cart. 203 | */ 204 | public function testDeleteCart() { 205 | $store_id = 'MC001'; 206 | $cart_id = 'cart0001'; 207 | 208 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 209 | $mc = new MailchimpEcommerce($api_user); 210 | $mc->deleteCart($store_id, $cart_id); 211 | 212 | $this->assertEquals('DELETE', $mc->getClient()->method); 213 | $this->assertEquals($mc->getEndPoint() . '/ecommerce/stores/' . $store_id . '/carts/' . $cart_id, $mc->getClient()->uri); 214 | } 215 | 216 | /** 217 | * Tests library function for getting cart lines. 218 | */ 219 | public function testGetCartLines() { 220 | $store_id = 'MC001'; 221 | $cart_id = 'cart0001'; 222 | 223 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 224 | $mc = new MailchimpEcommerce($api_user); 225 | $mc->getCartLines($store_id, $cart_id); 226 | 227 | $this->assertEquals('GET', $mc->getClient()->method); 228 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/carts/' . $cart_id . '/lines', $mc->getClient()->uri); 229 | } 230 | 231 | /** 232 | * Tests library function for getting a specific cart's line item. 233 | */ 234 | public function testGetCartLine() { 235 | $store_id = 'MC001'; 236 | $cart_id = 'cart0001'; 237 | $line_id = 'line002'; 238 | 239 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 240 | $mc = new MailchimpEcommerce($api_user); 241 | $mc->getCartLine($store_id, $cart_id, $line_id); 242 | 243 | $this->assertEquals('GET', $mc->getClient()->method); 244 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/carts/' . $cart_id . '/lines/' . $line_id, $mc->getClient()->uri); 245 | } 246 | 247 | /** 248 | * Tests library function for adding a line item to a cart. 249 | */ 250 | public function testAddCartLine() { 251 | $store_id = 'MC001'; 252 | $cart_id = 'cart0001'; 253 | $id = 'L001'; 254 | $product = [ 255 | 'product_id' => 'PROD001', 256 | 'product_variant_id' => "Freddie's Jokes", 257 | 'quantity' => 1, 258 | 'price' => 5, 259 | ]; 260 | 261 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 262 | $mc = new MailchimpEcommerce($api_user); 263 | $mc->addCartLine($store_id, $cart_id, $id, $product); 264 | 265 | $this->assertEquals('POST', $mc->getClient()->method); 266 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/carts/' . $cart_id . '/lines', $mc->getClient()->uri); 267 | 268 | $this->assertNotEmpty($mc->getClient()->options['json']); 269 | 270 | $request_body = $mc->getClient()->options['json']; 271 | 272 | $this->assertEquals($id, $request_body->id); 273 | $this->assertEquals($product['product_id'], $request_body->product_id); 274 | $this->assertEquals($product['product_variant_id'], $request_body->product_variant_id); 275 | $this->assertEquals($product['quantity'], $request_body->quantity); 276 | $this->assertEquals($product['price'], $request_body->price); 277 | } 278 | 279 | /** 280 | * Tests library function for updating a cart line item. 281 | */ 282 | public function testUpdateCartLine() { 283 | $store_id = 'MC001'; 284 | $cart_id = 'cart0001'; 285 | $line_id = 'L001'; 286 | 287 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 288 | $mc = new MailchimpEcommerce($api_user); 289 | $mc->updateCartLine($store_id, $cart_id, $line_id); 290 | 291 | $this->assertEquals('PATCH', $mc->getClient()->method); 292 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/carts/' . $cart_id . '/lines/' . $line_id, $mc->getClient()->uri); 293 | } 294 | 295 | /** 296 | * Tests library function for deleting a cart line item. 297 | */ 298 | public function testDeleteCartLine() { 299 | $store_id = 'MC001'; 300 | $cart_id = 'cart0001'; 301 | $line_id = 'L001'; 302 | 303 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 304 | $mc = new MailchimpEcommerce($api_user); 305 | $mc->deleteCartLine($store_id, $cart_id, $line_id); 306 | 307 | $this->assertEquals('DELETE', $mc->getClient()->method); 308 | $this->assertEquals($mc->getEndPoint() . '/ecommerce/stores/' . $store_id . '/carts/' . $cart_id . '/lines/' . $line_id, $mc->getClient()->uri); 309 | } 310 | 311 | /** 312 | * Tests library function for getting customers. 313 | */ 314 | public function testGetCustomers() { 315 | $store_id = 'MC001'; 316 | 317 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 318 | $mc = new MailchimpEcommerce($api_user); 319 | $mc->getCustomers($store_id); 320 | 321 | $this->assertEquals('GET', $mc->getClient()->method); 322 | $this->assertEquals($mc->getEndPoint() . '/ecommerce/stores/' . $store_id . '/customers', $mc->getClient()->uri); 323 | } 324 | 325 | /** 326 | * Tests library function for getting a customer. 327 | */ 328 | public function testGetCustomer() { 329 | $store_id = 'MC001'; 330 | $customer_id = 'cust0001'; 331 | 332 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 333 | $mc = new MailchimpEcommerce($api_user); 334 | $mc->getCustomer($store_id, $customer_id); 335 | 336 | $this->assertEquals('GET', $mc->getClient()->method); 337 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/customers/' . $customer_id, $mc->getClient()->uri); 338 | } 339 | 340 | /** 341 | * Tests library function for adding a customer. 342 | */ 343 | public function testAddCustomer() { 344 | $store_id = 'MC001'; 345 | $customer = [ 346 | 'id' => 'cust0001', 347 | 'email_address' => 'freddie@freddiesjokes.com', 348 | 'opt_in_status' => TRUE, 349 | ]; 350 | 351 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 352 | $mc = new MailchimpEcommerce($api_user); 353 | $mc->addCustomer($store_id, $customer); 354 | 355 | $this->assertEquals('POST', $mc->getClient()->method); 356 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/customers', $mc->getClient()->uri); 357 | 358 | $this->assertNotEmpty($mc->getClient()->options['json']); 359 | 360 | $request_body = $mc->getClient()->options['json']; 361 | 362 | $this->assertEquals($customer['id'], $request_body->id); 363 | $this->assertEquals($customer['email_address'], $request_body->email_address); 364 | $this->assertEquals($customer['opt_in_status'], $request_body->opt_in_status); 365 | } 366 | 367 | /** 368 | * Tests library function for updating a customer. 369 | */ 370 | public function testUpdateCustomer() { 371 | $store_id = 'MC001'; 372 | $customer = [ 373 | 'id' => 'cust0001', 374 | 'email_address' => 'freddie@freddiesjokes.com', 375 | 'opt_in_status' => TRUE, 376 | ]; 377 | 378 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 379 | $mc = new MailchimpEcommerce($api_user); 380 | $mc->updateCustomer($store_id, $customer); 381 | 382 | $this->assertEquals('PATCH', $mc->getClient()->method); 383 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/customers/' . $customer['id'], $mc->getClient()->uri); 384 | 385 | $this->assertNotEmpty($mc->getClient()->options['json']); 386 | 387 | $request_body = $mc->getClient()->options['json']; 388 | 389 | $this->assertEquals($customer['id'], $request_body->id); 390 | $this->assertEquals($customer['email_address'], $request_body->email_address); 391 | $this->assertEquals($customer['opt_in_status'], $request_body->opt_in_status); 392 | } 393 | 394 | /** 395 | * Tests library function for deleting a customer. 396 | */ 397 | public function testDeleteCustomer() { 398 | $store_id = 'MC001'; 399 | $customer_id = 'cust0003'; 400 | 401 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 402 | $mc = new MailchimpEcommerce($api_user); 403 | $mc->deleteCustomer($store_id, $customer_id); 404 | 405 | $this->assertEquals('DELETE', $mc->getClient()->method); 406 | $this->assertEquals($mc->getEndPoint() . '/ecommerce/stores/' . $store_id . '/customers/' . $customer_id, $mc->getClient()->uri); 407 | } 408 | 409 | /** 410 | * Tests library function for getting orders. 411 | */ 412 | public function testGetOrders() { 413 | $store_id = 'MC001'; 414 | 415 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 416 | $mc = new MailchimpEcommerce($api_user); 417 | $mc->getOrders($store_id); 418 | 419 | $this->assertEquals('GET', $mc->getClient()->method); 420 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/orders', $mc->getClient()->uri); 421 | } 422 | 423 | /** 424 | * Tests library function for getting an order. 425 | */ 426 | public function testGetOrder() { 427 | $store_id = 'MC001'; 428 | $order_id = 'ord0001'; 429 | 430 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 431 | $mc = new MailchimpEcommerce($api_user); 432 | $mc->getOrder($store_id, $order_id); 433 | 434 | $this->assertEquals('GET', $mc->getClient()->method); 435 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/orders/' . $order_id, $mc->getClient()->uri); 436 | } 437 | 438 | /** 439 | * Tests library function for adding an order. 440 | */ 441 | public function testAddOrder() { 442 | $store_id = 'MC001'; 443 | $order_id = 'ord0001'; 444 | $customer = [ 445 | 'id' => 'cust0005', 446 | 'email_address' => 'freddy@freddiesjokes.com', 447 | 'opt_in_status' => TRUE, 448 | ]; 449 | $order = [ 450 | 'currency_code' => 'USD', 451 | 'order_total' => 12.45, 452 | 'lines' => [ 453 | 'id' => 'LINE001', 454 | 'product_id' => 'PROD001', 455 | 'product_title' => "Freddie's Jokes", 456 | 'product_variant_id' => 'PROD001A', 457 | 'product_variant_title' => "Freddie's Jokes Volume 1", 458 | 'quantity' => 2, 459 | 'price' => 10, 460 | ], 461 | ]; 462 | 463 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 464 | $mc = new MailchimpEcommerce($api_user); 465 | $mc->addOrder($store_id, $order_id, $customer, $order); 466 | 467 | $this->assertEquals('POST', $mc->getClient()->method); 468 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/orders', $mc->getClient()->uri); 469 | 470 | $this->assertNotEmpty($mc->getClient()->options['json']); 471 | 472 | $request_body = $mc->getClient()->options['json']; 473 | 474 | $this->assertEquals($order_id, $request_body->id); 475 | $this->assertEquals($customer['id'], $request_body->customer->id); 476 | $this->assertEquals($customer['email_address'], $request_body->customer->email_address); 477 | $this->assertEquals($customer['opt_in_status'], $request_body->customer->opt_in_status); 478 | $this->assertEquals($order['currency_code'], $request_body->currency_code); 479 | $this->assertEquals($order['order_total'], $request_body->order_total); 480 | $this->assertEquals($order['lines'], $request_body->lines); 481 | $this->assertEquals($order['lines']['id'], $request_body->lines['id']); 482 | $this->assertEquals($order['lines']['product_id'], $request_body->lines['product_id']); 483 | $this->assertEquals($order['lines']['product_title'], $request_body->lines['product_title']); 484 | $this->assertEquals($order['lines']['product_variant_id'], $request_body->lines['product_variant_id']); 485 | $this->assertEquals($order['lines']['product_variant_title'], $request_body->lines['product_variant_title']); 486 | $this->assertEquals($order['lines']['quantity'], $request_body->lines['quantity']); 487 | $this->assertEquals($order['lines']['price'], $request_body->lines['price']); 488 | } 489 | 490 | /** 491 | * Tests library function for updating an order. 492 | */ 493 | public function testUpdateOrder() { 494 | $store_id = 'MC001'; 495 | $order_id = 'ord0001'; 496 | 497 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 498 | $mc = new MailchimpEcommerce($api_user); 499 | $mc->updateOrder($store_id, $order_id); 500 | 501 | $this->assertEquals('PATCH', $mc->getClient()->method); 502 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/orders/' . $order_id, $mc->getClient()->uri); 503 | } 504 | 505 | /** 506 | * Tests library functionality for deleting an order. 507 | */ 508 | public function testDeleteOrder() { 509 | $store_id = 'MC002'; 510 | $order_id = 'ord0001'; 511 | 512 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 513 | $mc = new MailchimpEcommerce($api_user); 514 | $mc->deleteOrder($store_id, $order_id); 515 | 516 | $this->assertEquals('DELETE', $mc->getClient()->method); 517 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/orders/' . $order_id, $mc->getClient()->uri); 518 | } 519 | 520 | /** 521 | * Tests library function for getting order lines. 522 | */ 523 | public function testGetOrderLines() { 524 | $store_id = 'MC001'; 525 | $order_id = 'ord0001'; 526 | 527 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 528 | $mc = new MailchimpEcommerce($api_user); 529 | $mc->getOrderLines($store_id, $order_id); 530 | 531 | $this->assertEquals('GET', $mc->getClient()->method); 532 | $this->assertEquals($mc->getEndPoint() . '/ecommerce/stores/' . $store_id . '/orders/' . $order_id . '/lines', $mc->getClient()->uri); 533 | } 534 | 535 | /** 536 | * Tests library function for getting order lines. 537 | */ 538 | public function testGetOrderLine() { 539 | $store_id = 'MC001'; 540 | $order_id = 'ord0001'; 541 | $line_id = 'L001'; 542 | 543 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 544 | $mc = new MailchimpEcommerce($api_user); 545 | $mc->getOrderLine($store_id, $order_id, $line_id); 546 | 547 | $this->assertEquals('GET', $mc->getClient()->method); 548 | $this->assertEquals($mc->getEndPoint() . '/ecommerce/stores/' . $store_id . '/orders/' . $order_id . '/lines/' . $line_id, $mc->getClient()->uri); 549 | } 550 | 551 | /** 552 | * Tests library function for adding an order line. 553 | */ 554 | public function testAddOrderLine() { 555 | $store_id = 'MC001'; 556 | $order_id = 'ord0001'; 557 | $id = 'L002'; 558 | $product = [ 559 | 'product_id' => 'PROD001', 560 | 'product_variant_id' => "Freddie's Jokes", 561 | 'quantity' => 1, 562 | 'price' => 5, 563 | ]; 564 | 565 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 566 | $mc = new MailchimpEcommerce($api_user); 567 | $mc->addOrderLine($store_id, $order_id, $id, $product); 568 | 569 | $this->assertEquals('POST', $mc->getClient()->method); 570 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/orders/' . $order_id . '/lines', $mc->getClient()->uri); 571 | 572 | $this->assertNotEmpty($mc->getClient()->options['json']); 573 | 574 | $request_body = $mc->getClient()->options['json']; 575 | 576 | $this->assertEquals($id, $request_body->id); 577 | $this->assertEquals($product['product_id'], $request_body->product_id); 578 | $this->assertEquals($product['product_variant_id'], $request_body->product_variant_id); 579 | $this->assertEquals($product['quantity'], $request_body->quantity); 580 | $this->assertEquals($product['price'], $request_body->price); 581 | } 582 | 583 | /** 584 | * Test getting all products. 585 | */ 586 | public function testsGetProducts() { 587 | $store_id = 'MC001'; 588 | 589 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 590 | $mc = new MailchimpEcommerce($api_user); 591 | $mc->getProducts($store_id); 592 | // Method must be GET. 593 | $this->assertEquals('GET', $mc->getClient()->method); 594 | // Confirm the URI being used. 595 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products', $mc->getClient()->uri); 596 | } 597 | 598 | /** 599 | * Test getting information on a single product. 600 | */ 601 | public function testGetProduct() { 602 | $store_id = 'MC001'; 603 | $product_id = 'sku0001'; 604 | 605 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 606 | $mc = new MailchimpEcommerce($api_user); 607 | $mc->getProduct($store_id, $product_id); 608 | // Method must be GET. 609 | $this->assertEquals('GET', $mc->getClient()->method); 610 | // Confirm the URI being used. 611 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products/' . $product_id, $mc->getClient()->uri); 612 | } 613 | 614 | /** 615 | * Test adding a product. 616 | */ 617 | public function testAddProduct() { 618 | $store_id = 'MC001'; 619 | $id = 'sku0001'; 620 | $title = 'Test Product 001'; 621 | $url = 'http://example.org/'; 622 | $variant_1 = (object) [ 623 | 'id' => 'PROD001A', 624 | 'title' => "Freddie's Jokes Volume 1", 625 | ]; 626 | $variants = [ 627 | $variant_1, 628 | ]; 629 | 630 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 631 | $mc = new MailchimpEcommerce($api_user); 632 | 633 | $mc->addProduct($store_id, $id, $title, $url, $variants); 634 | $this->assertEquals('POST', $mc->getClient()->method); 635 | 636 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products', $mc->getClient()->uri); 637 | $this->assertNotEmpty($mc->getClient()->options['json']); 638 | 639 | $request_body = $mc->getClient()->options['json']; 640 | 641 | $this->assertEquals($id, $request_body->id); 642 | $this->assertEquals($title, $request_body->title); 643 | $this->assertEquals($variant_1->id, $request_body->variants[0]->id); 644 | $this->assertEquals($variant_1->title, $request_body->variants[0]->title); 645 | } 646 | 647 | /** 648 | * Test updating a product. 649 | */ 650 | public function testUpdateProduct() { 651 | $store_id = 'MC001'; 652 | $id = 'sku0001'; 653 | $variant_1 = (object) [ 654 | 'id' => 'PROD001A', 655 | 'title' => "Freddie's Jokes Volume 1", 656 | ]; 657 | $variant_2 = (object) [ 658 | 'id' => 'PROD002A', 659 | 'title' => "Freddie's Jokes Volume 2", 660 | ]; 661 | $variants = [ 662 | $variant_1, 663 | $variant_2, 664 | ]; 665 | 666 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 667 | $mc = new MailchimpEcommerce($api_user); 668 | 669 | $mc->updateProduct($store_id, $id, $variants); 670 | $this->assertEquals('PATCH', $mc->getClient()->method); 671 | 672 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products/' . $id, $mc->getClient()->uri); 673 | $this->assertNotEmpty($mc->getClient()->options['json']); 674 | 675 | $request_body = $mc->getClient()->options['json']; 676 | 677 | $this->assertEquals($variant_1->id, $request_body->variants[0]->id); 678 | $this->assertEquals($variant_1->title, $request_body->variants[0]->title); 679 | $this->assertEquals($variant_2->id, $request_body->variants[1]->id); 680 | $this->assertEquals($variant_2->title, $request_body->variants[1]->title); 681 | } 682 | 683 | /** 684 | * Test deleting a product. 685 | */ 686 | public function testDeleteProduct() { 687 | $store_id = 'MC001'; 688 | $product_id = 'sku0001'; 689 | 690 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 691 | $mc = new MailchimpEcommerce($api_user); 692 | $mc->deleteProduct($store_id, $product_id); 693 | // Method must be DELETE. 694 | $this->assertEquals('DELETE', $mc->getClient()->method); 695 | // Confirm URI being used. 696 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products/' . $product_id, $mc->getClient()->uri); 697 | } 698 | 699 | /** 700 | * Test adding a product variant. 701 | */ 702 | public function testAddProductVariant() { 703 | $store_id = 'MC001'; 704 | $product_id = 'sku0001'; 705 | $params = [ 706 | 'id' => 'var001', 707 | 'title' => 'Var Title', 708 | ]; 709 | 710 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 711 | $mc = new MailchimpEcommerce($api_user); 712 | $mc->addProductVariant($store_id, $product_id, $params); 713 | $this->assertEquals('POST', $mc->getClient()->method); 714 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products/' . $product_id . '/variants', $mc->getClient()->uri); 715 | $this->assertNotEmpty($mc->getClient()->options['json']); 716 | $request_body = $mc->getClient()->options['json']; 717 | $this->assertEquals($params['id'], $request_body->id); 718 | $this->assertEquals($params['title'], $request_body->title); 719 | } 720 | 721 | /** 722 | * Test deleting a variant. 723 | */ 724 | public function testDeleteVariant() { 725 | $store_id = 'MC001'; 726 | $product_id = 'sku0001'; 727 | $variant_id = 'var001'; 728 | 729 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 730 | $mc = new MailchimpEcommerce($api_user); 731 | $mc->deleteProductVariant($store_id, $product_id, $variant_id); 732 | // Confirm we are using DELETE in the client method. 733 | $this->assertEquals('DELETE', $mc->getClient()->method); 734 | // Confirm URI being used. 735 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products/' . $product_id . '/variants/' . $variant_id, $mc->getClient()->uri); 736 | } 737 | 738 | /** 739 | * Test getting a single variant of a single product. 740 | */ 741 | public function testGetVariant() { 742 | $store_id = 'MC001'; 743 | $product_id = 'sku0001'; 744 | $variant_id = 'var001'; 745 | 746 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 747 | $mc = new MailchimpEcommerce($api_user); 748 | $mc->getProductVariant($store_id, $product_id, $variant_id); 749 | // Check method. 750 | $this->assertEquals('GET', $mc->getClient()->method); 751 | // Check URI being used. 752 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products/' . $product_id . '/variants/' . $variant_id, $mc->getClient()->uri); 753 | } 754 | 755 | /** 756 | * Test getting all variants for a single product. 757 | */ 758 | public function testGetVariants() { 759 | $store_id = 'MC001'; 760 | $product_id = 'sku0001'; 761 | 762 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 763 | $mc = new MailchimpEcommerce($api_user); 764 | $mc->getProductVariants($store_id, $product_id); 765 | // Check method. 766 | $this->assertEquals('GET', $mc->getClient()->method); 767 | // Check URI being used. 768 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products/' . $product_id . '/variants', $mc->getClient()->uri); 769 | 770 | } 771 | 772 | /** 773 | * Test updating a variant. 774 | */ 775 | public function testUpdateVariant() { 776 | $store_id = 'MC001'; 777 | $product_id = 'sku0001'; 778 | $variant_id = 'var001'; 779 | $params = [ 780 | 'title' => 'New Title', 781 | 'url' => 'http://www.example.com', 782 | 'sku' => 'abc0042', 783 | ]; 784 | 785 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 786 | $mc = new MailchimpEcommerce($api_user); 787 | $mc->updateProductVariant($store_id, $product_id, $variant_id, $params); 788 | // Check method. 789 | $this->assertEquals('PATCH', $mc->getClient()->method); 790 | // Check URI being used. 791 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/products/' . $product_id . '/variants/' . $variant_id, $mc->getClient()->uri); 792 | // Test the contents of the body of the request for the params. 793 | $this->assertNotEmpty($mc->getClient()->options['json']); 794 | $request_body = $mc->getClient()->options['json']; 795 | $this->assertEquals($params['url'], $request_body->url); 796 | $this->assertEquals($params['title'], $request_body->title); 797 | $this->assertEquals($params['sku'], $request_body->sku); 798 | } 799 | 800 | 801 | /** 802 | * Tests creating a promo rule 803 | */ 804 | public function testAddPromoRule() { 805 | $store_id = 'MC001'; 806 | $params = [ 807 | 'id' => 'promo0001', 808 | 'description' => 'Test promotion rule', 809 | 'amount' => '10.00', 810 | 'type' => 'fixed', 811 | 'target' => 'total', 812 | ]; 813 | 814 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 815 | $mc = new MailchimpEcommerce($api_user); 816 | $mc->addPromoRule($store_id, $params); 817 | // Check method. 818 | $this->assertEquals('POST', $mc->getClient()->method); 819 | // Check URI being used. 820 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/promo-rules', $mc->getClient()->uri); 821 | // Test the contents of the body of the request for the params. 822 | $this->assertNotEmpty($mc->getClient()->options['json']); 823 | $request_body = $mc->getClient()->options['json']; 824 | $this->assertEquals($params['id'], $request_body->id); 825 | $this->assertEquals($params['description'], $request_body->description); 826 | $this->assertEquals($params['amount'], $request_body->amount); 827 | $this->assertEquals($params['type'], $request_body->type); 828 | $this->assertEquals($params['target'], $request_body->target); 829 | } 830 | 831 | /** 832 | * Tests updating a promo rule 833 | */ 834 | public function testUpdatePromoRule() { 835 | $store_id = 'MC001'; 836 | $params = [ 837 | 'id' => 'promo0001', 838 | 'description' => 'New description', 839 | 'amount' => '11', 840 | 'type' => 'percentage', 841 | 'target' => 'per_item', 842 | ]; 843 | 844 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 845 | $mc = new MailchimpEcommerce($api_user); 846 | $mc->updatePromoRule($store_id, $params); 847 | // Check method. 848 | $this->assertEquals('PATCH', $mc->getClient()->method); 849 | // Check URI being used. 850 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/promo-rules/' . $params['id'], $mc->getClient()->uri); 851 | // Test the contents of the body of the request for the params. 852 | $this->assertNotEmpty($mc->getClient()->options['json']); 853 | $request_body = $mc->getClient()->options['json']; 854 | $this->assertEquals($params['id'], $request_body->id); 855 | $this->assertEquals($params['description'], $request_body->description); 856 | $this->assertEquals($params['amount'], $request_body->amount); 857 | $this->assertEquals($params['type'], $request_body->type); 858 | $this->assertEquals($params['target'], $request_body->target); 859 | } 860 | 861 | /** 862 | * Tests getting promo rules 863 | */ 864 | public function testGetPromoRules() { 865 | $store_id = 'MC001'; 866 | 867 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 868 | $mc = new MailchimpEcommerce($api_user); 869 | $mc->getPromoRules($store_id); 870 | // Check method. 871 | $this->assertEquals('GET', $mc->getClient()->method); 872 | // Check URI being used. 873 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/promo-rules', $mc->getClient()->uri); 874 | } 875 | 876 | /** 877 | * Tests getting a promo rule 878 | */ 879 | public function testGetPromoRule() { 880 | $store_id = 'MC001'; 881 | $promo_rule_id = 'promo0001'; 882 | 883 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 884 | $mc = new MailchimpEcommerce($api_user); 885 | $mc->getPromoRule($store_id, $promo_rule_id); 886 | // Check method. 887 | $this->assertEquals('GET', $mc->getClient()->method); 888 | // Check URI being used. 889 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/promo-rules/' . $promo_rule_id, $mc->getClient()->uri); 890 | } 891 | 892 | /** 893 | * Tests deleting a promo rule 894 | */ 895 | public function testDeletePromoRule() { 896 | $store_id = 'MC001'; 897 | $promo_rule_id = 'promo0001'; 898 | 899 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 900 | $mc = new MailchimpEcommerce($api_user); 901 | $mc->deletePromoRule($store_id, $promo_rule_id); 902 | // Method must be DELETE. 903 | $this->assertEquals('DELETE', $mc->getClient()->method); 904 | // Confirm URI being used. 905 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/promo-rules/' . $promo_rule_id, $mc->getClient()->uri); 906 | } 907 | 908 | /** 909 | * Tests creating a promo code 910 | */ 911 | public function testAddPromoCode() { 912 | $store_id = 'MC001'; 913 | $promo_rule_id = 'promo0001'; 914 | $promo_code_id = 'code001'; 915 | $params = [ 916 | 'id' => 'code001', 917 | 'code' => 'abc0042', 918 | 'redemption_url' => 'http://www.example.com', 919 | ]; 920 | 921 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 922 | $mc = new MailchimpEcommerce($api_user); 923 | $mc->addPromoCode($store_id, $promo_rule_id, $params); 924 | // Check method. 925 | $this->assertEquals('POST', $mc->getClient()->method); 926 | // Check URI being used. 927 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/promo-rules/' . $promo_rule_id . '/promo-codes', $mc->getClient()->uri); 928 | // Test the contents of the body of the request for the params. 929 | $this->assertNotEmpty($mc->getClient()->options['json']); 930 | $request_body = $mc->getClient()->options['json']; 931 | $this->assertEquals($params['id'], $request_body->id); 932 | $this->assertEquals($params['code'], $request_body->code); 933 | $this->assertEquals($params['redemption_url'], $request_body->redemption_url); } 934 | 935 | /** 936 | * Tests updating a promo code 937 | */ 938 | public function testUpdatePromoCode() { 939 | $store_id = 'MC001'; 940 | $promo_rule_id = 'promo0001'; 941 | $params = [ 942 | 'id' => 'code001', 943 | 'code' => 'abc0042', 944 | 'redemption_url' => 'http://www.example.com', 945 | ]; 946 | 947 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 948 | $mc = new MailchimpEcommerce($api_user); 949 | $mc->updatePromoCode($store_id, $promo_rule_id, $params); 950 | // Check method. 951 | $this->assertEquals('PATCH', $mc->getClient()->method); 952 | // Check URI being used. 953 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/promo-rules/' . $promo_rule_id . '/promo-codes/' . $params['id'], $mc->getClient()->uri); 954 | // Test the contents of the body of the request for the params. 955 | $this->assertNotEmpty($mc->getClient()->options['json']); 956 | $request_body = $mc->getClient()->options['json']; 957 | $this->assertEquals($params['id'], $request_body->id); 958 | $this->assertEquals($params['code'], $request_body->code); 959 | $this->assertEquals($params['redemption_url'], $request_body->redemption_url); 960 | } 961 | 962 | /** 963 | * Tests getting promo codes 964 | */ 965 | public function testGetPromoCodes() { 966 | $store_id = 'MC001'; 967 | $promo_rule_id = 'promo0001'; 968 | 969 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 970 | $mc = new MailchimpEcommerce($api_user); 971 | $mc->getPromoCodes($store_id, $promo_rule_id); 972 | // Check method. 973 | $this->assertEquals('GET', $mc->getClient()->method); 974 | // Check URI being used. 975 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/promo-rules/' . $promo_rule_id . '/promo-codes', $mc->getClient()->uri); 976 | } 977 | 978 | /** 979 | * Tests getting a promo code 980 | */ 981 | public function testGetPromoCode() { 982 | $store_id = 'MC001'; 983 | $promo_rule_id = 'promo0001'; 984 | $promo_code_id = 'code001'; 985 | 986 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 987 | $mc = new MailchimpEcommerce($api_user); 988 | $mc->getPromoCode($store_id, $promo_rule_id, $promo_code_id); 989 | // Check method. 990 | $this->assertEquals('GET', $mc->getClient()->method); 991 | // Check URI being used. 992 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/promo-rules/' . $promo_rule_id . '/promo-codes/' . $promo_code_id, $mc->getClient()->uri); 993 | } 994 | 995 | /** 996 | * Tests deleting a promo code 997 | */ 998 | public function testDeletePromoCode() { 999 | $store_id = 'MC001'; 1000 | $promo_rule_id = 'promo0001'; 1001 | $promo_code_id = 'code001'; 1002 | 1003 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 1004 | $mc = new MailchimpEcommerce($api_user); 1005 | $mc->deletePromoCode($store_id, $promo_rule_id, $promo_code_id); 1006 | // Method must be DELETE. 1007 | $this->assertEquals('DELETE', $mc->getClient()->method); 1008 | // Confirm URI being used. 1009 | $this->assertEquals($mc->getEndpoint() . '/ecommerce/stores/' . $store_id . '/promo-rules/' . $promo_rule_id . '/promo-codes/' . $promo_code_id, $mc->getClient()->uri); 1010 | } 1011 | 1012 | } 1013 | -------------------------------------------------------------------------------- /tests/MailchimpListsTest.php: -------------------------------------------------------------------------------- 1 | null, 'api_key' => null]); 19 | $mc = new MailchimpLists($api_user); 20 | $mc->getLists(); 21 | 22 | $this->assertEquals('GET', $mc->getClient()->method); 23 | $this->assertEquals($mc->getEndpoint() . '/lists', $mc->getClient()->uri); 24 | } 25 | 26 | /** 27 | * Tests library functionality for list information. 28 | */ 29 | public function testGetList() { 30 | $list_id = '57afe96172'; 31 | 32 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 33 | $mc = new MailchimpLists($api_user); 34 | $mc->getList($list_id); 35 | 36 | $this->assertEquals('GET', $mc->getClient()->method); 37 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id, $mc->getClient()->uri); 38 | } 39 | 40 | /** 41 | * Tests library functionality for interest categories information. 42 | */ 43 | public function testGetInterestCategories() { 44 | $list_id = '57afe96172'; 45 | 46 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 47 | $mc = new MailchimpLists($api_user); 48 | $mc->getInterestCategories($list_id); 49 | 50 | $this->assertEquals('GET', $mc->getClient()->method); 51 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/interest-categories', $mc->getClient()->uri); 52 | } 53 | 54 | /** 55 | * Tests library functionality for adding new interest categories. 56 | */ 57 | public function testAddInterestCategories() { 58 | $list_id = '57afe96172'; 59 | $title = 'Test Interest Category'; 60 | $type = 'checkbox'; 61 | 62 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 63 | $mc = new MailchimpLists($api_user); 64 | $mc->addInterestCategories($list_id, $title, $type); 65 | 66 | $this->assertEquals('POST', $mc->getClient()->method); 67 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/interest-categories', $mc->getClient()->uri); 68 | 69 | $this->assertNotEmpty($mc->getClient()->options['json']); 70 | 71 | $request_body = $mc->getClient()->options['json']; 72 | 73 | $this->assertEquals($title, $request_body->title); 74 | $this->assertEquals($type, $request_body->type); 75 | } 76 | 77 | /** 78 | * Tests library functionality for updating interest categories. 79 | */ 80 | public function testUpdateInterestCategories() { 81 | $list_id = '57afe96172'; 82 | $title = 'Test Interest Category Edited'; 83 | $type = 'dropdown'; 84 | $interest_category_id = '08f0b1d7b2'; 85 | 86 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 87 | $mc = new MailchimpLists($api_user); 88 | $mc->updateInterestCategories($list_id, $interest_category_id, $title, $type); 89 | 90 | $this->assertEquals('PATCH', $mc->getClient()->method); 91 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/interest-categories/' . $interest_category_id, $mc->getClient()->uri); 92 | 93 | $this->assertNotEmpty($mc->getClient()->options['json']); 94 | 95 | $request_body = $mc->getClient()->options['json']; 96 | 97 | $this->assertEquals($title, $request_body->title); 98 | $this->assertEquals($type, $request_body->type); 99 | } 100 | 101 | /** 102 | * Tests library functionality for deleting interest categories. 103 | */ 104 | public function testDeleteInterestCategories() { 105 | $list_id = '57afe96172'; 106 | $interest_category_id = '08f0b1d7b2'; 107 | 108 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 109 | $mc = new MailchimpLists($api_user); 110 | $mc->deleteInterestCategories($list_id, $interest_category_id); 111 | 112 | $this->assertEquals('DELETE', $mc->getClient()->method); 113 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/interest-categories/' . $interest_category_id, $mc->getClient()->uri); 114 | } 115 | 116 | /** 117 | * Tests library functionality for interests information. 118 | */ 119 | public function testGetInterests() { 120 | $list_id = ''; 121 | $interest_category_id = ''; 122 | 123 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 124 | $mc = new MailchimpLists($api_user); 125 | $mc->getInterests($list_id, $interest_category_id); 126 | 127 | $this->assertEquals('GET', $mc->getClient()->method); 128 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/interest-categories/' . $interest_category_id . '/interests', $mc->getClient()->uri); 129 | } 130 | 131 | /** 132 | * Tests library functionality for adding interests. 133 | */ 134 | public function testAddInterests() { 135 | $list_id = '57afe96172'; 136 | $interest_category_id = '08f0b1d7b2'; 137 | $name = 'Test Interest'; 138 | 139 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 140 | $mc = new MailchimpLists($api_user); 141 | $mc->addInterests($list_id, $interest_category_id, $name); 142 | 143 | $this->assertEquals('POST', $mc->getClient()->method); 144 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/interest-categories/' . $interest_category_id . '/interests', $mc->getClient()->uri); 145 | 146 | $this->assertNotEmpty($mc->getClient()->options['json']); 147 | 148 | $request_body = $mc->getClient()->options['json']; 149 | 150 | $this->assertEquals($name, $request_body->name); 151 | } 152 | 153 | /** 154 | * Tests library functionality for updating interests. 155 | */ 156 | public function testUpdateInterests() { 157 | $list_id = '57afe96172'; 158 | $interest_category_id = '08f0b1d7b2'; 159 | $interest_id = '9143cf3bd1'; 160 | $name = 'Test Interest Edited'; 161 | 162 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 163 | $mc = new MailchimpLists($api_user); 164 | $mc->updateInterests($list_id, $interest_category_id, $interest_id, $name); 165 | 166 | $this->assertEquals('PATCH', $mc->getClient()->method); 167 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/interest-categories/' . $interest_category_id . '/interests/' . $interest_id, $mc->getClient()->uri); 168 | 169 | $this->assertNotEmpty($mc->getClient()->options['json']); 170 | 171 | $request_body = $mc->getClient()->options['json']; 172 | 173 | $this->assertEquals($name, $request_body->name); 174 | } 175 | 176 | /** 177 | * Tests library functionality for deleting interests. 178 | */ 179 | public function testDeleteInterests() { 180 | $list_id = '57afe96172'; 181 | $interest_category_id = '08f0b1d7b2'; 182 | $interest_id = '9143cf3bd1'; 183 | 184 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 185 | $mc = new MailchimpLists($api_user); 186 | $mc->deleteInterests($list_id, $interest_category_id, $interest_id); 187 | 188 | $this->assertEquals('DELETE', $mc->getClient()->method); 189 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/interest-categories/' . $interest_category_id . '/interests/' . $interest_id, $mc->getClient()->uri); 190 | } 191 | 192 | /** 193 | * Tests library functionality for merge fields information. 194 | */ 195 | public function testGetMergeFields() { 196 | $list_id = '57afe96172'; 197 | 198 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 199 | $mc = new MailchimpLists($api_user); 200 | $mc->getMergeFields($list_id); 201 | 202 | $this->assertEquals('GET', $mc->getClient()->method); 203 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/merge-fields', $mc->getClient()->uri); 204 | } 205 | 206 | /** 207 | * Tests library functionality for adding a merge field. 208 | */ 209 | public function testAddMergeField() { 210 | $list_id = '57afe96172'; 211 | $name = 'Phone number'; 212 | $type = 'phone'; 213 | 214 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 215 | $mc = new MailchimpLists($api_user); 216 | $mc->addMergeField($list_id, $name, $type); 217 | 218 | $this->assertEquals('POST', $mc->getClient()->method); 219 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/merge-fields', $mc->getClient()->uri); 220 | 221 | $request_body = $mc->getClient()->options['json']; 222 | 223 | $this->assertEquals($name, $request_body->name); 224 | $this->assertEquals($type, $request_body->type); 225 | } 226 | 227 | /** 228 | * Tests library functionality for members information. 229 | */ 230 | public function testGetMembers() { 231 | $list_id = '57afe96172'; 232 | 233 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 234 | $mc = new MailchimpLists($api_user); 235 | $mc->getMembers($list_id); 236 | 237 | $this->assertEquals('GET', $mc->getClient()->method); 238 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/members', $mc->getClient()->uri); 239 | } 240 | 241 | /** 242 | * Tests library functionality for member information. 243 | */ 244 | public function testGetMemberInfo() { 245 | $list_id = '57afe96172'; 246 | $email = 'test@example.com'; 247 | 248 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 249 | $mc = new MailchimpLists($api_user); 250 | $mc->getMemberInfo($list_id, $email); 251 | 252 | $this->assertEquals('GET', $mc->getClient()->method); 253 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/members/' . md5($email), $mc->getClient()->uri); 254 | } 255 | 256 | /** 257 | * Tests library functionality for member activity information. 258 | */ 259 | public function testGetMemberActivity() { 260 | $list_id = '57afe96172'; 261 | $email = 'test@example.com'; 262 | 263 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 264 | $mc = new MailchimpLists($api_user); 265 | $mc->getMemberActivity($list_id, $email); 266 | 267 | $this->assertEquals('GET', $mc->getClient()->method); 268 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/members/' . md5($email) . '/activity', $mc->getClient()->uri); 269 | } 270 | 271 | /** 272 | * Tests library functionality for member events information. 273 | */ 274 | public function testGetMemberEvents() { 275 | $list_id = '57afe96172'; 276 | $email = 'test@example.com'; 277 | 278 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 279 | $mc = new MailchimpLists($api_user); 280 | $mc->getMemberEvents($list_id, $email); 281 | 282 | $this->assertEquals('GET', $mc->getClient()->method); 283 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/members/' . md5($email) . '/events', $mc->getClient()->uri); 284 | } 285 | 286 | /** 287 | * Tests library functionality for adding a list member. 288 | */ 289 | public function testAddMember() { 290 | $list_id = '57afe96172'; 291 | $email = 'test@example.com'; 292 | 293 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 294 | $mc = new MailchimpLists($api_user); 295 | $mc->addMember($list_id, $email); 296 | 297 | $this->assertEquals('POST', $mc->getClient()->method); 298 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/members', $mc->getClient()->uri); 299 | 300 | $this->assertNotEmpty($mc->getClient()->options['json']); 301 | 302 | $request_body = $mc->getClient()->options['json']; 303 | 304 | $this->assertEquals($email, $request_body->email_address); 305 | } 306 | 307 | /** 308 | * Tests library functionality for removing a list member. 309 | */ 310 | public function testRemoveMember() { 311 | $list_id = '57afe96172'; 312 | $email = 'test@example.com'; 313 | 314 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 315 | $mc = new MailchimpLists($api_user); 316 | $mc->removeMember($list_id, $email); 317 | 318 | $this->assertEquals('DELETE', $mc->getClient()->method); 319 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/members/' . md5($email), $mc->getClient()->uri); 320 | } 321 | 322 | /** 323 | * Tests library functionality for updating a list member. 324 | */ 325 | public function testUpdateMember() { 326 | $list_id = '57afe96172'; 327 | $email = 'test@example.com'; 328 | 329 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 330 | $mc = new MailchimpLists($api_user); 331 | $mc->updateMember($list_id, $email); 332 | 333 | $this->assertEquals('PATCH', $mc->getClient()->method); 334 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/members/' . md5($email), $mc->getClient()->uri); 335 | } 336 | 337 | /** 338 | * Tests library functionality for adding or updating an existing list member. 339 | */ 340 | public function testAddOrUpdateMember() { 341 | $list_id = '57afe96172'; 342 | $email = 'test@example.com'; 343 | 344 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 345 | $mc = new MailchimpLists($api_user); 346 | $mc->addOrUpdateMember($list_id, $email); 347 | 348 | $this->assertEquals('PUT', $mc->getClient()->method); 349 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/members/' . md5($email), $mc->getClient()->uri); 350 | } 351 | 352 | /** 353 | * Tests library functionality for member tags information. 354 | */ 355 | public function testGetMemberTags() { 356 | $list_id = '57afe96172'; 357 | $email = 'test@example.com'; 358 | 359 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 360 | $mc = new MailchimpLists($api_user); 361 | $mc->getMemberTags($list_id, $email); 362 | 363 | $this->assertEquals('GET', $mc->getClient()->method); 364 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/members/' . md5($email) . '/tags', $mc->getClient()->uri); 365 | } 366 | 367 | /** 368 | * Tests library functionality for list segment information. 369 | */ 370 | public function testGetSegments() { 371 | $list_id = '57afe96172'; 372 | 373 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 374 | $mc = new MailchimpLists($api_user); 375 | $mc->getSegments($list_id); 376 | 377 | $this->assertEquals('GET', $mc->getClient()->method); 378 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/segments', $mc->getClient()->uri); 379 | } 380 | 381 | /** 382 | * Tests library functionality for list segment information. 383 | */ 384 | public function testGetSegment() { 385 | $list_id = '57afe96172'; 386 | $segment_id = '49377'; 387 | 388 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 389 | $mc = new MailchimpLists($api_user); 390 | $mc->getSegment($list_id, $segment_id); 391 | 392 | $this->assertEquals('GET', $mc->getClient()->method); 393 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/segments/' . $segment_id, $mc->getClient()->uri); 394 | } 395 | 396 | /** 397 | * Tests library functionality for adding a list segment. 398 | */ 399 | public function testAddSegment() { 400 | $list_id = '57afe96172'; 401 | $name = 'Test Segment'; 402 | 403 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 404 | $mc = new MailchimpLists($api_user); 405 | $mc->addSegment($list_id, $name); 406 | 407 | $this->assertEquals('POST', $mc->getClient()->method); 408 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/segments', $mc->getClient()->uri); 409 | 410 | $this->assertNotEmpty($mc->getClient()->options['json']); 411 | 412 | $request_body = $mc->getClient()->options['json']; 413 | 414 | $this->assertEquals($name, $request_body->name); 415 | } 416 | 417 | /** 418 | * Tests library functionality for updating a list segment. 419 | */ 420 | public function testUpdateSegment() { 421 | $list_id = '57afe96172'; 422 | $segment_id = '49381'; 423 | $name = 'Updated Test Segment'; 424 | 425 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 426 | $mc = new MailchimpLists($api_user); 427 | $mc->updateSegment($list_id, $segment_id, $name); 428 | 429 | $this->assertEquals('PATCH', $mc->getClient()->method); 430 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/segments/' . $segment_id, $mc->getClient()->uri); 431 | 432 | $this->assertNotEmpty($mc->getClient()->options['json']); 433 | 434 | $request_body = $mc->getClient()->options['json']; 435 | 436 | $this->assertEquals($name, $request_body->name); 437 | } 438 | 439 | /** 440 | * Tests library functionality for segment member information. 441 | */ 442 | public function testGetSegmentMembers() { 443 | $list_id = '205d96e6b4'; 444 | $segment_id = '457'; 445 | 446 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 447 | $mc = new MailchimpLists($api_user); 448 | $mc->getSegmentMembers($list_id, $segment_id); 449 | 450 | $this->assertEquals('GET', $mc->getClient()->method); 451 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/segments/' . $segment_id . '/members', $mc->getClient()->uri); 452 | } 453 | 454 | /** 455 | * Tests library functionality for adding a segment member. 456 | */ 457 | public function testAddSegmentMember() { 458 | $list_id = '205d96e6b4'; 459 | $segment_id = '457'; 460 | $email = 'test@example.com'; 461 | 462 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 463 | $mc = new MailchimpLists($api_user); 464 | $mc->addSegmentMember($list_id, $segment_id, $email); 465 | 466 | $this->assertEquals('POST', $mc->getClient()->method); 467 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/segments/' . $segment_id . '/members', $mc->getClient()->uri); 468 | 469 | $this->assertNotEmpty($mc->getClient()->options['json']); 470 | 471 | $request_body = $mc->getClient()->options['json']; 472 | 473 | $this->assertEquals($email, $request_body->email_address); 474 | } 475 | 476 | /** 477 | * Tests library functionality for removing a segment member. 478 | */ 479 | public function testRemoveSegmentMember() { 480 | $list_id = '205d96e6b4'; 481 | $segment_id = '457'; 482 | $email = 'test@example.com'; 483 | 484 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 485 | $mc = new MailchimpLists($api_user); 486 | $mc->removeSegmentMember($list_id, $segment_id, $email); 487 | 488 | $this->assertEquals('DELETE', $mc->getClient()->method); 489 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/segments/' . $segment_id . '/members/' . md5($email), $mc->getClient()->uri); 490 | } 491 | 492 | /** 493 | * Tests library functionality for adding tags to a member. 494 | */ 495 | public function testAddTagsMember() { 496 | $list_id = '205d96e6b4'; 497 | $tags = ['Foo', 'Bar']; 498 | $email = 'test@example.com'; 499 | 500 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 501 | $mc = new MailchimpLists($api_user); 502 | $mc->addTagsMember($list_id, $tags, $email); 503 | 504 | $this->assertEquals('POST', $mc->getClient()->method); 505 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/members/' . md5($email) . '/tags', $mc->getClient()->uri); 506 | 507 | $this->assertNotEmpty($mc->getClient()->options['json']); 508 | 509 | $request_body = $mc->getClient()->options['json']; 510 | 511 | $expected = [ 512 | [ 513 | 'name' => 'Foo', 514 | 'status' => 'active', 515 | ], 516 | [ 517 | 'name' => 'Bar', 518 | 'status' => 'active', 519 | ], 520 | ]; 521 | $this->assertEquals($expected, $request_body->tags); 522 | } 523 | 524 | /** 525 | * Tests library functionality for removing tags from a member. 526 | */ 527 | public function testRemoveTagsMember() { 528 | $list_id = '205d96e6b4'; 529 | $tags = ['Foo', 'Bar']; 530 | $email = 'test@example.com'; 531 | 532 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 533 | $mc = new MailchimpLists($api_user); 534 | $mc->removeTagsMember($list_id, $tags, $email); 535 | 536 | $this->assertEquals('POST', $mc->getClient()->method); 537 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/members/' . md5($email) . '/tags', $mc->getClient()->uri); 538 | 539 | $this->assertNotEmpty($mc->getClient()->options['json']); 540 | 541 | $request_body = $mc->getClient()->options['json']; 542 | 543 | $expected = [ 544 | [ 545 | 'name' => 'Foo', 546 | 'status' => 'inactive', 547 | ], 548 | [ 549 | 'name' => 'Bar', 550 | 'status' => 'inactive', 551 | ], 552 | ]; 553 | $this->assertEquals($expected, $request_body->tags); 554 | } 555 | 556 | /** 557 | * Tests library functionality for adding a member event. 558 | */ 559 | public function testAddMemberEvent() { 560 | $list_id = '205d96e6b4'; 561 | $email = 'test@example.com'; 562 | $event = [ 563 | "name" => "registered_referral", 564 | "properties" => [ 565 | "ref-code-123456" 566 | ], 567 | ]; 568 | 569 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 570 | $mc = new MailchimpLists($api_user); 571 | $mc->AddMemberEvent($list_id, $email, $event); 572 | 573 | $this->assertEquals('POST', $mc->getClient()->method); 574 | $this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/members/' . md5($email) . '/events', $mc->getClient()->uri); 575 | 576 | $this->assertNotEmpty($mc->getClient()->options['json']); 577 | 578 | $request_body = $mc->getClient()->options['json']; 579 | 580 | $this->assertEquals($event, (array) $request_body); 581 | } 582 | } 583 | -------------------------------------------------------------------------------- /tests/MailchimpReportsTest.php: -------------------------------------------------------------------------------- 1 | null, 'api_key' => null]); 19 | $mc = new MailchimpReports($api_user); 20 | $mc->getSummary(); 21 | 22 | $this->assertEquals('GET', $mc->getClient()->method); 23 | $this->assertEquals($mc->getEndpoint() . '/reports', $mc->getClient()->uri); 24 | } 25 | 26 | /** 27 | * Tests library functionality for campaign report information. 28 | */ 29 | public function testCampaignSummary() { 30 | $campaign_id = '42694e9e57'; 31 | 32 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 33 | $mc = new MailchimpReports($api_user); 34 | $mc->getCampaignSummary($campaign_id); 35 | 36 | $this->assertEquals('GET', $mc->getClient()->method); 37 | $this->assertEquals($mc->getEndpoint() . '/reports/' . $campaign_id, $mc->getClient()->uri); 38 | } 39 | 40 | /** 41 | * Tests library functionality for campaign report information. 42 | */ 43 | public function testCampaignReport() { 44 | $campaign_id = '42694e9e57'; 45 | $type = 'email-activity'; 46 | 47 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 48 | $mc = new MailchimpReports($api_user); 49 | $mc->getCampaignReport($campaign_id, $type); 50 | 51 | $this->assertEquals('GET', $mc->getClient()->method); 52 | $this->assertEquals($mc->getEndpoint() . '/reports/' . $campaign_id . '/' . $type, $mc->getClient()->uri); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /tests/MailchimpTemplatesTest.php: -------------------------------------------------------------------------------- 1 | null, 'api_key' => null]); 19 | $mc = new MailchimpTemplates($api_user); 20 | $mc->getTemplates(); 21 | 22 | $this->assertEquals('GET', $mc->getClient()->method); 23 | $this->assertEquals($mc->getEndpoint() . '/templates', $mc->getClient()->uri); 24 | } 25 | 26 | /** 27 | * Tests library functionality for template information. 28 | */ 29 | public function testGetTemplate() { 30 | $template_id = '2000094'; 31 | 32 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 33 | $mc = new MailchimpTemplates($api_user); 34 | $mc->getTemplate($template_id); 35 | 36 | $this->assertEquals('GET', $mc->getClient()->method); 37 | $this->assertEquals($mc->getEndpoint() . '/templates/' . $template_id, $mc->getClient()->uri); 38 | } 39 | 40 | /** 41 | * Tests library functionality for template content information. 42 | */ 43 | public function testGetTemplateContent() { 44 | $template_id = '2000094'; 45 | 46 | $api_user = new Mailchimp(['api_user' => null, 'api_key' => null]); 47 | $mc = new MailchimpTemplates($api_user); 48 | $mc->getTemplateContent($template_id); 49 | 50 | $this->assertEquals('GET', $mc->getClient()->method); 51 | $this->assertEquals($mc->getEndpoint() . '/templates/' . $template_id . '/default-content', $mc->getClient()->uri); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /tests/MailchimpTest.php: -------------------------------------------------------------------------------- 1 | null, 'api_key' => null]); 19 | $mc = new MailchimpApiUser($api_user); 20 | $mc->getAccount(); 21 | 22 | $this->assertEquals('GET', $mc->getClient()->method); 23 | $this->assertEquals($mc->getEndpoint() . '/', $mc->getClient()->uri); 24 | } 25 | 26 | /** 27 | * Test the version number. 28 | */ 29 | public function testVersion() { 30 | $mc = new Mailchimp(['api_user' => null, 'api_key' => null]); 31 | $this->assertEquals(json_decode(file_get_contents('composer.json'))->version, $mc::VERSION); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /tests/src/Client.php: -------------------------------------------------------------------------------- 1 | method = $method; 23 | $this->uri = $uri; 24 | $this->options = $options; 25 | 26 | return new Response(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /tests/src/Mailchimp.php: -------------------------------------------------------------------------------- 1 | client = new MailchimpTestHttpClient(); 17 | 18 | parent::__construct($authentication_settings, $http_options, $this->client); 19 | } 20 | 21 | public function getClient() { 22 | return $this->api_class->client; 23 | } 24 | 25 | public function getEndpoint() { 26 | return 'https://us1.api.mailchimp.com/3.0'; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /tests/src/MailchimpApiUser.php: -------------------------------------------------------------------------------- 1 | client = new MailchimpTestHttpClient(); 19 | 20 | parent::__construct($api_class); 21 | } 22 | 23 | public function getClient() { 24 | return $this->api_class->client; 25 | } 26 | 27 | public function getEndpoint() { 28 | return 'https://us1.api.mailchimp.com/3.0'; 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /tests/src/MailchimpAutomations.php: -------------------------------------------------------------------------------- 1 | client = new MailchimpTestHttpClient(); 19 | 20 | parent::__construct($api_class); 21 | } 22 | 23 | public function getClient() { 24 | return $this->api_class->client; 25 | } 26 | 27 | public function getEndpoint() { 28 | return 'https://us1.api.mailchimp.com/3.0'; 29 | } 30 | 31 | /** 32 | * @inheritdoc 33 | */ 34 | public function getAutomations($parameters = []) { 35 | parent::getAutomations($parameters); 36 | 37 | $response = (object) [ 38 | 'automations' => [ 39 | (object) [ 40 | 'id' => '57afe96172', 41 | 'name' => 'Test Automation One', 42 | ], 43 | (object) [ 44 | 'id' => 'f4b7b26b2e', 45 | 'name' => 'Test Automation Two', 46 | ], 47 | (object) [ 48 | 'id' => '587693d673', 49 | 'name' => 'Test Automation Three', 50 | ], 51 | ], 52 | 'total_items' => 3, 53 | ]; 54 | 55 | return $response; 56 | } 57 | 58 | /** 59 | * @inheritdoc 60 | */ 61 | public function getWorkflow($workflow_id) { 62 | parent::getWorkflow($workflow_id); 63 | $response = (object) [ 64 | 'id' => 'eb4c82c9d2', 65 | 'create_time' => '2015-07-23T15:15:00+00:00', 66 | 'start_time' => '', 67 | 'status' => 'save', 68 | 'emails_sent' => 0, 69 | ]; 70 | 71 | return $response; 72 | } 73 | 74 | /** 75 | * @inheritdoc 76 | */ 77 | public function getWorkflowEmails($workflow_id) { 78 | parent::getWorkflowEmails($workflow_id); 79 | 80 | $response = (object) [ 81 | 'emails' => [ 82 | (object) [ 83 | 'id' => 'a87de7d1e5', 84 | 'workflow_id' => '57afe96172', 85 | 'position' => 1, 86 | 'status' => 'sending', 87 | 'emails_sent' => 1, 88 | 'send_time' => '2016-07-20T15:48:04+00:00', 89 | 'content_type' => 'template', 90 | ], 91 | ], 92 | 'total_items' => 1, 93 | ]; 94 | 95 | return $response; 96 | } 97 | 98 | /** 99 | * @inheritdoc 100 | */ 101 | public function getWorkflowEmail($workflow_id,$workflow_email_id) { 102 | parent::getWorkflowEmail($workflow_id, $workflow_email_id); 103 | 104 | $response = (object) [ 105 | 'id' => 'a87de7d1e5', 106 | 'workflow_id' => '57afe96172', 107 | 'position' => 1, 108 | 'status' => 'sending', 109 | 'emails_sent' => 1, 110 | 'send_time' => '2016-07-20T15:48:04+00:00', 111 | 'content_type' => 'template', 112 | ]; 113 | 114 | return $response; 115 | } 116 | 117 | /** 118 | * @inheritdoc 119 | */ 120 | public function getWorkflowEmailSubscribers($workflow_id, $workflow_email_id) { 121 | parent::getWorkflowEmailSubscribers($workflow_id, $workflow_email_id); 122 | 123 | $response = (object) [ 124 | 'workflow_id' => '4e3da78a41', 125 | 'email_id' => 'a87de7d1e5', 126 | 'queue' => [], 127 | 'total_items' => 0, 128 | ]; 129 | 130 | return $response; 131 | } 132 | 133 | /** 134 | * @inheritdoc 135 | */ 136 | public function getWorkflowEmailSubscriber($workflow_id, $workflow_email_id, $email) { 137 | parent::getWorkflowEmailSubscriber($workflow_id, $workflow_email_id, $email); 138 | 139 | $response = (object) [ 140 | 'id' => md5(strtolower($email)), 141 | 'workflow_id' => '4e3da78a41', 142 | 'email_id' => 'a87de7d1e5', 143 | 'list_id' => '57afe96172', 144 | 'email_address' => $email, 145 | 'next_send' => '2017-04-28T15:48:04+00:00', 146 | ]; 147 | 148 | return $response; 149 | } 150 | 151 | } 152 | -------------------------------------------------------------------------------- /tests/src/MailchimpCampaigns.php: -------------------------------------------------------------------------------- 1 | client = new MailchimpTestHttpClient(); 24 | 25 | parent::__construct($api_class); 26 | } 27 | 28 | public function getClient() { 29 | return $this->api_class->client; 30 | } 31 | 32 | public function getEndpoint() { 33 | return 'https://us1.api.mailchimp.com/3.0'; 34 | } 35 | 36 | /** 37 | * @inheritdoc 38 | */ 39 | public function getCampaign($campaign_id, $parameters = []) { 40 | parent::getCampaign($campaign_id, $parameters); 41 | 42 | $response = (object) [ 43 | 'id' => $campaign_id, 44 | 'type' => 'regular', 45 | 'recipients' => (object) [ 46 | 'list_id' => '57afe96172', 47 | ], 48 | 'settings' => (object) [ 49 | 'subject_line' => 'Test Campaign', 50 | ], 51 | 'tracking' => (object) [ 52 | 'html_clicks' => TRUE, 53 | 'text_clicks' => FALSE, 54 | ], 55 | ]; 56 | 57 | return $response; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /tests/src/MailchimpConnectedSites.php: -------------------------------------------------------------------------------- 1 | client = new MailchimpTestHttpClient(); 24 | 25 | parent::__construct($api_class); 26 | } 27 | 28 | public function getClient() { 29 | return $this->api_class->client; 30 | } 31 | 32 | public function getEndpoint() { 33 | return 'https://us1.api.mailchimp.com/3.0'; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /tests/src/MailchimpEcommerce.php: -------------------------------------------------------------------------------- 1 | client = new MailchimpTestHttpClient(); 47 | 48 | parent::__construct($api_class); 49 | } 50 | 51 | public function getClient() { 52 | return $this->api_class->client; 53 | } 54 | 55 | public function getEndpoint() { 56 | return 'https://us1.api.mailchimp.com/3.0'; 57 | } 58 | 59 | /** 60 | * @inheritdoc 61 | */ 62 | public function getStore($store_id, $parameters = []) { 63 | parent::getStore($store_id, $parameters); 64 | 65 | return (isset($this->stores[$store_id])) ? $this->stores[$store_id] : NULL; 66 | } 67 | 68 | /** 69 | * @inheritdoc 70 | */ 71 | public function addStore($id, $store, $parameters = [], $batch = FALSE) { 72 | parent::addStore($id, $store, $batch); 73 | 74 | $parameters = [ 75 | 'id' => $id, 76 | ]; 77 | $parameters += $store; 78 | 79 | $this->stores[$id] = (object) $parameters; 80 | } 81 | 82 | /** 83 | * @inheritdoc 84 | */ 85 | public function getCustomer($store_id, $customer_id, $parameters = []) { 86 | parent::getCustomer($store_id, $customer_id, $parameters); 87 | 88 | if (isset($this->customers[$store_id])) { 89 | return (isset($this->customers[$store_id][$customer_id])) ? $this->customers[$store_id][$customer_id] : NULL; 90 | } 91 | 92 | return NULL; 93 | } 94 | 95 | /** 96 | * @inheritdoc 97 | */ 98 | public function addCustomer($store_id, $customer, $batch = FALSE) { 99 | parent::addCustomer($store_id, $customer, $batch); 100 | 101 | if (!isset($this->customers[$store_id])) { 102 | $this->customers[$store_id] = []; 103 | } 104 | 105 | $this->customers[$store_id][$customer['id']] = (object) $customer; 106 | } 107 | 108 | /** 109 | * @inheritdoc 110 | */ 111 | public function getOrder($store_id, $order_id, $parameters = []) { 112 | parent::getOrder($store_id, $order_id, $parameters); 113 | 114 | if (isset($this->orders[$store_id])) { 115 | return (isset($this->orders[$store_id][$order_id])) ? $this->orders[$store_id][$order_id] : NULL; 116 | } 117 | 118 | return NULL; 119 | } 120 | 121 | /** 122 | * @inheritdoc 123 | */ 124 | public function addOrder($store_id, $id, array $customer, array $order, $batch = FALSE) { 125 | parent::addOrder($store_id, $id, $customer, $order, $batch); 126 | 127 | if (empty($store_id)) { 128 | throw new MailchimpAPIException('Store ID cannot be empty.'); 129 | } 130 | 131 | if (empty($id)) { 132 | throw new MailchimpAPIException('Order ID cannot be empty.'); 133 | } 134 | 135 | if (empty($customer)) { 136 | throw new MailchimpAPIException('Customer cannot be empty.'); 137 | } 138 | 139 | if (empty($order)) { 140 | throw new MailchimpAPIException('Order cannot be empty.'); 141 | } 142 | 143 | if (!isset($order['lines']) || empty($order['lines'])) { 144 | throw new MailchimpAPIException('Order must contain at least one line item.'); 145 | } 146 | 147 | if (!isset($this->orders[$store_id])) { 148 | $this->orders[$store_id] = []; 149 | } 150 | 151 | $parameters = [ 152 | 'id' => $id, 153 | 'customer' => (object) $customer, 154 | ]; 155 | 156 | $parameters += $order; 157 | 158 | $this->orders[$store_id][$id] = (object) $parameters; 159 | } 160 | 161 | } 162 | -------------------------------------------------------------------------------- /tests/src/MailchimpLists.php: -------------------------------------------------------------------------------- 1 | client = new MailchimpTestHttpClient(); 24 | 25 | parent::__construct($api_class); 26 | } 27 | 28 | public function getClient() { 29 | return $this->api_class->client; 30 | } 31 | 32 | public function getEndpoint() { 33 | return 'https://us1.api.mailchimp.com/3.0'; 34 | } 35 | 36 | /** 37 | * @inheritdoc 38 | */ 39 | public function getLists($parameters = []) { 40 | parent::getLists($parameters); 41 | 42 | $response = (object) [ 43 | 'lists' => [ 44 | (object) [ 45 | 'id' => '57afe96172', 46 | 'name' => 'Test List One', 47 | ], 48 | (object) [ 49 | 'id' => 'f4b7b26b2e', 50 | 'name' => 'Test List Two', 51 | ], 52 | (object) [ 53 | 'id' => '587693d673', 54 | 'name' => 'Test List Three', 55 | ], 56 | ], 57 | 'total_items' => 3, 58 | ]; 59 | 60 | return $response; 61 | } 62 | 63 | /** 64 | * @inheritdoc 65 | */ 66 | public function getList($list_id, $parameters = []) { 67 | parent::getList($list_id, $parameters); 68 | 69 | $response = (object) [ 70 | 'id' => $list_id, 71 | 'name' => 'Test List One', 72 | ]; 73 | 74 | return $response; 75 | } 76 | 77 | /** 78 | * @inheritdoc 79 | */ 80 | public function getInterestCategories($list_id, $parameters = []) { 81 | parent::getInterestCategories($list_id, $parameters); 82 | 83 | $response = (object) [ 84 | 'list_id' => $list_id, 85 | 'categories' => [ 86 | (object) [ 87 | 'list_id' => $list_id, 88 | 'id' => 'a1e9f4b7f6', 89 | 'title' => 'Test Interest Category', 90 | ], 91 | ], 92 | 'total_items' => 1, 93 | ]; 94 | 95 | return $response; 96 | } 97 | 98 | /** 99 | * @inheritdoc 100 | */ 101 | public function addInterestCategories($list_id, $title, $type, $parameters = [], $batch = FALSE) { 102 | parent::addInterestCategories($list_id, $title, $type, $parameters = [], $batch = FALSE); 103 | 104 | $response = (object) [ 105 | 'list_id' => $list_id, 106 | 'id' => 'a1e9f4b7f6', 107 | 'title' => $title, 108 | 'type' => $type, 109 | ]; 110 | 111 | return $response; 112 | } 113 | 114 | /** 115 | * @inheritdoc 116 | */ 117 | public function updateInterestCategories($list_id, $interest_category_id, $title, $type, $parameters = [], $batch = FALSE) { 118 | parent::updateInterestCategories($list_id, $interest_category_id, $title, $type, $parameters = [], $batch = FALSE); 119 | 120 | $response = (object) [ 121 | 'list_id' => $list_id, 122 | 'id' => 'a1e9f4b7f6', 123 | 'title' => $title, 124 | 'type' => $type, 125 | 'interest_category_id' => $interest_category_id, 126 | ]; 127 | 128 | return $response; 129 | } 130 | 131 | /** 132 | * @inheritdoc 133 | */ 134 | public function deleteInterestCategories($list_id, $interest_category_id, $parameters = [], $batch = FALSE) { 135 | parent::deleteInterestCategories($list_id, $interest_category_id, $parameters = [], $batch = FALSE); 136 | 137 | return (!empty($list_id) && !empty($interest_category_id)); 138 | } 139 | 140 | /** 141 | * @inheritdoc 142 | */ 143 | public function getInterests($list_id, $interest_category_id, $parameters = []) { 144 | parent::getInterests($list_id, $interest_category_id, $parameters); 145 | 146 | $response = (object) [ 147 | 'interests' => [ 148 | (object) [ 149 | 'category_id' => $interest_category_id, 150 | 'list_id' => $list_id, 151 | 'id' => '9143cf3bd1', 152 | 'name' => 'Test Interest', 153 | ], 154 | ], 155 | 'total_items' => 1, 156 | ]; 157 | 158 | return $response; 159 | } 160 | 161 | /** 162 | * @inheritdoc 163 | */ 164 | public function addInterests($list_id, $interest_category_id, $name, $parameters = [], $batch = FALSE) { 165 | parent::addInterests($list_id, $interest_category_id, $name, $parameters = [], $batch = FALSE); 166 | 167 | $response = (object) [ 168 | 'list_id' => $list_id, 169 | 'category_id' => $interest_category_id, 170 | 'interest_id' => '9143cf3bd1', 171 | 'name' => $name, 172 | ]; 173 | 174 | return $response; 175 | } 176 | 177 | /** 178 | * @inheritdoc 179 | */ 180 | public function updateInterests($list_id, $interest_category_id, $interest_id, $name, $parameters = [], $batch = FALSE) { 181 | parent::updateInterests($list_id, $interest_category_id, $interest_id, $name, $parameters = [], $batch = FALSE); 182 | 183 | $response = (object) [ 184 | 'list_id' => $list_id, 185 | 'category_id' => $interest_category_id, 186 | 'interest_id' => $interest_id, 187 | 'name' => $name, 188 | ]; 189 | 190 | return $response; 191 | } 192 | 193 | /** 194 | * @inheritdoc 195 | */ 196 | public function deleteInterests($list_id, $interest_category_id, $interest_id, $parameters = [], $batch = FALSE) { 197 | parent::deleteInterests($list_id, $interest_category_id, $interest_id, $parameters = [], $batch = FALSE); 198 | 199 | return (!empty($list_id) && !empty($interest_category_id) && !empty($interest_id)); 200 | } 201 | 202 | /** 203 | * @inheritdoc 204 | */ 205 | public function getMergeFields($list_id, $parameters = []) { 206 | parent::getMergeFields($list_id, $parameters); 207 | 208 | $response = (object) [ 209 | 'merge_fields' => [ 210 | (object) [ 211 | 'merge_id' => 1, 212 | 'tag' => 'FNAME', 213 | 'list_id' => $list_id, 214 | ], 215 | (object) [ 216 | 'merge_id' => 2, 217 | 'tag' => 'LNAME', 218 | 'list_id' => $list_id, 219 | ], 220 | ], 221 | 'total_items' => 2, 222 | ]; 223 | 224 | return $response; 225 | } 226 | 227 | /** 228 | * @inheritdoc 229 | */ 230 | public function getMemberInfo($list_id, $email, $parameters = []) { 231 | parent::getMemberInfo($list_id, $email, $parameters); 232 | 233 | $response = (object) [ 234 | 'id' => md5(strtolower($email)), 235 | 'email_address' => $email, 236 | 'status' => 'subscribed', 237 | ]; 238 | 239 | return $response; 240 | } 241 | 242 | /** 243 | * @inheritdoc 244 | */ 245 | public function addMember($list_id, $email, $parameters = [], $batch = FALSE) { 246 | parent::addMember($list_id, $email, $parameters, $batch); 247 | 248 | $response = (object) [ 249 | 'id' => md5(strtolower($email)), 250 | 'email_address' => $email, 251 | ]; 252 | 253 | foreach ($parameters as $key => $value) { 254 | $response->{$key} = $value; 255 | } 256 | 257 | return $response; 258 | } 259 | 260 | /** 261 | * @inheritdoc 262 | */ 263 | public function removeMember($list_id, $email) { 264 | parent::removeMember($list_id, $email); 265 | } 266 | 267 | /** 268 | * @inheritdoc 269 | */ 270 | public function updateMember($list_id, $email, $parameters = [], $batch = FALSE) { 271 | parent::updateMember($list_id, $email, $parameters, $batch); 272 | 273 | $response = (object) [ 274 | 'id' => md5(strtolower($email)), 275 | 'email_address' => $email, 276 | ]; 277 | 278 | foreach ($parameters as $key => $value) { 279 | $response->{$key} = $value; 280 | } 281 | 282 | return $response; 283 | } 284 | 285 | /** 286 | * @inheritdoc 287 | */ 288 | public function addOrUpdateMember($list_id, $email, $parameters = [], $batch = FALSE) { 289 | parent::addOrUpdateMember($list_id, $email, $parameters, $batch); 290 | 291 | $response = (object) [ 292 | 'id' => md5(strtolower($email)), 293 | 'email_address' => $email, 294 | ]; 295 | 296 | foreach ($parameters as $key => $value) { 297 | $response->{$key} = $value; 298 | } 299 | 300 | return $response; 301 | } 302 | 303 | /** 304 | * @inheritdoc 305 | */ 306 | public function getSegments($list_id, $parameters = []) { 307 | parent::getSegments($list_id, $parameters); 308 | 309 | $response = (object) [ 310 | 'segments' => [ 311 | (object) [ 312 | 'id' => 49377, 313 | 'name' => 'Test Segment One', 314 | 'type' => 'static', 315 | 'list_id' => $list_id, 316 | ], 317 | (object) [ 318 | 'id' => 49378, 319 | 'name' => 'Test Segment Two', 320 | 'type' => 'static', 321 | 'list_id' => $list_id, 322 | ], 323 | ], 324 | 'total_items' => 2, 325 | ]; 326 | 327 | return $response; 328 | } 329 | 330 | /** 331 | * @inheritdoc 332 | */ 333 | public function getSegment($list_id, $segment_id, $parameters = []) { 334 | parent::getSegment($list_id, $segment_id, $parameters); 335 | 336 | $response = (object) [ 337 | 'id' => 49377, 338 | 'name' => 'Test Segment One', 339 | 'type' => 'static', 340 | 'list_id' => $list_id, 341 | ]; 342 | 343 | return $response; 344 | } 345 | 346 | /** 347 | * @inheritdoc 348 | */ 349 | public function addSegment($list_id, $name, $parameters = [], $batch = FALSE) { 350 | parent::addSegment($list_id, $name, $parameters, $batch); 351 | 352 | $response = (object) []; 353 | 354 | if (!empty($list_id) && !empty($name) && !empty($parameters['type'])) { 355 | $response->id = 49381; 356 | $response->name = $name; 357 | $response->type = $parameters['type']; 358 | $response->list_id = $list_id; 359 | } 360 | 361 | return $response; 362 | } 363 | 364 | /** 365 | * @inheritdoc 366 | */ 367 | public function updateSegment($list_id, $segment_id, $name, $parameters = [], $batch = FALSE) { 368 | parent::updateSegment($list_id, $segment_id, $name, $parameters); 369 | 370 | $response = (object) [ 371 | 'id' => $segment_id, 372 | 'name' => $name, 373 | 'member_count' => (isset($parameters['static_segment'])) ? count($parameters['static_segment']) : 0, 374 | 'list_id' => $list_id, 375 | ]; 376 | 377 | return $response; 378 | } 379 | 380 | /** 381 | * @inheritdoc 382 | */ 383 | public function getWebhooks($list_id, $parameters = []) { 384 | parent::getWebhooks($list_id, $parameters); 385 | 386 | $response = (object) [ 387 | 'webhooks' => [ 388 | (object) [ 389 | 'id' => '37b9c73a88', 390 | 'url' => 'http://example.org', 391 | 'events' => (object) [ 392 | 'subscribe' => TRUE, 393 | 'unsubscribe' => FALSE, 394 | ], 395 | 'sources' => (object) [ 396 | 'user' => TRUE, 397 | 'api' => FALSE, 398 | ], 399 | 'list_id' => $list_id, 400 | ], 401 | ], 402 | 'total_items' => 1, 403 | ]; 404 | 405 | return $response; 406 | } 407 | 408 | /** 409 | * @inheritdoc 410 | */ 411 | public function addWebhook($list_id, $url, $parameters = [], $batch = FALSE) { 412 | parent::addWebhook($list_id, $url, $parameters, $batch); 413 | 414 | $response = (object) [ 415 | 'id' => 'ab24521a00', 416 | 'url' => $url, 417 | 'list_id' => $list_id, 418 | ]; 419 | 420 | foreach ($parameters as $key => $value) { 421 | $response->{$key} = $value; 422 | } 423 | 424 | return $response; 425 | } 426 | 427 | /** 428 | * @inheritdoc 429 | */ 430 | public function deleteWebhook($list_id, $webhook_id, $parameters = []) { 431 | parent::deleteWebhook($list_id, $webhook_id, $parameters); 432 | 433 | return (!empty($list_id) && !empty($webhook_id)); 434 | } 435 | 436 | } 437 | -------------------------------------------------------------------------------- /tests/src/MailchimpReports.php: -------------------------------------------------------------------------------- 1 | client = new MailchimpTestHttpClient(); 24 | 25 | parent::__construct($api_class); 26 | } 27 | 28 | public function getClient() { 29 | return $this->api_class->client; 30 | } 31 | 32 | public function getEndpoint() { 33 | return 'https://us1.api.mailchimp.com/3.0'; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /tests/src/MailchimpTemplates.php: -------------------------------------------------------------------------------- 1 | client = new MailchimpTestHttpClient(); 24 | 25 | parent::__construct($api_class); 26 | } 27 | 28 | public function getClient() { 29 | return $this->api_class->client; 30 | } 31 | 32 | public function getEndpoint() { 33 | return 'https://us1.api.mailchimp.com/3.0'; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /tests/src/MailchimpTestHttpClient.php: -------------------------------------------------------------------------------- 1 | method = $method; 38 | $this->uri = $uri; 39 | $this->options = $options; 40 | 41 | return new MailchimpTestHttpResponse(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /tests/src/MailchimpTestHttpResponse.php: -------------------------------------------------------------------------------- 1 |