-
Notifications
You must be signed in to change notification settings - Fork 0
/
tableTest.php
91 lines (72 loc) · 2.42 KB
/
tableTest.php
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
require_once('table.php');
class TableTest extends PHPUnit_Framework_TestCase {
/**
* A basic functional test example.
*
* @return void
*/
var $tabler;
public function __construct(){
$this->tabler = new Tabler();
}
public function _getSubject(){
return $this->tabler;
}
public function _getTestRow(){
return array(
'Name' => 'Trixie',
'Color' => 'Green',
'Element' => 'Earth',
'Likes' => 'Flowers'
);
}
public function testGenerateDoesNotAcceptANonArray()
{
$t = $this->_getSubject();
$this->assertFalse($t->generate('not an array'));
}
public function testGenerateDoesNotAcceptAnEmptyArray(){
$t = $this->_getSubject();
$this->assertFalse($t->generate(array()));
}
public function testGetBreakReturnsALineBreak(){
$t = $this->_getSubject();
$this->assertEquals($t->getBreak(), "\n");
}
public function testGetStringFromRowShouldStartwithTheDelimiter(){
$t = $this->_getSubject();
$delimiter = "|";
$this->assertStringStartsWith($delimiter, $t->getStringFromRow($this->_getTestRow(), $delimiter));
}
public function testGetStringFromRowShouldEndwithTheDelimiter(){
$t = $this->_getSubject();
$delimiter = "|";
$this->assertStringEndsWith($delimiter, $t->getStringFromRow($this->_getTestRow(), $delimiter));
}
public function testGetStringFromRowShouldNotStartwithASpace(){
$t = $this->_getSubject();
$delimiter = " | ";
$this->assertStringStartsNotWith(' ', $t->getStringFromRow($this->_getTestRow(), $delimiter));
}
public function testGetStringFromRowShouldNotEndwithASpace(){
$t = $this->_getSubject();
$delimiter = " | ";
$this->assertStringEndsNotWith(' ', $t->getStringFromRow($this->_getTestRow(), $delimiter));
}
public function testGeneratedStringMustStartWithALineFromGetLine(){
$t = $this->_getSubject();
$delimiter = " | ";
$arr = array($this->_getTestRow());
$this->assertStringStartsWith($t->getLine($t->getColumnNamesFromArray($arr)), $t->generate($arr));
}
public function testArrangeRowToColumnsMustReturnAnArrayWithOnlyTheOriginalColumns(){
$t = $this->_getSubject();
$original_row = $this->_getTestRow();
$extra = array('wrong', 'column');
$extra_row = array_merge($original_row, $extra);
$original_columns = $t->getColumnNamesFromArray(array($original_row));
$extra_row = $t->arrangeRowToColumns($original_row, $original_columns);
$this->assertNotContains('wrong', array_keys($extra_row));
}
}