public static function tearDownAfterClass() { ExportModule::$asynchronousThreshold = self::$asynchronousThreshold; parent::tearDownAfterClass(); }
/** * @depends testCreateActionForRowsAndColumns */ public function testExportAction() { $notificationsBeforeCount = Notification::getCount(); $notificationMessagesBeforeCount = NotificationMessage::getCount(); $savedReports = SavedReport::getAll(); $this->assertEquals(2, count($savedReports)); $this->setGetArray(array('id' => $savedReports[0]->id)); //Test where there is no data to export $this->runControllerWithRedirectExceptionAndGetContent('reports/default/export'); $this->assertContains('There is no data to export.', Yii::app()->user->getFlash('notification')); $reportModelTestItem = new ReportModelTestItem(); $reportModelTestItem->string = 'string1'; $reportModelTestItem->lastName = 'xLast1'; $this->assertTrue($reportModelTestItem->save()); $reportModelTestItem = new ReportModelTestItem(); $reportModelTestItem->string = 'string2'; $reportModelTestItem->lastName = 'xLast2'; $this->assertTrue($reportModelTestItem->save()); $content = $this->runControllerWithExitExceptionAndGetContent('reports/default/export'); $this->assertEquals('Testing download.', $content); ExportModule::$asynchronousThreshold = 1; $this->runControllerWithRedirectExceptionAndGetUrl('reports/default/export'); // Start background job $job = new ExportJob(); $this->assertTrue($job->run()); $exportItems = ExportItem::getAll(); $this->assertEquals(1, count($exportItems)); $fileModel = $exportItems[0]->exportFileModel; $this->assertEquals(1, $exportItems[0]->isCompleted); $this->assertEquals('csv', $exportItems[0]->exportFileType); $this->assertEquals('reports', $exportItems[0]->exportFileName); $this->assertTrue($fileModel instanceof ExportFileModel); $this->assertEquals($notificationsBeforeCount + 1, Notification::getCount()); $this->assertEquals($notificationMessagesBeforeCount + 1, NotificationMessage::getCount()); }
/** * @depends testExportByModelIds */ public function testExportReportWithMultiplePagesOfData() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $numberOfUserNotifications = Notification::getCountByTypeAndUser('ExportProcessCompleted', Yii::app()->user->userModel); $report = new Report(); $report->setType(Report::TYPE_ROWS_AND_COLUMNS); $report->setModuleClassName('AccountsModule'); $report->setFiltersStructure(''); $displayAttribute = new DisplayAttributeForReportForm('AccountsModule', 'Account', Report::TYPE_ROWS_AND_COLUMNS); $displayAttribute->setModelAliasUsingTableAliasName('model1'); $displayAttribute->attributeIndexOrDerivedType = 'name'; $report->addDisplayAttribute($displayAttribute); $dataProvider = new RowsAndColumnsReportDataProvider($report); $exportItem = new ExportItem(); $exportItem->isCompleted = 0; $exportItem->exportFileType = 'csv'; $exportItem->exportFileName = 'rowAndColumnsTest2'; $exportItem->modelClassName = 'SavedReport'; $exportItem->serializedData = ExportUtil::getSerializedDataForExport($dataProvider); $this->assertTrue($exportItem->save()); $id = $exportItem->id; $exportItem->forget(); unset($exportItem); //Delete queued jobs from test exportItems created above Yii::app()->jobQueue->deleteAll(); ExportModule::$asynchronousPageSize = 2; $job = new ExportJob(); $this->assertEquals(0, count(Yii::app()->jobQueue->getAll())); $this->assertTrue($job->run()); $this->assertEquals(0, count(Yii::app()->jobQueue->getAll())); $exportItem = ExportItem::getById($id); $fileModel = $exportItem->exportFileModel; $this->assertEquals(1, $exportItem->isCompleted); $this->assertEquals(0, $exportItem->processOffset); $this->assertEquals('csv', $exportItem->exportFileType); $this->assertEquals('rowAndColumnsTest2', $exportItem->exportFileName); $this->assertTrue($fileModel instanceof ExportFileModel); $accounts = Account::getAll(); $headerData = array('Name'); $data = array(); foreach ($accounts as $account) { $data[] = array($account->name); } $output = ExportItemToCsvFileUtil::export($data, $headerData, 'rowAndColumnsTest2.csv', false); $this->assertEquals($output, $fileModel->fileContent->content); // Check if user got notification message, and if its type is ExportProcessCompleted $this->assertEquals($numberOfUserNotifications + 1, Notification::getCountByTypeAndUser('ExportProcessCompleted', Yii::app()->user->userModel)); //Matrix report should not paginate $report = new Report(); $report->setType(Report::TYPE_MATRIX); $report->setModuleClassName('AccountsModule'); $report->setFiltersStructure(''); $displayAttribute = new DisplayAttributeForReportForm('AccountsModule', 'Account', Report::TYPE_MATRIX); $displayAttribute->setModelAliasUsingTableAliasName('model1'); $displayAttribute->attributeIndexOrDerivedType = 'Count'; $report->addDisplayAttribute($displayAttribute); $groupBy = new GroupByForReportForm('AccountsModule', 'Account', Report::TYPE_MATRIX); $groupBy->attributeIndexOrDerivedType = 'name'; $groupBy->axis = 'y'; $report->addGroupBy($groupBy); $groupBy = new GroupByForReportForm('AccountsModule', 'Account', Report::TYPE_MATRIX); $groupBy->attributeIndexOrDerivedType = 'officePhone'; $report->addGroupBy($groupBy); $dataProvider = new MatrixReportDataProvider($report); $exportItem = new ExportItem(); $exportItem->isCompleted = 0; $exportItem->exportFileType = 'csv'; $exportItem->exportFileName = 'matrixTest1'; $exportItem->modelClassName = 'SavedReport'; $exportItem->serializedData = ExportUtil::getSerializedDataForExport($dataProvider); $this->assertTrue($exportItem->save()); $id = $exportItem->id; $exportItem->forget(); unset($exportItem); //Delete queued jobs from test exportItems created above Yii::app()->jobQueue->deleteAll(); ExportModule::$asynchronousPageSize = 2; $job = new ExportJob(); $this->assertTrue($job->run()); $exportItem = ExportItem::getById($id); $fileModel = $exportItem->exportFileModel; $this->assertEquals(1, $exportItem->isCompleted); $this->assertEquals(0, $exportItem->processOffset); $this->assertEquals('csv', $exportItem->exportFileType); $this->assertEquals('matrixTest1', $exportItem->exportFileName); $this->assertTrue($fileModel instanceof ExportFileModel); $fileContent = $fileModel->fileContent->content; $this->assertContains('Test Account', $fileContent); $this->assertContains('Test Account 2', $fileContent); $this->assertContains('Test Account 3', $fileContent); $this->assertContains('Test Account 4', $fileContent); // Check if user got notification message, and if its type is ExportProcessCompleted $this->assertEquals($numberOfUserNotifications + 2, Notification::getCountByTypeAndUser('ExportProcessCompleted', Yii::app()->user->userModel)); }
public function testExportWithSelectAllForMoreThan10Records() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $accounts = Account::getAll(); foreach ($accounts as $account) { $account->delete(); } $exportItems = ExportItem::getAll(); foreach ($exportItems as $exportItem) { $exportItem->delete(); } $numberOfRecords = rand(12, 100); ExportModule::$asynchronusThreshold = $numberOfRecords - 1; for ($i = 1; $i <= $numberOfRecords; $i++) { $randomData = RandomDataUtil::getRandomDataByModuleAndModelClassNames('AccountsModule', 'Account'); AccountTestHelper::createAccountByNameForOwner($randomData['names'][$i], $super); } $this->setGetArray(array('Account_page' => '1', 'export' => '', 'selectAll' => '1', 'selectedIds' => '', 'ajax' => '')); $this->runControllerWithRedirectExceptionAndGetUrl('accounts/default/export'); // Start background job $job = new ExportJob(); $this->assertTrue($job->run()); $exportItems = ExportItem::getAll(); $this->assertEquals(1, count($exportItems)); $fileModel = $exportItems[0]->exportFileModel; $this->assertEquals(1, $exportItems[0]->isCompleted); $this->assertEquals('csv', $exportItems[0]->exportFileType); $this->assertEquals('accounts', $exportItems[0]->exportFileName); $this->assertTrue($fileModel instanceof ExportFileModel); for ($i = 1; $i <= $numberOfRecords; $i++) { $this->assertContains($randomData['names'][$i], $fileModel->fileContent->content); } }
public function filters() { $filters = array(); $filters[] = array(ZurmoBaseController::RIGHTS_FILTER_PATH, 'moduleClassName' => 'ExportModule', 'rightName' => ExportModule::getAccessRight()); return $filters; }