public function testGetPerson()
 {
     $container = $responses = [];
     $responses[] = new Response(200, [], json_encode($this->responsePerson));
     $person_manager = $this->getPersonService($container, $responses);
     $person = $person_manager->getPerson('abc');
     $this->assertTrue($person instanceof PersonModel, 'The person manager should had returned an instance of a PersonModel.');
     $response_person = PersonModel::create($this->responsePerson);
     $this->assertEquals($response_person, $person);
 }
 public function assertModelMatchesConfiguration(ModelInterface $list, $configuration = array())
 {
     if (empty($configuration)) {
         $configuration = $this->configuration;
     }
     $this->assertSame($configuration['object'], $list->objectType);
     $this->assertSame($configuration['email'], $list->email);
     $date_added = new \DateTime($configuration['date_added']);
     $this->assertEquals($date_added, $list->dateAdded);
     $person = PersonModel::create($configuration['person']);
     $this->assertEquals($person, $list->person);
 }
 public function testGetPerson()
 {
     $container = $responses = [];
     $responses[] = new Response(200, [], '1');
     $track_manager = $this->getTrackService($container, $responses);
     $person = PersonModel::create($this->personConfiguration);
     $this->assertTrue($track_manager->identify($person));
     $request = $container[0]['request'];
     $this->assertEquals('GET', $request->getMethod());
     $options = http_build_query(['data' => base64_encode(json_encode(['token' => $this->apiKey, 'properties' => $person]))]);
     $this->assertSame($options, $request->getUri()->getQuery());
 }
 public function testAddPersonToList()
 {
     $container = $responses = [];
     $responses[] = new Response(200, [], json_encode($this->responseAddListPerson));
     $list_manager = $this->getListService($container, $responses);
     $list = new ListModel($this->responseListZero);
     $person = PersonModel::create(['$first_name' => 'George', 'Birthday' => '02/22/1732', '$email' => '*****@*****.**']);
     $person_list = $list_manager->addPersonToList($list, $person);
     $this->assertTrue($person_list instanceof PersonListModel, 'The returned object should be an instance of PersonListModel.');
     $person_reference = PersonReferenceModel::create($this->responseAddListPerson['person']);
     $this->assertEquals($person_reference, $person_list->person);
     $list_reference = ListReferenceModel::create($this->responseAddListPerson['list']);
     $this->assertEquals($list_reference, $person_list->list);
     $this->assertTrue($person_list->alreadyMember);
     $request = $container[0]['request'];
     $this->assertSame('POST', $request->getMethod());
     $fields = [];
     parse_str(urldecode((string) $request->getBody()), $fields);
     $this->assertSame('*****@*****.**', $fields['email']);
     $this->assertEquals($person, PersonModel::createFromJson($fields['properties']));
     $this->assertTrue((bool) $fields['confirm_optin']);
 }
 /**
  * Retrieve a person from the Klaviyo API.
  *
  * @param string $id
  *   The id of the person that should be retrieved.
  *
  * @return PersonModel
  *   The person model object if it exists in Klaviyo.
  */
 public function getPerson($id)
 {
     $response = $this->api->request('GET', $this->getResourcePath("person/{$id}"));
     return PersonModel::createFromJson($response->getBody());
 }
 /**
  * @expectedException Klaviyo\Exception\InvalidSpecialAttributeKeyException
  */
 public function testInvalidGetModelPropertyFromSpecialAttributeKey()
 {
     PersonModel::getModelPropertyFromSpecialAttributeKey('$someAwesomeAttribute');
 }