file = NULL;
}
public function tearDown(): void {
if ($this->file) {
unlink($this->file);
}
parent::tearDown();
}
public function testGood_file() {
$this->file = tempnam(sys_get_temp_dir(), 'infoxml-');
file_put_contents($this->file, "foozamboni");
$info = CRM_Extension_Info::loadFromFile($this->file);
$this->assertEquals('test.foo', $info->key);
$this->assertEquals('foo', $info->file);
$this->assertEquals('zamboni', $info->typeInfo['extra']);
}
public function testBad_file() {
// vs file>
$this->file = tempnam(sys_get_temp_dir(), 'infoxml-');
file_put_contents($this->file, "file>foo");
$exc = NULL;
try {
$info = CRM_Extension_Info::loadFromFile($this->file);
}
catch (CRM_Extension_Exception $e) {
$exc = $e;
}
$this->assertTrue(is_object($exc));
}
public function testGood_string() {
$data = "foozamboni";
$info = CRM_Extension_Info::loadFromString($data);
$this->assertEquals('test.foo', $info->key);
$this->assertEquals('foo', $info->file);
$this->assertEquals('zamboni', $info->typeInfo['extra']);
$this->assertEquals([], $info->requires);
}
public function testGood_string_extras() {
$data = "testbar
org.civicrm.aorg.civicrm.b
";
$info = CRM_Extension_Info::loadFromString($data);
$this->assertEquals('test.bar', $info->key);
$this->assertEquals('testbar', $info->file);
$this->assertEquals('Civi\\', $info->classloader[0]['prefix']);
$this->assertEquals('Civi', $info->classloader[0]['path']);
$this->assertEquals(['org.civicrm.a', 'org.civicrm.b'], $info->requires);
}
public function getExampleAuthors() {
$authorAliceXml = 'Alicealice@example.orgMaintainer';
$authorAliceArr = ['name' => 'Alice', 'email' => 'alice@example.org', 'role' => 'Maintainer'];
$authorBobXml = ' Bobhttps://example.com/bobDeveloper';
$authorBobArr = ['name' => 'Bob', 'homepage' => 'https://example.com/bob', 'role' => 'Developer'];
$maintAliceXml = 'Alicealice@example.org';
$maintAliceArr = ['author' => 'Alice', 'email' => 'alice@example.org'];
$hdr = "testauthor";
$ftr = "";
// Maintainers can be inputted via either or (with role).
// Maintainers are outputted via both `$info->maintainer` and `$info->authors` (with role)
$cases = [];
$cases[] = ["{$hdr}{$maintAliceXml}{$ftr}", [$authorAliceArr], $maintAliceArr];
$cases[] = ["{$hdr}{$authorAliceXml}{$ftr}", [$authorAliceArr], $maintAliceArr];
$cases[] = ["{$hdr}{$authorAliceXml}{$authorBobXml}{$ftr}", [$authorAliceArr, $authorBobArr], $maintAliceArr];
$cases[] = ["{$hdr}{$authorBobXml}{$ftr}", [$authorBobArr], NULL];
return $cases;
}
/**
* @dataProvider getExampleAuthors
*/
public function testAuthors($xmlString, $expectAuthors, $expectMaintainer) {
$info = CRM_Extension_Info::loadFromString($xmlString);
$this->assertEquals($expectAuthors, $info->authors);
$this->assertEquals($expectMaintainer, $info->maintainer);
}
public function testBad_string() {
// vs file>
$data = "file>foo";
$exc = NULL;
try {
$info = CRM_Extension_Info::loadFromString($data);
}
catch (CRM_Extension_Exception $e) {
$exc = $e;
}
$this->assertTrue(is_object($exc));
}
public function test_requirements() {
// Quicksearch requirement should get filtered out per extension-compatibility.json
$data = "fooexample.testcom.ixiam.modules.quicksearch";
$info = CRM_Extension_Info::loadFromString($data);
$this->assertEquals(['example.test'], $info->requires);
}
}