forked from jakiestfu/Shadow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.php
More file actions
143 lines (114 loc) · 4.43 KB
/
tests.php
File metadata and controls
143 lines (114 loc) · 4.43 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
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
<?PHP
require 'src/Shadow.php';
$time_start = microtime(true);
$autoTrack = false;
$shadow = new Shadow('MyAppName', function($sh){
global $autoTrack;
$sh->type('shadow_test')->item('object-id')->meta('autoTrack', "tracked")->track();
$autoTrack = $sh->type('shadow_test')->item('object-id')->meta('autoTrack')->get() == "tracked" ? true : false;
});
// Simple String Operation
$shadow->type('shadow_test')->item('object-id')->meta('stringKey', "shadowROX")->track();
$simpleStringRes = $shadow->type('shadow_test')->item('object-id')->meta('stringKey')->get() == "shadowROX" ? true : false;
// Complex String Operation
$shadow->type('shadow_test')->item('object-id')->meta('complexStringKey/wow', "shadowComplexROX")->track();
$complexStringRes = $shadow->type('shadow_test')->item('object-id')->meta('complexStringKey/wow')->get() == "shadowComplexROX" ? true : false;
// Simple Array Operation
$simpArray = array(
'alpha' => 'beta',
'foo' => 'bar',
'hello' => 200
);
$shadow->type('shadow_test')->item('object-id')->meta('arrayKey', $simpArray)->track();
$simpleArrayRes = $shadow->type('shadow_test')->item('object-id')->meta('arrayKey')->get() == $simpArray ? true : false;
// Complex Array Operation
$compArray = array(
'alpha' => 'beta',
'foo' => 'bar',
'hello' => 200
);
$shadow->type('shadow_test')->item('object-id')->meta('arrayComplexKey', $compArray)->track();
$complexArrayRes = $shadow->type('shadow_test')->item('object-id')->meta('arrayComplexKey')->get() == $compArray ? true : false;
// Simple Count Operation
$shadow->type('shadow_test')->item('object-id')->meta('impressions')->track();
$shadow->type('shadow_test')->item('object-id')->meta('impressions')->track();
$simpleCountRes = $shadow->type('shadow_test')->item('object-id')->meta('impressions')->get() == 2 ? true : false;
// Complex Operation
$shadow->type('shadow_test')->item('object-id')->meta('gender/male')->track();
$shadow->type('shadow_test')->item('object-id')->meta('gender/male')->track();
$shadow->type('shadow_test')->item('object-id')->meta('gender/male')->track();
$shadow->type('shadow_test')->item('object-id')->meta('gender/female')->track();
$shadow->type('shadow_test')->item('object-id')->meta('gender/female')->track();
$complexRes = $shadow->type('shadow_test')->item('object-id')->meta('gender')->get();
$complexCountRes = $complexRes['male'] == 3 && $complexRes['female']==2 ? true : false;
// Unary Operation
$shadow->type('shadow_test')->item('object-id')->relation('unary', 1, true)->track();
$unaryRes = $shadow->type('shadow_test')->item('object-id')->relation('unary', 1)->get() ? true : false;
// Binary Operation
$shadow->type('shadow_test')->item('object-id')->relation('binary', 1, false)->track();
$binaryRes = $shadow->type('shadow_test')->item('object-id')->relation('binary', 1)->get();
$binaryRes = $binaryRes===false ? true : false;
// Multary Operation
$shadow->type('shadow_test')->item('object-id')->relation('multary', 1, 4)->track();
$multaryRes = $shadow->type('shadow_test')->item('object-id')->relation('multary', 1)->get() == 4 ? true : false;
$testResults = array(
'auto_track' => $autoTrack,
'simple_string_operation' => $simpleStringRes,
'simple_array_operation' => $simpleArrayRes,
'simple_count_operation' => $simpleCountRes,
'complex_string_operation' => $complexStringRes,
'complex_array_operation' => $complexArrayRes,
'complex_count_operation' => $complexCountRes,
'unary_relation' => $unaryRes,
'binary_relation' => $binaryRes,
'multary_relation' => $multaryRes
);
$shadow->clearDataByType('shadow_test');
$time_end = microtime(true);
?><!doctype html>
<html lang="en">
<head>
<title>Shadow Tests</title>
<style type="text/css">
ul{
margin: 0;
padding: 0;
}
ul, ul li{
display:block;
}
.success, .error{
padding:20px;
color:#fff;
font-family:monospace;
font-size:18px;
margin-bottom:10px;
-webkit-border-radius:5px;
-moz-border-radius:5px;
border-radius:5px;
}
.success{
background:#468847;
}
.error{
background:#b94a48;
}
span{
float:right;
}
</style>
</head>
<body><?PHP
echo '<p>Completed in '.number_format($time_end-$time_start, 3).' seconds</p>';
?>
<ul>
<?PHP
foreach($testResults as $k=>$r){
$klass = $r ? 'success' : 'error';
$text = $r ? 'Passed' : 'Failed';
echo '<li class="'.$klass.'">'.ucwords(str_ireplace('_',' ',$k)).'<span>'.$text.'</span></li>';
}
?>
</ul>
</body>
</html>