-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathGraphTest.php
69 lines (61 loc) · 2.62 KB
/
GraphTest.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
<?php
require_once(__DIR__ . "/../inc/global.php");
require_once(__DIR__ . "/../layout/graphs.php");
require_once(__DIR__ . "/../graphs/types.php");
/**
* Tests related to graphs.
*/
class GraphTestsTest extends PHPUnit_Framework_TestCase {
function testDefaultExchangeTest() {
$this->assertEquals('BTC-e for LTC/FTC, Bitstamp for USD, CEX.io for GHS', get_default_exchange_text(array('ltc', 'ftc', 'usd', 'ghs')));
$this->assertEquals('BTC-e for LTC, Bitstamp for USD, CEX.io for GHS', get_default_exchange_text(array('ltc', 'usd', 'ghs')));
$this->assertEquals('BTC-e for LTC/FTC', get_default_exchange_text(array('ltc', 'ftc')));
$this->assertEquals('', get_default_exchange_text(array()));
}
/**
* Can probably remove this test when graphs are subclasses rather than
* associative arrays.
*/
function testAllGraphsHaveHeadings() {
// we need to login because private graphs require summary currencies
$_SESSION["user_id"] = 101;
$_SESSION["user_name"] = "Testing user";
$_SESSION["user_key"] = "testing-key";
global $global_user_logged_in;
$global_user_logged_in = true;
$graphs = graph_types();
foreach ($graphs as $key => $type) {
if (isset($type['category']) && $type['category']) {
$this->assertEmpty(isset($type['heading']), "Graph $key is a category and should not have a heading");
} else if (isset($type['subcategory']) && $type['subcategory']) {
$this->assertEmpty(isset($type['heading']), "Graph $key is a subcategory and should not have a heading");
} else {
$this->assertNotEmpty(isset($type['heading']), "Graph $key has no heading");
$this->assertNotEmpty($type['heading'], "Graph $key has an empty heading");
}
}
}
/**
* Currently the type of `graph_type` in the `graphs` database table
* is limited to varchar(32); we check that all defined graph types, that
* are not categories or subcategories, are within this limit.
*/
function testAllGraphsHaveShortNames() {
// we need to login because private graphs require summary currencies
$_SESSION["user_id"] = 101;
$_SESSION["user_name"] = "Testing user";
$_SESSION["user_key"] = "testing-key";
global $global_user_logged_in;
$global_user_logged_in = true;
$graphs = graph_types();
foreach ($graphs as $key => $type) {
if (isset($type['category']) && $type['category']) {
// ignore
} else if (isset($type['subcategory']) && $type['subcategory']) {
// ignore
} else {
$this->assertLessThan(32, strlen($key), "Graph key '$key' should be less than 32 characters long");
}
}
}
}