Skip to content

Commit

Permalink
Add JComponentHelper::isInstalled()
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Babker committed Sep 26, 2014
1 parent 8184494 commit 932b872
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion administrator/modules/mod_stats_admin/helper.php
Expand Up @@ -112,7 +112,7 @@ public static function getStats(&$params)
$i++;
}

if (JComponentHelper::isEnabled('com_weblinks'))
if (JComponentHelper::isInstalled('com_weblinks'))
{
$query->clear()
->select('COUNT(id) AS count_links')
Expand Down
21 changes: 21 additions & 0 deletions libraries/cms/component/helper.php
Expand Up @@ -77,6 +77,27 @@ public static function isEnabled($option)
return $result->enabled;
}

/**
* Checks if a component is installed
*
* @param string $option The component option.
*
* @return integer
*
* @since 3.4
*/
public static function isInstalled($option)
{
$db = JFactory::getDbo();

return (int) $db->setQuery(
$db->getQuery(true)
->select('COUNT(extension_id)')
->from('#__extensions')
->where('element = ' . $db->quote($option))
)->loadResult();
}

/**
* Gets the parameter object for the component
*
Expand Down
2 changes: 1 addition & 1 deletion modules/mod_stats/helper.php
Expand Up @@ -102,7 +102,7 @@ public static function &getList(&$params)
$i++;
}

if (JComponentHelper::isEnabled('com_weblinks'))
if (JComponentHelper::isInstalled('com_weblinks'))
{
$query->clear()
->select('COUNT(id) AS count_links')
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/suites/libraries/cms/component/JComponentHelperTest.php
Expand Up @@ -49,6 +49,7 @@ public function testGetComponent()
'com_content is extension ID 22'
);
}

/**
* Test JComponentHelper::isEnabled
*
Expand All @@ -63,6 +64,27 @@ public function testIsEnabled()
'com_content should be enabled'
);
}

/**
* Test JComponentHelper::isInstalled
*
* @return void
*
* @since 3.4
*/
public function testIsInstalled()
{
$this->assertTrue(
(bool) JComponentHelper::isInstalled('com_content'),
'com_content should be installed'
);

$this->assertFalse(
(bool) JComponentHelper::isInstalled('com_willneverhappen'),
'com_willneverhappen should not be enabled'
);
}

/**
* Test JComponentHelper::getParams
*
Expand Down

0 comments on commit 932b872

Please sign in to comment.