forked from SteamDatabase/SteamLinux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.test.php
98 lines (81 loc) · 3.02 KB
/
.test.php
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
class SteamLinuxTest extends PHPUnit_Framework_TestCase
{
public function testFileExists( )
{
// Trying to get dataProvider to work with depends in phpunit requires some serious magic
$filePath = __DIR__ . DIRECTORY_SEPARATOR . 'GAMES.json';
$this->assertFileExists( $filePath );
return $filePath;
}
/**
* @depends testFileExists
*/
public function testFileNotEmpty( $filePath )
{
$games = file_get_contents( $filePath );
$this->assertNotEmpty( $games );
return $games;
}
/**
* We're sadistic bastards that only allow tabs
*
* @depends testFileNotEmpty
*/
public function testWhitespace( $games )
{
$this->assertNotRegExp( '/^ +/m', $games, 'Spaces used, we only allow tabs' );
$this->assertNotRegExp( '/^\t+ +/m', $games, 'Tabs mixed with spaces, we only allow tabs' );
return $games;
}
/**
* @depends testWhitespace
*/
public function testJSON( $games )
{
$games = json_decode( $games, true );
$this->assertTrue( json_last_error() === JSON_ERROR_NONE, 'JSON Error: ' . json_last_error_msg() );
$allowedKeys = Array(
'Working' => 'is_bool',
'Hidden' => 'is_bool',
'Beta' => 'is_bool',
'Comment' => 'is_string',
'CommentURL' => 'is_string'
);
foreach( $games as $appID => $keys )
{
$this->assertTrue( is_numeric( $appID ), 'Key "' . $appID . '" must be numeric' );
$this->assertTrue( is_array( $keys ), 'Value of "' . $appID . '" must be an array' );
foreach( $keys as $key => $value )
{
$this->assertArrayHasKey( $key, $allowedKeys, 'Invalid key "' . $key . '" in "' . $appID . '"' );
$this->assertTrue( $allowedKeys[ $key ]( $value ), '"' . $key . '" in "' . $appID . '" is not "' . $allowedKeys[ $key ] . '"' );
if( $key === 'Working' || $key === 'Beta' )
{
$this->assertFalse( array_key_exists( 'Hidden', $keys ), 'Hidden key cant be used along with ' . $key . ' key in "' . $appID . '"' );
$this->assertTrue( $value, $key . ' key in "' . $appID . '" can only be set to true because we only list working games' );
}
else if( $key === 'Hidden' )
{
$this->assertFalse( array_key_exists( 'Working', $keys ), 'Working key can not be used along with Hidden key in "' . $appID . '"' );
$this->assertFalse( array_key_exists( 'Beta', $keys ), 'Beta key can not be used along with Hidden key in "' . $appID . '"' );
$this->assertTrue( array_key_exists( 'Comment', $keys ), 'Hidden app "' . $appID . '" must contain a Comment explaining why it was hidden' );
}
else if( $key === 'CommentURL' )
{
$this->assertTrue( array_key_exists( 'Comment', $keys ), 'CommentURL key cant be without Comment key in "' . $appID . '"' );
}
}
}
return $games;
}
/**
* @depends testJSON
*/
public function testSorting( $games )
{
$gamesOriginal = $games;
ksort( $games );
$this->assertTrue( $gamesOriginal === $games, 'File must be sorted correctly by appid' );
}
}