forked from parse-community/parse-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathParseAnalyticsTest.php
More file actions
79 lines (67 loc) · 1.91 KB
/
Copy pathParseAnalyticsTest.php
File metadata and controls
79 lines (67 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
use Parse\ParseClient;
use Parse\ParseAnalytics;
require_once 'ParseTestHelper.php';
class ParseAnalyticsTest extends PHPUnit_Framework_TestCase
{
public static function setUpBeforeClass()
{
ParseTestHelper::setUp();
}
public function tearDown()
{
ParseTestHelper::tearDown();
}
public function assertAnalyticsValidation($event, $params, $expectedJSON)
{
// We'll test that the event encodes properly, and that the analytics call
// doesn't throw an exception.
$json = ParseAnalytics::_toSaveJSON($params ?: array());
$this->assertEquals($expectedJSON, $json);
ParseAnalytics::track($event, $params ?: array());
}
public function testTrackEvent()
{
$expected = '{"dimensions":{}}';
$this->assertAnalyticsValidation('testTrackEvent', null, $expected);
}
public function testFailsOnEventName1()
{
$this->setExpectedException(
'Exception', 'A name for the custom event must be provided.'
);
ParseAnalytics::track('');
}
public function testFailsOnEventName2()
{
$this->setExpectedException(
'Exception', 'A name for the custom event must be provided.'
);
ParseAnalytics::track(' ');
}
public function testFailsOnEventName3()
{
$this->setExpectedException(
'Exception', 'A name for the custom event must be provided.'
);
ParseAnalytics::track(" \n");
}
public function testTrackEventDimensions()
{
$expected = '{"dimensions":{"foo":"bar","bar":"baz"}}';
$params = array(
'foo' => 'bar',
'bar' => 'baz'
);
$this->assertAnalyticsValidation('testDimensions', $params, $expected);
$date = date(DATE_RFC3339);
$expected = '{"dimensions":{"foo":"bar","bar":"baz","someDate":"' .
$date . '"}}';
$params = array(
'foo' => 'bar',
'bar' => 'baz',
'someDate' => $date
);
$this->assertAnalyticsValidation('testDate', $params, $expected);
}
}