Skip to content
Extraits de code Groupes Projets
WidgetsListTest.php 5,37 ko
Newer Older
  • Learn to ignore specific revisions
  •  * 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;
    
    
    use Piwik\Widget\WidgetConfig;
    
    use Piwik\Tests\Framework\Mock\FakeAccess;
    use Piwik\Translate;
    
    use Piwik\Widget\WidgetsList;
    
    use Piwik\Tests\Framework\Fixture;
    use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
    
    class WidgetsListTest extends IntegrationTestCase
    
            FakeAccess::$superUser = true;
    
            Fixture::createWebsite('2009-01-04 00:11:42');
    
    
            $widgetsPerCategory = $this->getWidgetsPerCategory($widgets);
    
    
            // check if each category has the right number of widgets
            $numberOfWidgets = array(
    
                'Dashboard_Dashboard' => 1,
                'General_Actions' => 15,
    
    Thomas Steur's avatar
    Thomas Steur a validé
                'General_Visitors' => 35,
    
                'SEO' => 2,
                'Goals_Goals' => 3,
                'Live!' => 2,
                'Insights_WidgetCategory' => 2,
                'ExampleUI_UiFramework' => 8,
                'Referrers_Referrers' => 9,
    
    mattab's avatar
    mattab a validé
            // number of main categories
    
            $this->assertEquals(count($numberOfWidgets), count($widgetsPerCategory));
    
    mattab's avatar
    mattab a validé
    
    
            foreach ($numberOfWidgets as $category => $widgetCount) {
    
                $this->assertEquals($widgetCount, count($widgetsPerCategory[$category]), sprintf("Widget: %s", $category));
    
        private function getWidgetsPerCategory(WidgetsList $list)
    
            $widgetsPerCategory = array();
            foreach ($list->getWidgetConfigs() as $widgetConfig) {
                $category = $widgetConfig->getCategoryId();
                if (!isset($widgetsPerCategory[$category])) {
                    $widgetsPerCategory[$category] = array();
                }
    
                $widgetsPerCategory[$category][] = $widgetConfig;
            }
    
            return $widgetsPerCategory;
        }
    
        public function testGetWithGoals()
        {
    
            Fixture::createWebsite('2009-01-04 00:11:42');
    
            $perCategory = $this->getWidgetsPerCategory(WidgetsList::get());
            $this->assertEquals($initialGoalsWidgets, count($perCategory['Goals_Goals']));
    
            API::getInstance()->addGoal(1, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 1);
    
            $perCategory = $this->getWidgetsPerCategory(WidgetsList::get());
    
            // number of main categories
            $this->assertEquals(10, count($perCategory));
            $this->assertEquals($initialGoalsWidgets + 2, count($perCategory['Goals_Goals'])); // make sure widgets for that goal were added
    
        }
    
        public function testGetWithGoalsAndEcommerce()
        {
    
            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);
    
            $perCategory = $this->getWidgetsPerCategory(WidgetsList::get());
    
    mattab's avatar
    mattab a validé
            // number of main categories
    
            $this->assertEquals(11, count($perCategory));
    
    
            // check if each category has the right number of widgets
            $numberOfWidgets = array(
    
                'Goals_Goals'     => 5,
                'Goals_Ecommerce' => 4,
    
            foreach ($numberOfWidgets as $category => $widgetCount) {
    
                $this->assertEquals($widgetCount, count($perCategory[$category]));
    
    sgiehl's avatar
    sgiehl a validé
        public function testRemove()
        {
    
            Fixture::createWebsite('2009-01-04 00:11:42', true);
    
    sgiehl's avatar
    sgiehl a validé
            API::getInstance()->addGoal(1, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 1);
    
            $_GET['idSite'] = 1;
    
    
    sgiehl's avatar
    sgiehl a validé
    
    
            $this->assertCount(11, $this->getWidgetsPerCategory($list));
    
    sgiehl's avatar
    sgiehl a validé
    
    
            $list->remove('SEO', 'NoTeXiStInG');
    
    sgiehl's avatar
    sgiehl a validé
    
    
            $perCategory = $this->getWidgetsPerCategory($list);
            $this->assertCount(11, $perCategory);
    
    sgiehl's avatar
    sgiehl a validé
    
    
            $this->assertArrayHasKey('SEO', $perCategory);
            $this->assertCount(2, $perCategory['SEO']);
    
    sgiehl's avatar
    sgiehl a validé
    
    
            $list->remove('SEO', 'SEO_SeoRankings');
    
    mattab's avatar
    mattab a validé
    
    
            $perCategory = $this->getWidgetsPerCategory($list);
            $this->assertCount(1, $perCategory['SEO']);
    
    sgiehl's avatar
    sgiehl a validé
    
    
    sgiehl's avatar
    sgiehl a validé
    
    
            $perCategory = $this->getWidgetsPerCategory($list);
            $this->assertArrayNotHasKey('SEO', $perCategory);
    
    sgiehl's avatar
    sgiehl a validé
        }
    
        public function testIsDefined()
        {
    
            Translate::loadAllTranslations();
    
    sgiehl's avatar
    sgiehl a validé
    
    
            Fixture::createWebsite('2009-01-04 00:11:42', true);
    
    sgiehl's avatar
    sgiehl a validé
    
            $_GET['idSite'] = 1;
    
    
            $config = new WidgetConfig();
            $config->setCategoryId('Actions');
            $config->setName('Pages');
            $config->setModule('Actions');
            $config->setAction('getPageUrls');
            $list = WidgetsList::get();
            $list->addWidgetConfig($config);
    
    sgiehl's avatar
    sgiehl a validé
    
    
            $this->assertTrue($list->isDefined('Actions', 'getPageUrls'));
            $this->assertFalse($list->isDefined('Actions', 'inValiD'));
    
    
            Translate::reset();
    
    sgiehl's avatar
    sgiehl a validé
        }
    
    
        public function provideContainerConfig()
        {
            return array(
                'Piwik\Access' => new FakeAccess()
            );
        }