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