/** * @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()); }
/** * Walkthrough test for synchronous download */ public function testAsynchronousDownloadDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $notificationsBeforeCount = Notification::getCount(); $notificationMessagesBeforeCount = NotificationMessage::getCount(); $products = Product::getAll(); if (count($products)) { foreach ($products as $product) { $product->delete(); } } $products = array(); for ($i = 0; $i <= ExportModule::$asynchronousThreshold + 1; $i++) { $products[] = ProductTestHelper::createProductByNameForOwner('superProduct' . $i, $super); } $this->setGetArray(array('Product_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '1', 'selectedIds' => '')); $this->runControllerWithRedirectExceptionAndGetUrl('products/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('products', $exportItems[0]->exportFileName); $this->assertTrue($fileModel instanceof ExportFileModel); $this->assertEquals($notificationsBeforeCount + 1, Notification::getCount()); $this->assertEquals($notificationMessagesBeforeCount + 1, NotificationMessage::getCount()); // Check export job, when many ids are selected. // This will probably never happen, but we need test for this case too. $notificationsBeforeCount = Notification::getCount(); $notificationMessagesBeforeCount = NotificationMessage::getCount(); // Now test case when multiple ids are selected $exportItems = ExportItem::getAll(); if (count($exportItems)) { foreach ($exportItems as $exportItem) { $exportItem->delete(); } } $selectedIds = ""; foreach ($products as $product) { $selectedIds .= $product->id . ","; // Not Coding Standard } $this->setGetArray(array('ProductsSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'quantity' => ''), 'multiselect_ProductsSearchForm_anyMixedAttributesScope' => 'All', 'Product_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '', 'selectedIds' => "{$selectedIds}")); $this->runControllerWithRedirectExceptionAndGetUrl('products/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('products', $exportItems[0]->exportFileName); $this->assertTrue($fileModel instanceof ExportFileModel); $this->assertEquals($notificationsBeforeCount + 1, Notification::getCount()); $this->assertEquals($notificationMessagesBeforeCount + 1, NotificationMessage::getCount()); }