You are here

public function MailchimpCampaignsTest::testAddCampaign in Mailchimp 8

Tests library functionality for adding a new campaign.

File

lib/mailchimp-api-php/tests/MailchimpCampaignsTest.php, line 41

Class

MailchimpCampaignsTest
Mailchimp Campaign test library.

Namespace

Mailchimp\Tests

Code

public function testAddCampaign() {
  $type = 'regular';
  $recipients = (object) [
    'list_id' => '3c307a9f3f',
  ];
  $settings = (object) [
    'subject_line' => 'Your Purchase Receipt',
    'from_name' => 'Customer Service',
  ];
  $mc = new MailchimpCampaigns();
  $mc
    ->addCampaign($type, $recipients, $settings);
  $this
    ->assertEquals('POST', $mc
    ->getClient()->method);
  $this
    ->assertEquals($mc
    ->getEndpoint() . '/campaigns', $mc
    ->getClient()->uri);
  $this
    ->assertNotEmpty($mc
    ->getClient()->options['json']);
  $request_body = $mc
    ->getClient()->options['json'];
  $this
    ->assertEquals($type, $request_body->type);
  $this
    ->assertEquals($recipients->list_id, $request_body->recipients->list_id);
  $this
    ->assertEquals($settings->subject_line, $request_body->settings->subject_line);
  $this
    ->assertEquals($settings->from_name, $request_body->settings->from_name);
}