diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2015-07-03 03:54:27 +0300 |
---|---|---|
committer | sgiehl <stefan@piwik.org> | 2015-10-06 18:25:13 +0300 |
commit | 9ba8f216fd7856ce5fef06bf82ecb8f8a2e7e630 (patch) | |
tree | 6ce07d18a85d00b39ab720abe042361c0775aead /tests/PHPUnit/Unit/Report | |
parent | 8ccc9dc05da021325cdbf141a548637fa52f16b2 (diff) |
generate pages instead of implementing them in each controller
Diffstat (limited to 'tests/PHPUnit/Unit/Report')
-rw-r--r-- | tests/PHPUnit/Unit/Report/ReportWidgetConfigTest.php | 262 | ||||
-rw-r--r-- | tests/PHPUnit/Unit/Report/ReportWidgetFactoryTest.php | 112 |
2 files changed, 374 insertions, 0 deletions
diff --git a/tests/PHPUnit/Unit/Report/ReportWidgetConfigTest.php b/tests/PHPUnit/Unit/Report/ReportWidgetConfigTest.php new file mode 100644 index 0000000000..d1ac8d4021 --- /dev/null +++ b/tests/PHPUnit/Unit/Report/ReportWidgetConfigTest.php @@ -0,0 +1,262 @@ +<?php +/** + * 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\Unit\Report; + +use Piwik\Report\ReportWidgetConfig; + +/** + * @group Widget + * @group Report + * @group ReportWidgetConfig + * @group ReportWidgetConfigTest + */ +class ReportWidgetConfigTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var ReportWidgetConfig + */ + private $config; + + public function setUp() + { + parent::setUp(); + $this->config = new ReportWidgetConfig(); + } + + public function test_getViewDataTable_ByDefaultThereShouldBeNoDefaultView() + { + $this->assertNull($this->config->getViewDataTable()); + } + + public function test_setDefaultViewDataTable() + { + $this->config->setDefaultViewDataTable('table'); + + $this->assertSame('table', $this->config->getViewDataTable()); + $this->assertFalse($this->config->isViewDataTableForced()); + } + + public function test_forceViewDataTable() + { + $this->config->forceViewDataTable('table'); + + $this->assertSame('table', $this->config->getViewDataTable()); + $this->assertTrue($this->config->isViewDataTableForced()); + } + + public function test_name_set_get() + { + $this->config->setName('testName'); + + $this->assertSame('testName', $this->config->getName()); + } + + public function test_getName_shouldBeEmptyStringByDefault() + { + $this->assertSame('', $this->config->getName()); + } + + public function test_categoryId_set_get() + { + $this->config->setCategoryId('testCat'); + + $this->assertSame('testCat', $this->config->getCategoryId()); + } + + public function test_getCategoryId_shouldBeEmptyStringByDefault() + { + $this->assertSame('', $this->config->getCategoryId()); + } + + public function test_subcategoryId_set_get() + { + $this->config->setSubcategoryId('testsubcat'); + + $this->assertSame('testsubcat', $this->config->getSubcategoryId()); + } + + public function test_getSubcategoryId_shouldBeEmptyStringByDefault() + { + $this->assertSame('', $this->config->getSubcategoryId()); + } + + public function test_module_set_get() + { + $this->config->setModule('CoreHome'); + + $this->assertSame('CoreHome', $this->config->getModule()); + } + + public function test_getModule_shouldBeEmptyStringByDefault() + { + $this->assertSame('', $this->config->getModule()); + } + + public function test_action_set_get() + { + $this->config->setAction('get'); + + $this->assertSame('get', $this->config->getAction()); + } + + public function test_getAction_shouldBeEmptyStringByDefault() + { + $this->assertSame('', $this->config->getAction()); + } + + public function test_order_set_get() + { + $this->config->setOrder(99); + $this->assertSame(99, $this->config->getOrder()); + + $this->config->setOrder('98'); + $this->assertSame(98, $this->config->getOrder()); + } + + public function test_getOrder_shouldReturnADefaultValue() + { + $this->assertSame(99, $this->config->getOrder()); + } + + public function test_setMiddlewareParameters_set_get() + { + $this->config->setMiddlewareParameters(array( + 'module' => 'Goals', + 'action' => 'hasConversions' + )); + + $this->assertSame(array( + 'module' => 'Goals', + 'action' => 'hasConversions' + ), $this->config->getMiddlewareParameters()); + } + + public function test_getMiddlewareParameters_shouldReturnADefaultValue() + { + $this->assertSame(array(), $this->config->getMiddlewareParameters()); + } + + public function test_getParameters_ShouldAddModuleAndAction() + { + $this->setModuleAndAction(); + $this->assertSame(array('module' => 'CoreHome', 'action' => 'renderMe'), $this->config->getParameters()); + } + + public function test_getParameters_ShouldNotBePossibleToOverwriteModuleAndAction() + { + $this->setModuleAndAction(); + $this->config->setParameters(array('module' => 'Actions', 'action' => 'index')); + + $this->assertSame(array('module' => 'CoreHome', 'action' => 'renderMe'), $this->config->getParameters()); + } + + public function test_getParameters_ShouldReturnViewDataTableIfSet() + { + $this->setModuleAndAction(); + $this->config->setDefaultViewDataTable('graph'); + + $this->assertSame(array('viewDataTable' => 'graph', 'module' => 'CoreHome', 'action' => 'renderMe'), $this->config->getParameters()); + } + + public function test_getParameters_ShouldForceViewDataTableIfSet() + { + $this->setModuleAndAction(); + $this->config->forceViewDataTable('graph'); + + $this->assertSame(array('forceView' => '1', 'viewDataTable' => 'graph', 'module' => 'CoreHome', 'action' => 'renderMe'), $this->config->getParameters()); + } + + public function test_addParameters_ShouldAddMoreParams() + { + $this->setModuleAndAction(); + $this->config->addParameters(array('test' => '1')); // should be removed by setParameters + $this->config->addParameters(array('forceView' => '1')); + $this->config->addParameters(array('test' => '3')); + + $this->assertSame(array('module' => 'CoreHome', 'action' => 'renderMe', 'test' => '3', 'forceView' => '1'), $this->config->getParameters()); + } + + public function test_setParameters_ShouldOverwriteAnyExistingParameters() + { + $this->setModuleAndAction(); + $this->config->addParameters(array('test' => '1')); // should be removed by setParameters + $this->config->setParameters(array('forceView' => '1')); + + $this->assertSame(array('module' => 'CoreHome', 'action' => 'renderMe', 'forceView' => '1'), $this->config->getParameters()); + } + + public function test_shouldBeEnabledByDefault() + { + $this->assertTrue($this->config->isEnabled()); + } + + public function test_enable_disable() + { + $this->config->disable(); + $this->assertFalse($this->config->isEnabled()); + $this->config->enable(); + $this->assertTrue($this->config->isEnabled()); + } + + public function test_setIsEnabled() + { + $this->config->setIsEnabled(false); + $this->assertFalse($this->config->isEnabled()); + $this->config->setIsEnabled(true); + $this->assertTrue($this->config->isEnabled()); + } + + public function test_checkIsEnabled_shouldNotThrowException_IfEnabled() + { + $this->config->enable(); + $this->config->checkIsEnabled(); + } + + /** + * @expectedException \Exception + */ + public function test_checkIsEnabled_shouldThrowException_IfDisabled() + { + $this->config->disable(); + $this->config->checkIsEnabled(); + } + + public function test_shouldBeWidgetizable_ByDefault() + { + $this->assertTrue($this->config->isWidgetizeable()); + } + + public function test_widgetizeable() + { + $this->config->setIsNotWidgetizable(); + $this->assertFalse($this->config->isWidgetizeable()); + $this->config->setIsWidgetizable(); + $this->assertTrue($this->config->isWidgetizeable()); + } + + public function test_getUniqueId_withNoParameters() + { + $this->setModuleAndAction(); + $this->assertSame('widgetCoreHomerenderMe', $this->config->getUniqueId()); + } + + public function test_getUniqueId_withParameters() + { + $this->setModuleAndAction(); + $this->config->addParameters(array('viewDataTable' => 'table', 'forceView' => '1', 'mtest' => array('test'))); + $this->assertSame('widgetCoreHomerenderMeviewDataTabletableforceView1mtestArray', $this->config->getUniqueId()); + } + + private function setModuleAndAction() + { + $this->config->setModule('CoreHome'); + $this->config->setAction('renderMe'); + } + +} diff --git a/tests/PHPUnit/Unit/Report/ReportWidgetFactoryTest.php b/tests/PHPUnit/Unit/Report/ReportWidgetFactoryTest.php new file mode 100644 index 0000000000..2f49fee3cb --- /dev/null +++ b/tests/PHPUnit/Unit/Report/ReportWidgetFactoryTest.php @@ -0,0 +1,112 @@ +<?php +/** + * 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\Unit\Report; + +use Piwik\Plugin\Report; +use Piwik\Report\ReportWidgetConfig; +use Piwik\Report\ReportWidgetFactory; +use Piwik\Widget\WidgetConfig; +use Piwik\Widget\WidgetContainerConfig; + +class GetBasicReport extends Report +{ + protected function init() + { + parent::init(); + + $this->name = 'Report_MyCustomReportName'; + $this->order = 20; + $this->module = 'TestPlugin'; + $this->action = 'getBasicReport'; + $this->categoryId = 'Goals_Goals'; + $this->subcategoryId = 'General_Overview'; + $this->actionToLoadSubTables = 'invalidReport'; + $this->parameters = array('idGoal' => '1'); + } + + public function getDefaultTypeViewDataTable() + { + return 'graph'; + } +} + +/** + * @group Widget + * @group Report + * @group ReportWidgetFactory + * @group ReportWidgetFactoryTest + */ +class ReportWidgetFactoryTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var ReportWidgetFactory + */ + private $factory; + + public function setUp() + { + parent::setUp(); + + $this->factory = new ReportWidgetFactory(new GetBasicReport()); + } + + public function test_createContainerWidget_ShouldCreateAContainerBasedOnReportWithGivenId() + { + $config = $this->factory->createContainerWidget('myId'); + + $this->assertTrue($config instanceof WidgetContainerConfig); + $this->assertSame('myId', $config->getId()); + $this->assertSame('Goals_Goals', $config->getCategoryId()); + $this->assertSame('General_Overview', $config->getSubcategoryId()); + $this->assertSame(100 + 20, $config->getOrder()); + } + + public function test_createWidget_ShouldCreateAContainerBasedOnReportWithGivenId() + { + $config = $this->factory->createWidget(); + + $this->assertTrue($config instanceof ReportWidgetConfig); + $this->assertSame('Report_MyCustomReportName', $config->getName()); + $this->assertSame('Goals_Goals', $config->getCategoryId()); + $this->assertSame('General_Overview', $config->getSubcategoryId()); + $this->assertSame('graph', $config->getViewDataTable()); + $this->assertSame(100 + 20, $config->getOrder()); + $this->assertSame('TestPlugin', $config->getModule()); + $this->assertSame('getBasicReport', $config->getAction()); + + $this->assertSame(array( + 'viewDataTable' => 'graph', + 'module' => 'TestPlugin', + 'action' => 'getBasicReport', + 'idGoal' => '1' + ), $config->getParameters()); + } + + public function test_createCustomWidget_ShouldCreateAContainerBasedOnReportWithGivenId() + { + $config = $this->factory->createCustomWidget('customAction'); + + $this->assertTrue($config instanceof ReportWidgetConfig); + $this->assertSame('Report_MyCustomReportName', $config->getName()); + $this->assertSame('Goals_Goals', $config->getCategoryId()); + $this->assertSame('General_Overview', $config->getSubcategoryId()); + $this->assertNull($config->getViewDataTable()); + $this->assertSame(100 + 20, $config->getOrder()); + $this->assertSame('TestPlugin', $config->getModule()); + $this->assertSame('customAction', $config->getAction()); + + $this->assertSame(array( + 'module' => 'TestPlugin', + 'action' => 'customAction', + 'idGoal' => '1' + ), $config->getParameters()); + } + + +} |