Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | ||
3 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
4 | ||
aba1cd8b EM |
5 | /** |
6 | * Class CRM_Extension_InfoTest | |
7 | */ | |
6a488035 | 8 | class CRM_Extension_InfoTest extends CiviUnitTestCase { |
00be9182 | 9 | public function setUp() { |
6a488035 TO |
10 | parent::setUp(); |
11 | $this->file = NULL; | |
12 | } | |
13 | ||
00be9182 | 14 | public function tearDown() { |
6a488035 TO |
15 | if ($this->file) { |
16 | unlink($this->file); | |
17 | } | |
18 | parent::tearDown(); | |
19 | } | |
20 | ||
00be9182 | 21 | public function testGood_file() { |
6a488035 TO |
22 | $this->file = tempnam(sys_get_temp_dir(), 'infoxml-'); |
23 | file_put_contents($this->file, "<extension key='test.foo' type='module'><file>foo</file><typeInfo><extra>zamboni</extra></typeInfo></extension>"); | |
24 | ||
25 | $info = CRM_Extension_Info::loadFromFile($this->file); | |
26 | $this->assertEquals('test.foo', $info->key); | |
27 | $this->assertEquals('foo', $info->file); | |
28 | $this->assertEquals('zamboni', $info->typeInfo['extra']); | |
29 | } | |
30 | ||
00be9182 | 31 | public function testBad_file() { |
6a488035 TO |
32 | // <file> vs file> |
33 | $this->file = tempnam(sys_get_temp_dir(), 'infoxml-'); | |
34 | file_put_contents($this->file, "<extension key='test.foo' type='module'>file>foo</file></extension>"); | |
35 | ||
36 | $exc = NULL; | |
37 | try { | |
38 | $info = CRM_Extension_Info::loadFromFile($this->file); | |
39 | } catch (CRM_Extension_Exception $e) { | |
40 | $exc = $e; | |
41 | } | |
42 | $this->assertTrue(is_object($exc)); | |
43 | } | |
44 | ||
00be9182 | 45 | public function testGood_string() { |
6a488035 TO |
46 | $data = "<extension key='test.foo' type='module'><file>foo</file><typeInfo><extra>zamboni</extra></typeInfo></extension>"; |
47 | ||
48 | $info = CRM_Extension_Info::loadFromString($data); | |
49 | $this->assertEquals('test.foo', $info->key); | |
50 | $this->assertEquals('foo', $info->file); | |
51 | $this->assertEquals('zamboni', $info->typeInfo['extra']); | |
52 | } | |
53 | ||
00be9182 | 54 | public function testBad_string() { |
6a488035 TO |
55 | // <file> vs file> |
56 | $data = "<extension key='test.foo' type='module'>file>foo</file></extension>"; | |
57 | ||
58 | $exc = NULL; | |
59 | try { | |
60 | $info = CRM_Extension_Info::loadFromString($data); | |
61 | } catch (CRM_Extension_Exception $e) { | |
62 | $exc = $e; | |
63 | } | |
64 | $this->assertTrue(is_object($exc)); | |
65 | } | |
66 | } |