function test_deleteAll() { //Arrange $name = "Build a shed"; $motivation = "have storage"; $due_date = "2015-09-09"; $priority = 1; $test_project = new Project($name, $motivation, $due_date, $priority); $test_project->save(); $name2 = "Learn French"; $motivation2 = "To travel"; $test_project2 = new Project($name2, $motivation2, $due_date, $priority); $test_project2->save(); //Act Project::deleteAll(); $result = Project::getAll(); //Assert $this->assertEquals([], $result); }
/** * Walkthrough test for synchronous download */ public function testAsynchronousDownloadDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); Project::deleteAll(); $projects = array(); for ($i = 0; $i <= ExportModule::$asynchronousThreshold + 1; $i++) { $projects[] = ProjectTestHelper::createProjectByNameForOwner('superProject' . $i, $super); } Notification::deleteAll(); NotificationMessage::deleteAll(); $this->setGetArray(array('Project_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '1', 'selectedIds' => '')); $this->runControllerWithRedirectExceptionAndGetUrl('projects/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('projects', $exportItems[0]->exportFileName); $this->assertTrue($fileModel instanceof ExportFileModel); $this->assertEquals(1, Notification::getCount()); $this->assertEquals(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::deleteAll(); $selectedIds = ""; foreach ($projects as $project) { $selectedIds .= $project->id . ","; // Not Coding Standard } $this->setGetArray(array('ProjectsSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => ''), 'multiselect_ProjectsSearchForm_anyMixedAttributesScope' => 'All', 'Project_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '', 'selectedIds' => "{$selectedIds}")); $this->runControllerWithRedirectExceptionAndGetUrl('projects/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('projects', $exportItems[0]->exportFileName); $this->assertTrue($fileModel instanceof ExportFileModel); $this->assertEquals(2, Notification::getCount()); $this->assertEquals(2, NotificationMessage::getCount()); }