Пример #1
0
 /**
  * Saves Custom Import Model Object
  * @param CustomImport $customImport
  * @throws DaoException
  */
 public function saveCustomImport(CustomImport $customImport)
 {
     try {
         $customImport->save();
         return true;
     } catch (Exception $e) {
         throw new DaoException($e->getMessage());
     }
 }
 /**
  * Test case for save() method for existing custom import definition
  */
 public function testSaveUpdate()
 {
     $countBefore = $this->_count();
     // save with duplicate name should throw exception
     $import = new CustomImport();
     // we set id = 2, so save should update the record with id=2
     $import->setId(2);
     $import->setName("Import 1");
     $import->setAssignedFields(array("empId", "street1", "gender", "firstName", "lastName"));
     try {
         $import->save();
         $this->fail("Exception should be thrown on duplicate name");
     } catch (CustomImportException $e) {
         $this->assertEquals(CustomImportException::DUPLICATE_IMPORT_NAME, $e->getCode());
     }
     // save with empty fields should throw exception
     $import->setName("New Import 1");
     $import->setAssignedFields(array());
     try {
         $import->save();
         $this->fail("Exception should be thrown on empty assigned fields");
     } catch (CustomImportException $e) {
         $this->assertEquals(CustomImportException::NO_ASSIGNED_FIELDS, $e->getCode());
     }
     $import->setName("New Import 1");
     $import->setAssignedFields(null);
     try {
         $import->save();
         $this->fail("Exception should be thrown on empty assigned fields");
     } catch (CustomImportException $e) {
         $this->assertEquals(CustomImportException::NO_ASSIGNED_FIELDS, $e->getCode());
     }
     // save with field not in field list should throw exception
     $import->setName("New Import 1");
     $import->setAssignedFields(array("firstName", "lastName", "EmployeeId"));
     try {
         $import->save();
         $this->fail("Exception should be thrown on invalid field");
     } catch (CustomImportException $e) {
         $this->assertEquals(CustomImportException::INVALID_FIELD_NAME, $e->getCode());
     }
     // save with compulsary field missing should throw exception.
     $import->setName("New Import 1");
     $import->setAssignedFields(array("firstName", "empId"));
     try {
         $import->save();
         $this->fail("Exception should be thrown when compulsary field is missing");
     } catch (CustomImportException $e) {
         $this->assertEquals(CustomImportException::COMPULSARY_FIELDS_NOT_ASSIGNED, $e->getCode());
     }
     // valid save, verify data saved
     $import->setName("New Import 1");
     $import->setAssignedFields(array("empId", "street1", "firstName", "lastName", "gender"));
     $import->setContainsHeader(true);
     $import->save();
     $id = $import->getId();
     // verify id not changed
     $this->assertTrue(!empty($id));
     $this->assertEquals(2, $id);
     // verify saved
     $name = $import->getName();
     $fields = implode(",", $import->getAssignedFields());
     $hasHeader = CustomImport::HAS_HEADING;
     $countAfter = $this->_count();
     $this->assertEquals($countAfter, $countBefore);
     $count = $this->_count("import_id={$id} AND name='{$name}' AND fields='{$fields}' AND has_heading='{$hasHeader}'");
     $this->assertEquals(1, $count, "Not Updated");
     // Save without changing anything
     $import->save();
     $id = $import->getId();
     // verify id not changed
     $this->assertTrue(!empty($id));
     $this->assertEquals(2, $id);
     $countAfter = $this->_count();
     $this->assertEquals($countAfter, $countBefore);
     $count = $this->_count("import_id={$id} AND name='{$name}' AND fields='{$fields}' AND has_heading='{$hasHeader}'");
     $this->assertEquals(1, $count, "Not Updated");
 }