MixpanelEventsProducerTest.php
2 years ago
MixpanelGroupsProducerTest.php
2 years ago
MixpanelPeopleProducerTest.php
2 years ago
index.php
2 years ago
MixpanelGroupsProducerTest.php
95 lines
| 1 | <?php |
| 2 | if (!defined('ABSPATH')) exit; |
| 3 | class MixpanelGroupsProducerTest extends PHPUnit_Framework_TestCase { |
| 4 | protected $_instance = null; |
| 5 | protected function setUp() |
| 6 | { |
| 7 | parent::setUp(); |
| 8 | $this->_instance = new Producers_MixpanelGroups("token"); |
| 9 | } |
| 10 | protected function tearDown() |
| 11 | { |
| 12 | parent::tearDown(); |
| 13 | $this->_instance->reset(); |
| 14 | $this->_instance = null; |
| 15 | } |
| 16 | public function testSet() { |
| 17 | $this->_instance->set("company","Mixpanel", array("industry" => "tech")); |
| 18 | $queue = $this->_instance->getQueue(); |
| 19 | $msg = $queue[count($queue)-1]; |
| 20 | $this->assertEquals("company", $msg['$group_key']); |
| 21 | $this->assertEquals("Mixpanel", $msg['$group_id']); |
| 22 | $this->assertEquals("token", $msg['$token']); |
| 23 | $this->assertArrayNotHasKey('$ignore_time', $msg); |
| 24 | $this->assertArrayHasKey('$set', $msg); |
| 25 | $this->assertArrayHasKey("industry", $msg['$set']); |
| 26 | $this->assertEquals("tech", $msg['$set']['industry']); |
| 27 | } |
| 28 | public function testSetIgnoreTime() { |
| 29 | $this->_instance->set("company","Mixpanel", array("industry" => "Tech"), true); |
| 30 | $queue = $this->_instance->getQueue(); |
| 31 | $msg = $queue[count($queue)-1]; |
| 32 | $this->assertEquals("company", $msg['$group_key']); |
| 33 | $this->assertEquals("Mixpanel", $msg['$group_id']); |
| 34 | $this->assertEquals("token", $msg['$token']); |
| 35 | $this->assertEquals(true, $msg['$ignore_time']); |
| 36 | $this->assertArrayHasKey('$set', $msg); |
| 37 | $this->assertArrayHasKey("industry", $msg['$set']); |
| 38 | $this->assertEquals("Tech", $msg['$set']['industry']); |
| 39 | } |
| 40 | public function testSetOnce() { |
| 41 | $this->_instance->setOnce("company","Mixpanel", array("industry" => "Tech"), true); |
| 42 | $queue = $this->_instance->getQueue(); |
| 43 | $msg = $queue[count($queue)-1]; |
| 44 | $this->assertEquals("company", $msg['$group_key']); |
| 45 | $this->assertEquals("Mixpanel", $msg['$group_id']); |
| 46 | $this->assertEquals("token", $msg['$token']); |
| 47 | $this->assertArrayHasKey('$set_once', $msg); |
| 48 | $this->assertArrayHasKey("industry", $msg['$set_once']); |
| 49 | $this->assertEquals("Tech", $msg['$set_once']['industry']); |
| 50 | } |
| 51 | public function testUnionSingle() { |
| 52 | $this->_instance->union("company","Mixpanel", "actions", "Logged In"); |
| 53 | $queue = $this->_instance->getQueue(); |
| 54 | $msg = $queue[count($queue)-1]; |
| 55 | $this->assertEquals("company", $msg['$group_key']); |
| 56 | $this->assertEquals("Mixpanel", $msg['$group_id']); |
| 57 | $this->assertArrayHasKey('$union', $msg); |
| 58 | $this->assertArrayHasKey("actions", $msg['$union']); |
| 59 | $this->assertEquals("Logged In", $msg['$union']['actions']); |
| 60 | } |
| 61 | public function testUnionMultiple() { |
| 62 | $this->_instance->union("company","Mixpanel", "actions", array("Logged In", "Logged Out")); |
| 63 | $queue = $this->_instance->getQueue(); |
| 64 | $msg = $queue[count($queue)-1]; |
| 65 | $this->assertEquals("company", $msg['$group_key']); |
| 66 | $this->assertEquals("Mixpanel", $msg['$group_id']); |
| 67 | $this->assertEquals("token", $msg['$token']); |
| 68 | $this->assertArrayHasKey('$union', $msg); |
| 69 | $this->assertArrayHasKey("actions", $msg['$union']); |
| 70 | $this->assertEquals(array("Logged In", "Logged Out"), $msg['$union']['actions']); |
| 71 | } |
| 72 | public function testRemove() { |
| 73 | $this->_instance->remove("company","Mixpanel", array("industry" => "tech")); |
| 74 | $queue = $this->_instance->getQueue(); |
| 75 | $msg = $queue[count($queue)-1]; |
| 76 | $this->assertEquals("company", $msg['$group_key']); |
| 77 | $this->assertEquals("Mixpanel", $msg['$group_id']); |
| 78 | $this->assertEquals("token", $msg['$token']); |
| 79 | $this->assertArrayNotHasKey('$ignore_time', $msg); |
| 80 | $this->assertArrayHasKey('$unset', $msg); |
| 81 | $this->assertArrayHasKey("industry", $msg['$unset']); |
| 82 | $this->assertEquals("tech", $msg['$unset']['industry']); |
| 83 | } |
| 84 | public function testDeleteGroup() { |
| 85 | $this->_instance->deleteGroup("company","Mixpanel"); |
| 86 | $queue = $this->_instance->getQueue(); |
| 87 | $msg = $queue[count($queue)-1]; |
| 88 | $this->assertEquals("company", $msg['$group_key']); |
| 89 | $this->assertEquals("Mixpanel", $msg['$group_id']); |
| 90 | $this->assertEquals("token", $msg['$token']); |
| 91 | $this->assertArrayHasKey('$delete', $msg); |
| 92 | $this->assertEquals("", $msg['$delete']); |
| 93 | } |
| 94 | } |
| 95 |