|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace SmrTest\lib\DefaultGame; |
|
4
|
|
|
|
|
5
|
|
|
use DOMDocument; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
use Smr\TradeGood; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @covers Smr\TradeGood |
|
11
|
|
|
*/ |
|
12
|
|
|
class TradeGoodTest extends TestCase { |
|
13
|
|
|
|
|
14
|
|
|
private static bool $original_libxml_use_internal_errors; |
|
15
|
|
|
|
|
16
|
|
|
public static function setUpBeforeClass(): void { |
|
17
|
|
|
// Make sure cache is clear so we can cover the cache population code |
|
18
|
|
|
TradeGood::clearCache(); |
|
19
|
|
|
|
|
20
|
|
|
// Get the original libxml state so we can restore it later |
|
21
|
|
|
self::$original_libxml_use_internal_errors = libxml_use_internal_errors(true); |
|
22
|
|
|
libxml_clear_errors(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public static function tearDownAfterClass(): void { |
|
26
|
|
|
// Restore the original libxml state |
|
27
|
|
|
libxml_use_internal_errors(self::$original_libxml_use_internal_errors); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function test_getAllIDs(): void { |
|
31
|
|
|
$expected = [ |
|
32
|
|
|
GOODS_WOOD, |
|
33
|
|
|
GOODS_FOOD, |
|
34
|
|
|
GOODS_ORE, |
|
35
|
|
|
GOODS_PRECIOUS_METALS, |
|
36
|
|
|
GOODS_SLAVES, |
|
37
|
|
|
GOODS_TEXTILES, |
|
38
|
|
|
GOODS_MACHINERY, |
|
39
|
|
|
GOODS_CIRCUITRY, |
|
40
|
|
|
GOODS_WEAPONS, |
|
41
|
|
|
GOODS_COMPUTERS, |
|
42
|
|
|
GOODS_LUXURY_ITEMS, |
|
43
|
|
|
GOODS_NARCOTICS, |
|
44
|
|
|
]; |
|
45
|
|
|
self::assertSame($expected, TradeGood::getAllIDs()); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function test_get(): void { |
|
49
|
|
|
// Spot check one of the TradeGoods |
|
50
|
|
|
$expected = new TradeGood( |
|
51
|
|
|
id: GOODS_WEAPONS, |
|
52
|
|
|
name: 'Weapons', |
|
53
|
|
|
maxPortAmount: 5000, |
|
54
|
|
|
basePrice: 168, |
|
55
|
|
|
class: 2, |
|
56
|
|
|
alignRestriction: -115, |
|
57
|
|
|
); |
|
58
|
|
|
self::assertEquals($expected, TradeGood::get(GOODS_WEAPONS)); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function test_getImageHTML(): void { |
|
62
|
|
|
foreach (TradeGood::getAll() as $good) { |
|
63
|
|
|
// Test as both HTML and XML because they each catch different errors |
|
64
|
|
|
// (loadHTML can validate things like tags, but automatically fixes many |
|
65
|
|
|
// HTML syntax errors without reporting them; whereas loadXML is more |
|
66
|
|
|
// strict about syntax, but not all XML is also valid HTML). |
|
67
|
|
|
$html = $good->getImageHTML(); |
|
68
|
|
|
$dom = new DOMDocument(); |
|
69
|
|
|
$dom->loadHTML($html); |
|
70
|
|
|
$dom->loadXML($html); |
|
71
|
|
|
self::assertSame([], libxml_get_errors(), $good->name); |
|
72
|
|
|
// Clear errors for the next case |
|
73
|
|
|
libxml_clear_errors(); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|