Skip to content

Commit a340698

Browse files
author
Phil E. Taylor
authored
Add unit test for ModuleAdapter::getElement (joomla#33260)
Signed-off-by: Phil E. Taylor <[email protected]>
1 parent d714e26 commit a340698

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
/**
3+
* @package Joomla.UnitTest
4+
* @subpackage Installer
5+
*
6+
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
*/
9+
10+
namespace Joomla\Tests\Unit\Libraries\Cms\Installer\Adapter;
11+
12+
use Joomla\CMS\Installer\Adapter\ModuleAdapter;
13+
use Joomla\Tests\Unit\UnitTestCase;
14+
15+
/**
16+
* ModuleAdapterTest
17+
*
18+
* @since __DEPLOY_VERSION__
19+
*/
20+
class ModuleAdapterTest extends UnitTestCase
21+
{
22+
/**
23+
* @var ModuleAdapter
24+
*
25+
* @since __DEPLOY_VERSION__
26+
*/
27+
protected $moduleAdapter;
28+
29+
/**
30+
* @return void
31+
* @since __DEPLOY_VERSION__
32+
*/
33+
protected function setUp():void
34+
{
35+
$this->moduleAdapter = $this->getMockBuilder(ModuleAdapter::class)
36+
->onlyMethods([])
37+
->disableOriginalConstructor()
38+
->getMock();
39+
40+
parent::setUp();
41+
}
42+
43+
/**
44+
* This method is called after a test is executed.
45+
*
46+
* @return void
47+
* @since __DEPLOY_VERSION__
48+
*/
49+
protected function tearDown():void
50+
{
51+
unset($this->moduleAdapter);
52+
53+
parent::tearDown();
54+
}
55+
56+
/**
57+
* @return void
58+
*
59+
* @since __DEPLOY_VERSION__
60+
*/
61+
public function testInit()
62+
{
63+
$this->assertInstanceOf(ModuleAdapter::class, $this->moduleAdapter);
64+
}
65+
66+
/**
67+
* Tests the legacy way of specifying the element in module XML
68+
*
69+
* @return void
70+
*
71+
* @since __DEPLOY_VERSION__
72+
*/
73+
public function testgetElement1()
74+
{
75+
$xml = simplexml_load_file(JPATH_ADMINISTRATOR . '/modules/mod_quickicon/mod_quickicon.xml');
76+
$this->moduleAdapter->setManifest($xml);
77+
78+
$this->assertNotNull($this->moduleAdapter->manifest);
79+
80+
$this->assertEquals('mod_quickicon', $this->moduleAdapter->getElement());
81+
$this->assertEquals('somethingElse', $this->moduleAdapter->getElement('somethingElse'));
82+
}
83+
84+
/**
85+
* Tests the legacy way of specifying the element in module XML
86+
*
87+
* @return void
88+
*
89+
* @since __DEPLOY_VERSION__
90+
*/
91+
public function testgetElement2()
92+
{
93+
$xml = simplexml_load_file(JPATH_ADMINISTRATOR . '/modules/mod_sampledata/mod_sampledata.xml');
94+
$this->moduleAdapter->setManifest($xml);
95+
96+
$this->assertNotNull($this->moduleAdapter->manifest);
97+
98+
$this->assertEquals('mod_sampledata', $this->moduleAdapter->getElement());
99+
$this->assertEquals('somethingElse', $this->moduleAdapter->getElement('somethingElse'));
100+
}
101+
102+
/**
103+
* Tests the new <element/> tag in Joomla 4 modules introduced in https://github.com/joomla/joomla-cms/pull/33182
104+
*
105+
* @return void
106+
*
107+
* @since __DEPLOY_VERSION__
108+
*/
109+
public function testgetElementFromElementTag()
110+
{
111+
$xml = file_get_contents(JPATH_ADMINISTRATOR . '/modules/mod_quickicon/mod_quickicon.xml');
112+
113+
// Insert a Joomla 4 <module/> tag
114+
$xml = str_replace('<name>mod_quickicon</name>', '<name>mod_quickicon</name><element>mod_quickicon</element>', $xml);
115+
116+
$xml = simplexml_load_string($xml);
117+
$this->moduleAdapter->setManifest($xml);
118+
119+
$this->assertNotNull($this->moduleAdapter->manifest);
120+
121+
$this->assertEquals('mod_quickicon', $this->moduleAdapter->getElement());
122+
$this->assertEquals('somethingElse', $this->moduleAdapter->getElement('somethingElse'));
123+
}
124+
}

0 commit comments

Comments
 (0)