HtmlTemplateTransformTest.php
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
include_once(dirname(dirname(__FILE__)) . '/ExportToHtmlTemplate.php');
include_once(dirname(dirname(__FILE__)) . '/CFDBPermittedFunctions.php');
include_once('MockQueryResultIterator.php');
include_once('WP_Mock_Functions.php');
include_once('WPDB_Mock.php');
class HtmlTemplateTransformTest extends PHPUnit_Framework_TestCase {
public function setUp() {
date_default_timezone_set('America/New_York');
$str = file_get_contents('HtmlTemplateTransformTest.json');
$data = json_decode($str, true);
$mock = new MockQueryResultIterator($data);
CFDBQueryResultIteratorFactory::getInstance()->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);
}