/** * Step 2. Upload the csv to import. */ public function actionStep2($id) { $import = Import::getById((int) $id); $importWizardForm = ImportWizardUtil::makeFormByImport($import); if (isset($_POST[get_class($importWizardForm)])) { ImportWizardUtil::setFormByPostForStep2($importWizardForm, $_POST[get_class($importWizardForm)]); if ($importWizardForm->fileUploadData == null) { $importWizardForm->addError('fileUploadData', Zurmo::t('ImportModule', 'A file must be uploaded in order to continue the import process.')); } elseif (!ImportWizardUtil::importFileHasAtLeastOneImportRow($importWizardForm, $import)) { if ($importWizardForm->firstRowIsHeaderRow) { $importWizardForm->addError('fileUploadData', Zurmo::t('ImportModule', 'The file that has been uploaded only has a header row and no additional rows to import.')); } else { $importWizardForm->addError('fileUploadData', Zurmo::t('ImportModule', 'A file must be uploaded with at least one row to import.')); } } else { $importRulesClassName = $importWizardForm->importRulesType . 'ImportRules'; if (!is_subclass_of($importRulesClassName::getModelClassName(), 'SecurableItem')) { $nextStep = 'step4'; } else { $nextStep = 'step3'; } $this->attemptToValidateImportWizardFormAndSave($importWizardForm, $import, $nextStep); } } $title = Zurmo::t('ImportModule', 'Import Wizard - Upload File'); $importRulesClassName = ImportRulesUtil::getImportRulesClassNameByType($importWizardForm->importRulesType); $progressBarAndStepsView = new ImportStepsAndProgressBarForWizardView($importRulesClassName, 1); $importView = new ImportWizardUploadFileView($this->getId(), $this->getModule()->getId(), $importWizardForm, $title); echo $this->getImportPageView($progressBarAndStepsView, $importView)->render(); }
/** * @depends testSetFormByFileUploadData */ public function testSetFormByPostForStep2() { $fakePostData = array('firstRowIsHeaderRow' => 'xyz', 'rowColumnDelimiter' => ',', 'rowColumnEnclosure' => '"'); // Not Coding Standard $importWizardForm = new ImportWizardForm(); ImportWizardUtil::setFormByPostForStep2($importWizardForm, $fakePostData); $this->assertEquals('xyz', $importWizardForm->firstRowIsHeaderRow); }