Skip to content

Commit fdd13a5

Browse files
author
dcaunt
committed
Added unit tests for ResponseData
git-svn-id: http://android-market-license-verification.googlecode.com/svn/trunk@6 9bbedade-4383-ce3b-2565-04fab2f84983
1 parent e15bcf2 commit fdd13a5

File tree

3 files changed

+172
-0
lines changed

3 files changed

+172
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
<?php
2+
/**
3+
* LICENSE
4+
*
5+
* This source file is subject to the new BSD license that is bundled
6+
* with this package in the file LICENSE.
7+
* It is also available through the world-wide-web at this URL:
8+
* http://code.google.com/p/android-market-license-verification/source/browse/trunk/LICENSE
9+
*/
10+
11+
require_once 'AndroidMarket/Licensing/ResponseData.php';
12+
13+
class ResponseDataTest extends PHPUnit_Framework_TestCase
14+
{
15+
16+
/**
17+
* @expectedException AndroidMarket_Licensing_InvalidArgumentException
18+
* @dataProvider invalidArgumentTypeProvider
19+
*/
20+
public function testConstructorThrowsWithOtherThanString($data)
21+
{
22+
new AndroidMarket_Licensing_ResponseData($data);
23+
}
24+
25+
/**
26+
* @expectedException AndroidMarket_Licensing_InvalidArgumentException
27+
*/
28+
public function testConstructorThrowsWithInvalidString()
29+
{
30+
new AndroidMarket_Licensing_ResponseData('this|doesnt|have|six|fields');
31+
}
32+
33+
public function testConstructor()
34+
{
35+
$data = '0|1448316265|uk.co.davidcaunt.android.licensingtest|1|ANlOHQOP0LkZ7Y0/zy7PIkZ2Nh5B73SgoA==|1308692145367';
36+
try {
37+
$response = new AndroidMarket_Licensing_ResponseData($data);
38+
} catch (AndroidMarket_Licensing_InvalidArgumentException $e) {
39+
$this->fail();
40+
}
41+
return $response;
42+
}
43+
44+
/**
45+
*
46+
* @depends testConstructor
47+
*/
48+
public function testGetResponseCode(AndroidMarket_Licensing_ResponseData $response)
49+
{
50+
$this->assertInternalType('int', $response->getResponseCode());
51+
$this->assertEquals(0, $response->getResponseCode());
52+
}
53+
54+
/**
55+
*
56+
* @depends testConstructor
57+
*/
58+
public function testGetNonce(AndroidMarket_Licensing_ResponseData $response)
59+
{
60+
$this->assertInternalType('string', $response->getNonce());
61+
$this->assertEquals(1448316265, $response->getNonce());
62+
}
63+
64+
/**
65+
*
66+
* @depends testConstructor
67+
*/
68+
public function testGetPackageName(AndroidMarket_Licensing_ResponseData $response)
69+
{
70+
$this->assertInternalType('string', $response->getPackageName());
71+
$this->assertEquals('uk.co.davidcaunt.android.licensingtest', $response->getPackageName());
72+
}
73+
74+
/**
75+
*
76+
* @depends testConstructor
77+
*/
78+
public function testGetVersionCode(AndroidMarket_Licensing_ResponseData $response)
79+
{
80+
$this->assertInternalType('int', $response->getVersionCode());
81+
$this->assertEquals(1, $response->getVersionCode());
82+
}
83+
84+
/**
85+
*
86+
* @depends testConstructor
87+
*/
88+
public function testGetUserId(AndroidMarket_Licensing_ResponseData $response)
89+
{
90+
$this->assertInternalType('string', $response->getUserId());
91+
$this->assertEquals('ANlOHQOP0LkZ7Y0/zy7PIkZ2Nh5B73SgoA==', $response->getUserId());
92+
}
93+
94+
/**
95+
*
96+
* @depends testConstructor
97+
*/
98+
public function testGetTimestamp(AndroidMarket_Licensing_ResponseData $response)
99+
{
100+
$this->assertInternalType('float', $response->getTimestamp());
101+
$this->assertEquals(1308692145367, $response->getTimestamp());
102+
}
103+
104+
public function testLicensedResponseIsLicensed()
105+
{
106+
$data = '0|1448316265|uk.co.davidcaunt.android.licensingtest|1|ANlOHQOP0LkZ7Y0/zy7PIkZ2Nh5B73SgoA==|1308692145367';
107+
$response = new AndroidMarket_Licensing_ResponseData($data);
108+
109+
$this->assertTrue($response->isLicensed());
110+
}
111+
112+
public function testOldLicensedResponseIsLicensed()
113+
{
114+
$data = '2|1448316265|uk.co.davidcaunt.android.licensingtest|1|ANlOHQOP0LkZ7Y0/zy7PIkZ2Nh5B73SgoA==|1308692145367';
115+
$response = new AndroidMarket_Licensing_ResponseData($data);
116+
117+
$this->assertTrue($response->isLicensed());
118+
}
119+
120+
public function testUnlicensedResponseIsNotLicensed()
121+
{
122+
$data = '1|1448316265|uk.co.davidcaunt.android.licensingtest|1|ANlOHQOP0LkZ7Y0/zy7PIkZ2Nh5B73SgoA==|1308692145367';
123+
$response = new AndroidMarket_Licensing_ResponseData($data);
124+
125+
$this->assertFalse($response->isLicensed());
126+
}
127+
128+
/**
129+
* @dataProvider errorResponseCodeProvider
130+
*/
131+
public function testErroneousResponseIsNotLicensed($responseCode)
132+
{
133+
$data = $responseCode . '|1448316265|uk.co.davidcaunt.android.licensingtest|1|ANlOHQOP0LkZ7Y0/zy7PIkZ2Nh5B73SgoA==|1308692145367';
134+
$response = new AndroidMarket_Licensing_ResponseData($data);
135+
136+
$this->assertFalse($response->isLicensed());
137+
}
138+
139+
public function invalidArgumentTypeProvider()
140+
{
141+
return array(
142+
array(1),
143+
array(0),
144+
array(false),
145+
array(true),
146+
array(''),
147+
);
148+
}
149+
150+
public function errorResponseCodeProvider()
151+
{
152+
return array(
153+
array(3),
154+
array(4),
155+
array(5),
156+
array(101),
157+
array(102),
158+
array(103),
159+
);
160+
}
161+
}

tests/TestHelper.php

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
set_include_path(
4+
dirname(__FILE__)."/../library". PATH_SEPARATOR . get_include_path()
5+
);
6+

tests/phpunit.xml-dist

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" ?>
2+
<phpunit bootstrap="./TestHelper.php">
3+
<php>
4+
</php>
5+
</phpunit>

0 commit comments

Comments
 (0)