/** * @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()); }
public static function tearDownAfterClass() { ExportModule::$asynchronousThreshold = self::$asynchronousThreshold; parent::tearDownAfterClass(); }
public function testExportWithSelectAllForMoreThan10Records() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); Account::deleteAll(); ExportItem::deleteAll(); $numberOfRecords = rand(12, 100); ExportModule::$asynchronousThreshold = $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); } }