/** * Walkthrough test for asynchronous download */ public function testAsynchronousDownloadDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $notificationsBeforeCount = count(Notification::getAll()); $notificationMessagesBeforeCount = count(NotificationMessage::getAll()); $accounts = Account::getAll(); if (count($accounts)) { foreach ($accounts as $account) { $account->delete(); } } $accounts = array(); for ($i = 0; $i <= ExportModule::$asynchronusThreshold + 1; $i++) { $accounts[] = AccountTestHelper::createAccountByNameForOwner('superAccount' . $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); $this->assertEquals($notificationsBeforeCount + 1, count(Notification::getAll())); $this->assertEquals($notificationMessagesBeforeCount + 1, count(NotificationMessage::getAll())); // Check export job, when many ids are selected. // This will probably never happen, but we need test for this case too. $notificationsBeforeCount = count(Notification::getAll()); $notificationMessagesBeforeCount = count(NotificationMessage::getAll()); // Now test case when multiple ids are selected $exportItems = ExportItem::getAll(); if (count($exportItems)) { foreach ($exportItems as $exportItem) { $exportItem->delete(); } } $selectedIds = ""; foreach ($accounts as $account) { $selectedIds .= $account->id . ","; // Not Coding Standard } $this->setGetArray(array('AccountsSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'name' => '', 'officePhone' => ''), 'multiselect_AccountsSearchForm_anyMixedAttributesScope' => 'All', 'selectAll' => '', 'selectedIds' => "{$selectedIds}", 'Account_page' => '1', 'export' => '', '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); $this->assertEquals($notificationsBeforeCount + 1, count(Notification::getAll())); $this->assertEquals($notificationMessagesBeforeCount + 1, count(NotificationMessage::getAll())); }
/** * @depends testCreateActionForRowsAndColumns */ public function testExportAction() { if (RedBeanDatabase::isFrozen()) { return; } $notificationsBeforeCount = count(Notification::getAll()); $notificationMessagesBeforeCount = count(NotificationMessage::getAll()); $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, count(Notification::getAll())); $this->assertEquals($notificationMessagesBeforeCount + 1, count(NotificationMessage::getAll())); }