/** * Execute the controller. * * @return boolean * * @since 1.0 */ public function execute() { // Check if we are allowed to receive the raw data $authorizedRaw = $this->getInput()->server->getString('HTTP_JOOMLA_RAW', 'fail') === $this->getApplication()->get('stats.rawdata', false); // Check if a single data source is requested $source = $this->getInput()->getString('source'); $this->view->isAuthorizedRaw($authorizedRaw); $this->view->setSource($source); $this->getApplication()->setBody($this->view->render()); return true; }
/** * @testdox An Exception is thrown if the requested data source does not exist * * @covers Stats\Views\Stats\StatsJsonView::render * @uses Stats\Views\Stats\StatsJsonView::setSource * @expectedException \InvalidArgumentException */ public function testAnExceptionIsThrownIfTheRequestedDataSourceDoesNotExist() { $mockModel = $this->getMockBuilder('Stats\\Models\\StatsModel')->disableOriginalConstructor()->getMock(); $mockModel->expects($this->once())->method('getItems')->willReturn([(object) ['unique_id' => '1a', 'php_version' => PHP_VERSION, 'cms_version' => '3.5.0', 'db_type' => 'mysql', 'db_version' => '5.6.25', 'server_os' => 'Darwin 14.1.0'], (object) ['unique_id' => '2b', 'php_version' => PHP_VERSION, 'cms_version' => '3.5.0', 'db_type' => 'postgresql', 'db_version' => '9.4.0', 'server_os' => 'Darwin 14.1.0']]); $view = new StatsJsonView($mockModel); $view->setSource('noway'); $view->render(); }