4 * Class CRM_Extension_InfoTest
7 class CRM_Extension_InfoTest
extends CiviUnitTestCase
{
9 public function setUp() {
14 public function tearDown() {
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>");
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']);
31 public function testBad_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>");
38 $info = CRM_Extension_Info
::loadFromFile($this->file
);
40 catch (CRM_Extension_Exception
$e) {
43 $this->assertTrue(is_object($exc));
46 public function testGood_string() {
47 $data = "<extension key='test.foo' type='module'><file>foo</file><typeInfo><extra>zamboni</extra></typeInfo></extension>";
49 $info = CRM_Extension_Info
::loadFromString($data);
50 $this->assertEquals('test.foo', $info->key
);
51 $this->assertEquals('foo', $info->file
);
52 $this->assertEquals('zamboni', $info->typeInfo
['extra']);
53 $this->assertEquals([], $info->requires
);
56 public function testGood_string_extras() {
57 $data = "<extension key='test.bar' type='module'><file>testbar</file>
58 <classloader><psr4 prefix=\"Civi\\\" path=\"Civi\"/></classloader>
59 <requires><ext>org.civicrm.a</ext><ext>org.civicrm.b</ext></requires>
63 $info = CRM_Extension_Info
::loadFromString($data);
64 $this->assertEquals('test.bar', $info->key
);
65 $this->assertEquals('testbar', $info->file
);
66 $this->assertEquals('Civi\\', $info->classloader
[0]['prefix']);
67 $this->assertEquals('Civi', $info->classloader
[0]['path']);
68 $this->assertEquals(['org.civicrm.a', 'org.civicrm.b'], $info->requires
);
71 public function getExampleAuthors() {
72 $authorAliceXml = '<author><name>Alice</name><email>alice@example.org</email><role>Maintainer</role></author>';
73 $authorAliceArr = ['name' => 'Alice', 'email' => 'alice@example.org', 'role' => 'Maintainer'];
74 $authorBobXml = ' <author><name>Bob</name><homepage>https://example.com/bob</homepage><role>Developer</role></author>';
75 $authorBobArr = ['name' => 'Bob', 'homepage' => 'https://example.com/bob', 'role' => 'Developer'];
77 $maintAliceXml = '<maintainer><author>Alice</author><email>alice@example.org</email></maintainer>';
78 $maintAliceArr = ['author' => 'Alice', 'email' => 'alice@example.org'];
80 $hdr = "<extension key='test.author' type='module'><file>testauthor</file>";
81 $ftr = "</extension>";
83 // Maintainers can be inputted via either <maintainer> or <authors> (with role).
84 // Maintainers are outputted via both `$info->maintainer` and `$info->authors` (with role)
87 $cases[] = ["{$hdr}{$maintAliceXml}{$ftr}", [$authorAliceArr], $maintAliceArr];
88 $cases[] = ["{$hdr}<authors>{$authorAliceXml}</authors>{$ftr}", [$authorAliceArr], $maintAliceArr];
89 $cases[] = ["{$hdr}<authors>{$authorAliceXml}{$authorBobXml}</authors>{$ftr}", [$authorAliceArr, $authorBobArr], $maintAliceArr];
90 $cases[] = ["{$hdr}<authors>{$authorBobXml}</authors>{$ftr}", [$authorBobArr], NULL];
95 * @dataProvider getExampleAuthors
97 public function testAuthors($xmlString, $expectAuthors, $expectMaintainer) {
98 $info = CRM_Extension_Info
::loadFromString($xmlString);
99 $this->assertEquals($expectAuthors, $info->authors
);
100 $this->assertEquals($expectMaintainer, $info->maintainer
);
103 public function testBad_string() {
105 $data = "<extension key='test.foo' type='module'>file>foo</file></extension>";
109 $info = CRM_Extension_Info
::loadFromString($data);
111 catch (CRM_Extension_Exception
$e) {
114 $this->assertTrue(is_object($exc));
117 public function test_requirements() {
118 // Quicksearch requirement should get filtered out per extension-compatibility.json
119 $data = "<extension key='test.foo' type='module'><file>foo</file><requires><ext>example.test</ext><ext>com.ixiam.modules.quicksearch</ext></requires></extension>";
121 $info = CRM_Extension_Info
::loadFromString($data);
122 $this->assertEquals(['example.test'], $info->requires
);