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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157<?php
require_once 'BasicFunctions.php';
class BasicTest extends PHPUnit_Framework_TestCase
{
public function testArrayReverse(){
$file = file_get_contents("BasicFunctions.php");
preg_match("/sf_array_reverse(.*)sf_evenly_divisble/s", $file, $matches);
if( count($matches) == 0 ){
$this->assertTrue(false);
return;
}
$usingArrayReverse = strpos($matches[0], "array_reverse");
$this->assertTrue( !$usingArrayReverse, "You can't use array_reverse to reverse the array.");
if( $usingArrayReverse !== false ){
return;
}
$arr = self::getRandomArray();
$reversed = sf_array_reverse( $arr );
$this->assertInternalType("array", $reversed, "The returned array isn't an array.");
if( is_array($reversed) ){
$this->assertTrue( array_reverse($arr) == $reversed, "The returned array is not reversed :(" );
}
}
public function testEvenlyDivisible(){
$divisor = rand(3, 5);
$arr = self::getRandomArray();
$evenlyDivisible = array_reduce($arr, function($result, $el) use ($divisor){
if( $el % $divisor === 0 ){
$result[] = $el;
}
return $result;
}, array());
sort($evenlyDivisible);
$testedEvenlyDivisible = sf_evenly_divisble($arr, $divisor);
$this->assertInternalType("array", $testedEvenlyDivisible, "The returned array isn't an array.");
if( is_array($testedEvenlyDivisible) ){
sort($testedEvenlyDivisible);
$this->assertTrue( $testedEvenlyDivisible == $evenlyDivisible, "The returned array doesn't match expected." );
}
}
public function testClosure(){
$l = rand(1, 100);
$r = rand(1, 100);
$fn = sf_get_sum_closure($l, $r);
$this->assertTrue( gettype($fn) == "object", "A function was not returned :(");
if( gettype($fn) == "object" ){
$this->assertEquals( $fn(), $l + $r);
}
}
public function testExtractLinks(){
$html = <<<EOF
<div class="span7">
<div class="row-fluid top-row">
<div class="span6">
<div class="metro-tile big-tile green">
<div class="tile-inner-image"><a href="/what-we-do/"><img src="/wp-content/themes/setfive_three/images/settings.png"></a></div>
<div class="tile-inner"><a href="/what-we-do/">What we do ></a></div>
</div>
</div>
<div class="span6">
<div class="metro-tile big-tile purple">
<div class="tile-inner-image"><a href="/about-us/"><img src="/wp-content/themes/setfive_three/images/user.png"></a></div>
<div class="tile-inner"><a href="/about-us/">Team ></a></div>
</div>
</div>
</div>
<div class="row-fluid bottom-row">
<div class="span6">
<div class="metro-tile big-tile orange">
<div class="tile-inner-image"><a href="/our-stack/"><img src="/wp-content/themes/setfive_three/images/storage.png"></a></div>
<div class="tile-inner"><a href="/our-stack/">Our stack ></a></div>
</div>
</div>
<div class="span6">
<div class="metro-tile big-tile red">
<div class="tile-inner-image"><a href="/work/"><img src="/wp-content/themes/setfive_three/images/gallery1.png"></a></div>
<div class="tile-inner"><a href="/work/">Work ></a></div>
</div>
</div>
</div>
<div class="banner"><h3>Get in touch</h3></div>
<div class="row-fluid">
<div class="span6">
<form action="/wp-content/themes/setfive_three/sendContactEmail.php" data-provide="contact-form">
<div data-provide="contact-success" class="alert alert-success hide">Your message has been sent!</div>
<ul class="listless contact-form">
<li><input type="text" placeholder="Enter your email address..." class="input-block-level" name="contact[email]"></li>
<li><textarea placeholder="Enter your message..." class="input-block-level" name="contact[message]"></textarea></li>
<li><input type="submit" value="Send Message" class="btn pull-right"></li>
</ul>
<input type="hidden" name="contact[is_human]">
</form>
</div>
<div class="span6">
<ul class="listless contact-form centered">
<li><a target="_blank" href="http://goo.gl/maps/EtCPp"><img src="http://maps.googleapis.com/maps/api/staticmap?center=Central%20Square%20Cambridge,%20MA&zoom=15&size=315x175&maptype=roadmap&sensor=false" class="shadowed-thumbnail"></a></li>
<li class="tight"><a href="mailto:contact@setfive.com">contact@setfive.com</a> | <a href="https://www.twitter.com/setfive">@setfive</a> | <a href="tel:6178630440">617-863-0440</a></li>
<li>678 Massachusetts Ave. Cambridge, MA 02139</li>
</ul>
</div>
</div>
</div>
EOF;
$links = sf_extract_links( $html );
$this->assertInternalType("array", $links, "The returned array isn't an array.");
$target = json_decode('["\/what-we-do\/","\/what-we-do\/","\/about-us\/","\/about-us\/","\/our-stack\/","\/our-stack\/","\/work\/","\/work\/","mailto:contact@setfive.com","https:\/\/www.twitter.com\/setfive","tel:6178630440"]', true);
if( is_array($links) ){
sort($links);
sort($target);
$this->assertTrue( $links == $target, "The array doesn't contain the links from the HTML!" );
}
}
private static function getRandomArray(){
$arr = array();
for($i = 0; $i < rand(15, 25); $i++){
$arr[] = rand(1, 100);
}
return $arr;
}
}