/** * Validate that the file-system logger factory constructs an object of the * correct type */ public function test_fsloggerfactoryinstantiatescorrectclass() { global $CFG; require_once $CFG->dirroot . '/local/datahub/lib/rlip_fslogger.class.php'; $file = get_plugin_directory('dhimport', 'version1') . '/rlip_import_version1_fslogger.class.php'; require_once $file; // Setup. $fslogger = rlip_fslogger_factory::factory('dhexport_version1', null); // Validation. $this->assertInstanceOf('rlip_fslogger_linebased', $fslogger); // Setup. $fslogger = rlip_fslogger_factory::factory('dhimport_version1', null); // Validation. $this->assertInstanceOf('rlip_import_version1_fslogger', $fslogger); }
/** * Provides the object used to log information to the file system logfile * * @param string $plugin the plugin * @param string $entity the entity type * @param boolean $manual Set to true if a manual run * @param integer $starttime the time used in the filename * @return object the fslogger */ function get_fslogger($plugin, $entity = '', $manual = false, $starttime = 0) { global $CFG; require_once $CFG->dirroot . '/local/datahub/lib/rlip_fslogger.class.php'; //set up the file-system logger $filepath = get_config($plugin, 'logfilelocation'); //get filename $filename = rlip_log_file_name('import', $plugin, $filepath, $entity, $manual, $starttime); if (!empty($filename)) { $this->set_log_path($filename); $fileplugin = rlip_fileplugin_factory::factory($filename, NULL, true); return rlip_fslogger_factory::factory($plugin, $fileplugin, $manual); } return null; }
/** * Validate that the file-system logger closes the appropriate file after writing */ public function test_fsloggerclosesfile() { // Set up the file plugin for IO. $fileplugin = new rlip_fileplugin_trackopen(); // Set up the logging object. $fslogger = rlip_fslogger_factory::factory('bogus_plugin', $fileplugin); // Write a line. $result = $fslogger->log_success('Teststring', 1000000000); // Clean up. $fslogger->close(); // Validation. $this->assertTrue($fileplugin->was_opened()); $this->assertFalse($fileplugin->is_open()); }
/** * Valid fslogger required for phpunit tests * @param string $plugin * @param string $entity the entity type * @param boolean $manual Set to true if a manual run * @param integer $starttime the time used in the filename * @return object The fslogger instance */ public function get_fslogger($plugin, $entity = '', $manual = false, $starttime = 0) { $fileplugin = rlip_fileplugin_factory::factory('/dev/null', null, true); $entity = ''; return rlip_fslogger_factory::factory($plugin, $fileplugin, $entity); }
/** * Default export plugin constructor * * @param object $fileplugin the file plugin used for output * @param boolean $manual Set to true if a manual run */ function __construct($fileplugin, $manual = false) { global $CFG; require_once $CFG->dirroot . '/local/datahub/lib/rlip_dblogger.class.php'; require_once $CFG->dirroot . '/local/datahub/lib/rlip_fslogger.class.php'; $this->fileplugin = $fileplugin; $this->manual = $manual; $this->dblogger = new rlip_dblogger_export($this->manual); //convert class name to plugin name $class = get_class($this); $this->plugin = str_replace('rlip_exportplugin_', 'dhexport_', $class); //track the start time as the current time - moved from run() in order to support rlip_log_file_name $this->dblogger->set_starttime(time()); //set up the file-system logger, if exists $filepath = get_config($this->plugin, 'logfilelocation'); $filename = rlip_log_file_name('export', $this->plugin, $filepath, '', $manual, $this->dblogger->starttime); if (!empty($filename)) { $this->dblogger->set_log_path($filename); $fileplugin = rlip_fileplugin_factory::factory($filename, NULL, true, $manual); $this->fslogger = rlip_fslogger_factory::factory($this->plugin, $fileplugin, $this->manual); } $this->dblogger->set_plugin($this->plugin); }