phpcs - Fix error, "Visibility must be declared on method"
[civicrm-core.git] / tests / phpunit / CRM / Extension / InfoTest.php
1 <?php
2
3 require_once 'CiviTest/CiviUnitTestCase.php';
4
5 /**
6 * Class CRM_Extension_InfoTest
7 */
8 class CRM_Extension_InfoTest extends CiviUnitTestCase {
9 public function setUp() {
10 parent::setUp();
11 $this->file = NULL;
12 }
13
14 public function tearDown() {
15 if ($this->file) {
16 unlink($this->file);
17 }
18 parent::tearDown();
19 }
20
21 public function testGood_file() {
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
31 public function testBad_file() {
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
45 public function testGood_string() {
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
54 public function testBad_string() {
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 }