forked from SteamDatabase/SteamLinux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.test.php
More file actions
80 lines (65 loc) · 2.35 KB
/
.test.php
File metadata and controls
80 lines (65 loc) · 2.35 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
80
<?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;
}
/**
* @depends testFileNotEmpty
*/
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 === 'CommentURL' )
{
$this->assertTrue( array_key_exists( 'Comment', $keys ), 'CommentURL key cant be without Comment key in "' . $appID . '"' );
}
else if( $key === 'Hidden' )
{
$this->assertFalse( array_key_exists( 'Working', $keys ), 'Working key cant be used along with Hidden key in "' . $appID . '"' );
$this->assertFalse( array_key_exists( 'Beta', $keys ), 'Beta key cant 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' );
}
}
}
return $games;
}
/**
* @depends testJSON
*/
public function testSorting( $games )
{
$gamesOriginal = $games;
ksort( $games );
$this->assertTrue( $gamesOriginal === $games, 'File must be sorted correctly by appid' );
}
}