setQueryResultsIteratorMock($mock); global $wpdb; $wpdb = new WPDB_Mock; $fields = array(); foreach (array_keys($data[0]) as $key) { $fields[] = (object)array('field_name' => $key); } $wpdb->getResultReturnVal = $fields; CFDBPermittedFunctions::getInstance()->addPermittedFunction('cambiaFecha'); } public function test_transform1() { $options = array(); $options['trans'] = 'inicio=cambiaFecha(inicio)'; $options['content'] = '${name}|${inicio}|${fin} '; $exp = new ExportToHtmlTemplate(); ob_start(); $exp->export('dates', $options); $text = ob_get_contents(); $this->assertEquals("Mike|1.1.2014|2/1/2014 Oya|5.1.2014|6/1/2014 ", $text); } public function test_transform2() { $options = array(); $options['trans'] = 'fin=cambiaFecha(fin)'; $options['content'] = '${name}|${inicio}|${fin} '; $exp = new ExportToHtmlTemplate(); ob_start(); $exp->export('dates', $options); $text = ob_get_contents(); $this->assertEquals("Mike|1/1/2014|2.1.2014 Oya|5/1/2014|6.1.2014 ", $text); } public function test_transforms() { $options = array(); $options['trans'] = 'inicio=cambiaFecha(inicio)&&fin=cambiaFecha(fin)'; $options['content'] = '${name}|${inicio}|${fin} '; $exp = new ExportToHtmlTemplate(); ob_start(); $exp->export('dates', $options); $text = ob_get_contents(); $this->assertEquals("Mike|1.1.2014|2.1.2014 Oya|5.1.2014|6.1.2014 ", $text); } } function cambiaFecha($date) { return str_replace('/', '.', $date); }