fix modlog test undo
[tine20] / tests / tine20 / ImportTestCase.php
1 <?php
2 /**
3  * Tine 2.0 - http://www.tine20.org
4  * 
5  * @package     Tests
6  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
7  * @copyright   Copyright (c) 2015 Metaways Infosystems GmbH (http://www.metaways.de)
8  * @author      Philipp Schüle <p.schuele@metaways.de>
9  */
10
11 /**
12  * abstract Test class for import tests
13  * 
14  * @package     Tests
15  */
16 abstract class ImportTestCase extends TestCase
17 {
18     /**
19      * importer instance
20      * 
21      * @var Object
22      */
23     protected $_instance = null;
24
25     /**
26      * @var string $_filename of the export
27      */
28     protected $_filename = null;
29
30     /**
31      * @var boolean
32      *
33      * TODO needed here?
34      */
35     protected $_deleteImportFile = true;
36
37     protected $_importerClassName = null;
38     protected $_exporterClassName = null;
39     protected $_modelName = null;
40     protected $_testContainer = null;
41
42     /**
43      * tear down tests
44      */
45     protected function tearDown()
46     {
47         parent::tearDown();
48
49         if ($this->_testContainer) {
50             Tinebase_Container::getInstance()->deleteContainer($this->_testContainer);
51         }
52     }
53
54     /**
55      * import helper
56      *
57      * @param array $_options
58      * @param string|Tinebase_Model_ImportExportDefinition $_definition
59      * @param Tinebase_Model_Filter_FilterGroup $_exportFilter
60      * @throws Tinebase_Exception_NotFound
61      * @return array
62      */
63     protected function _doImport(array $_options, $_definition, Tinebase_Model_Filter_FilterGroup $_exportFilter = NULL)
64     {
65         if (! $this->_importerClassName || ! $this->_modelName) {
66             throw new Tinebase_Exception_NotFound('No import class or model name given');
67         }
68
69         $definition = ($_definition instanceof Tinebase_Model_ImportExportDefinition) ? $_definition : Tinebase_ImportExportDefinition::getInstance()->getByName($_definition);
70         $this->_instance = call_user_func_array($this->_importerClassName . '::createFromDefinition' , array($definition, $_options));
71
72         // export first
73         if ($_exportFilter !== NULL && $this->_exporterClassName) {
74             $exporter = new $this->_exporterClassName($_exportFilter, Tinebase_Core::getApplicationInstance($this->_modelName));
75             $this->_filename = $exporter->generate();
76         }
77
78         // then import
79         $result = $this->_instance->importFile($this->_filename);
80
81         return $result;
82     }
83 }