Newer
Older
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tests\Integration;
mattab
a validé
use Piwik\Plugins\Goals\API;
use Piwik\Tests\Framework\Mock\FakeAccess;
use Piwik\Translate;
use Piwik\WidgetsList;
Thomas Steur
a validé
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
Thomas Steur
a validé
/**
* @group Core
*/
Thomas Steur
a validé
class Core_WidgetsListTest extends IntegrationTestCase
{
public function testGet()
{
// setup the access layer
$pseudoMockAccess = new FakeAccess;
FakeAccess::$superUser = true;
Access::setSingletonInstance($pseudoMockAccess);
$_GET['idSite'] = 1;
WidgetsList::_reset();
$widgets = WidgetsList::get();
WidgetsList::_reset();
// check if each category has the right number of widgets
$numberOfWidgets = array(
'VisitsSummary_VisitsSummary' => 6,
'General_Visitors' => 12,
'Actions_SubmenuSitesearch' => 5,
'Goals_Goals' => 1,
'Example Widgets' => 4,
'DevicesDetection_DevicesDetection' => 8,
// number of main categories
$this->assertEquals(count($numberOfWidgets), count($widgets));
foreach ($numberOfWidgets as $category => $widgetCount) {
$this->assertEquals($widgetCount, count($widgets[$category]), sprintf("Widget: %s", $category));
}
}
public function testGetWithGoals()
{
// setup the access layer
$pseudoMockAccess = new FakeAccess;
FakeAccess::$superUser = true;
Access::setSingletonInstance($pseudoMockAccess);
mattab
a validé
API::getInstance()->addGoal(1, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 1);
$_GET['idSite'] = 1;
WidgetsList::_reset();
$widgets = WidgetsList::get();
WidgetsList::_reset();
// check that the goal widget was added
$numberOfWidgets = array(
'Goals_Goals' => 2,
foreach ($numberOfWidgets as $category => $widgetCount) {
$this->assertEquals($widgetCount, count($widgets[$category]));
}
}
public function testGetWithGoalsAndEcommerce()
{
// setup the access layer
$pseudoMockAccess = new FakeAccess;
FakeAccess::$superUser = true;
Access::setSingletonInstance($pseudoMockAccess);
Fixture::createWebsite('2009-01-04 00:11:42', true);
mattab
a validé
API::getInstance()->addGoal(1, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 1);
$_GET['idSite'] = 1;
WidgetsList::_reset();
$widgets = WidgetsList::get();
WidgetsList::_reset();
// check if each category has the right number of widgets
$numberOfWidgets = array(
'Goals_Goals' => 2,
'Goals_Ecommerce' => 5,
foreach ($numberOfWidgets as $category => $widgetCount) {
$this->assertEquals($widgetCount, count($widgets[$category]));
}
}
public function testRemove()
{
// setup the access layer
$pseudoMockAccess = new FakeAccess;
FakeAccess::$superUser = true;
Access::setSingletonInstance($pseudoMockAccess);
Fixture::createWebsite('2009-01-04 00:11:42', true);
API::getInstance()->addGoal(1, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 1);
$_GET['idSite'] = 1;
WidgetsList::_reset();
$widgets = WidgetsList::get();
WidgetsList::remove('SEO', 'NoTeXiStInG');
$widgets = WidgetsList::get();
$this->assertArrayHasKey('SEO', $widgets);
$this->assertCount(2, $widgets['SEO']);
WidgetsList::remove('SEO', 'SEO_SeoRankings');
$widgets = WidgetsList::get();
$this->assertCount(1, $widgets['SEO']);
WidgetsList::remove('SEO');
$widgets = WidgetsList::get();
$this->assertArrayNotHasKey('SEO', $widgets);
WidgetsList::_reset();
}
public function testIsDefined()
{
// setup the access layer
$pseudoMockAccess = new FakeAccess;
FakeAccess::$superUser = true;
Access::setSingletonInstance($pseudoMockAccess);
Translate::loadEnglishTranslation();
Fixture::createWebsite('2009-01-04 00:11:42', true);
$_GET['idSite'] = 1;
WidgetsList::_reset();
WidgetsList::add('Actions', 'Pages', 'Actions', 'getPageUrls');
$this->assertTrue(WidgetsList::isDefined('Actions', 'getPageUrls'));
$this->assertFalse(WidgetsList::isDefined('Actions', 'inValiD'));
}