forked from argoproject/Argo
-
-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathtest-helpers.php
224 lines (187 loc) · 7.96 KB
/
test-helpers.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
class HelpersTestFunctions extends WP_UnitTestCase {
function setUp() {
parent::setUp();
// Test data
$this->author_user_ids = $this->factory->user->create_many(10, array('role' => 'author'));;
$this->contributor_user_ids = $this->factory->user->create_many(5, array('role' => 'contributor'));
}
function test_largo_fb_url_to_username() {
/**
* A short list of valid Facebook IDs:
https://www.facebook.com/Foo-bar.1
https://www.facebook.com/profile.php?id=012345678901234&fref=ts
https://www.facebook.com/Foo-bar.2?rf=012345678901234
https://www.facebook.com/pages/Foo-bar.3/012345678901234
https://m.facebook.com/Foo-bar.4?_e_pi_=7%2CPAGE_ID10%2C0123456789
https://m.facebook.com/profile.php?id=012345678901234
https://m.facebook.com/?_rdr#!/Foo-bar.5?__user=012345678901234
*/
/**
* With no input, it should return an empty string
*/
$result = largo_fb_url_to_username("");
$this->assertEquals("", $result);
unset($result);
/**
* With a valid username, it should return that username
*/
$result = largo_fb_url_to_username("Foo-bar.0");
$this->assertEquals("Foo-bar.0", $result);
unset($result);
$result = largo_fb_url_to_username("012345678901234");
$this->assertEquals("012345678901234", $result);
unset($result);
/**
* With a valid URL, it should return the username
*/
$result = largo_fb_url_to_username("https://www.facebook.com/Foo-bar.1");
$this->assertEquals("Foo-bar.1", $result);
unset($result);
$result = largo_fb_url_to_username("https://www.facebook.com/profile.php?id=012345678901234&fref=ts");
$this->assertEquals("012345678901234", $result);
unset($result);
$result = largo_fb_url_to_username("https://www.facebook.com/Foo-bar.2?rf=012345678901234");
$this->assertEquals("Foo-bar.2", $result);
unset($result);
// For making a URL, Foo-bar.3 is a valid username, but so is the ID listed here.
$result = largo_fb_url_to_username("https://www.facebook.com/pages/Foo-bar.3/012345678901234");
$this->assertEquals("012345678901234", $result);
unset($result);
$result = largo_fb_url_to_username("https://m.facebook.com/Foo-bar.4?_e_pi_=7%2CPAGE_ID10%2C0123456789");
$this->assertEquals("Foo-bar.4", $result);
unset($result);
$result = largo_fb_url_to_username("https://m.facebook.com/profile.php?id=012345678901234");
$this->assertEquals("012345678901234", $result);
unset($result);
$result = largo_fb_url_to_username("https://m.facebook.com/?_rdr#!/Foo-bar.5?__user=012345678901234");
$this->assertEquals("Foo-bar.5", $result);
unset($result);
}
function test_largo_fb_user_is_followable() {
/**
* With no input, there should be no <table> in the resulting iframe
*/
$result = largo_fb_user_is_followable("");
$this->assertFalse($result, "The Facebook follow button iframe HTML structure has changed and largo_fb_url_to_username no longer operates predictably. Please fix.");
unset($result);
/**
* With Mark Zuckerberg, we hope that he will remain followable.
*/
$result = largo_fb_user_is_followable("zuck");
$this->assertTrue($result, "Either Mark Zuckerberg is no longer followable, or the Facebook follow button iframe HTML structure has changed and largo_fb_url_to_username no longer operates predictably. Please log into Facebook and check that https://www.facebook.com/zuck has a 'Follow' button.");
unset($result);
/**
* With a user that does not exist, we hope that the user will continue to not exist
*/
$result = largo_fb_user_is_followable("fb8c57ff40dda4b6898ae049d8298584");
$this->assertFalse($result, "Either https://www.facebook.com/fb8c57ff40dda4b6898ae049d8298584 is user that exists and allows follows, or the Facebook follow button iframe HTML structure has changed and largo_fb_url_to_username no longer operates predictably.");
unset($result);
/**
* With an invalid username, this should return false
*/
$result = largo_fb_user_is_followable("%22Aardvarks+lurk%2C+OK%3F%22");
$this->assertFalse($result, "Either https://www.facebook.com/%22Aardvarks+lurk%2C+OK%3F%22 is user that exists and allows follows (not at all likely), or the Facebook follow button iframe HTML structure has changed and largo_fb_url_to_username no longer operates predictably.");
unset($result);
}
function test_clean_user_fb_username() {
$this->markTestIncomplete('This test has not been implemented yet.');
}
function test_validate_fb_username() {
$this->markTestIncomplete('This test has not been implemented yet.');
}
function test_largo_twitter_url_to_username() {
/**
* With no input, it should return an empty string
*/
$result = largo_twitter_url_to_username("");
$this->assertEquals("", $result);
unset($result);
/**
* With a valid username, it should return the username
*/
$result = largo_twitter_url_to_username("foo_1");
$this->assertEquals("foo_1", $result);
unset($result);
/**
* With a valid url, it should return a valid username
*/
$result = largo_twitter_url_to_username("http://twitter.com/foo_2");
$this->assertEquals("foo_2", $result);
unset($result);
$result = largo_twitter_url_to_username("https://twitter.com/foo_3");
$this->assertEquals("foo_3", $result);
unset($result);
$result = largo_twitter_url_to_username("https://www.twitter.com/foo_4");
$this->assertEquals("foo_4", $result);
unset($result);
/**
* With an @ in the username, it should return the username without the @
*/
$result = largo_twitter_url_to_username("https://twitter.com/@foo_5");
$this->assertEquals("foo_5", $result);
unset($result);
$result = largo_twitter_url_to_username("@foo_6");
$this->assertEquals("foo_6", $result);
unset($result);
/**
* With a username that has invalid characters and URL parameters in it, it should return the invalid characters, but not URL parameters
*/
$result = largo_twitter_url_to_username("http://twitter.com/@foo.bar_7-!0?baz=qux&yes=no#hi");
$this->assertEquals("foo.bar_7-!0", $result);
unset($result);
$result = largo_twitter_url_to_username("https://twitter.com/@foo.bar_8-!0?baz=qux&yes=no#hi");
$this->assertEquals("foo.bar_8-!0", $result);
unset($result);
/**
* With a non-Twitter URL, it should still return the last section after the /
*/
$result = largo_twitter_url_to_username("http://github.com/INN/foo_9");
$this->assertEquals("foo_9", $result);
unset($result);
$result = largo_twitter_url_to_username("https://plus.google.com/foo_10");
$this->assertEquals("foo_10", $result);
unset($result);
/**
* With no input, it should return an empty string
*/
$result = largo_twitter_url_to_username("");
$this->assertEquals("", $result);
unset($result);
}
function test_clean_user_twitter_username() {
$this->markTestIncomplete('This test has not been implemented yet.');;
}
function test_validate_twitter_username() {
$this->markTestIncomplete('This test has not been implemented yet.');
}
function test_largo_youtube_url_to_ID() {
$this->markTestIncomplete('This test has not been implemented yet.');
}
function test_largo_youtube_iframe_from_url() {
$this->markTestIncomplete('This test has not been implemented yet.');
}
function test_largo_youtube_image_from_url() {
$this->markTestIncomplete('This test has not been implemented yet.');
}
function test_largo_make_slug() {
$this->markTestIncomplete('This test has not been implemented yet.');
}
function test_var_log() {
$this->markTestIncomplete('This test has not been implemented yet.');
}
function test_render_template() {
$this->markTestIncomplete('This test has not been implemented yet.');
}
function test_largo_get_current_url() {
$preserve = $_SERVER;
$_SERVER['SERVER_NAME'] = 'testdomain.com';
$_SERVER['REQUEST_URI'] = '/path/to/something';
$current_url = largo_get_current_url();
$this->assertTrue((bool) preg_match('/^http:\/\//', $current_url));
$_SERVER['HTTPS'] = 'on';
$current_url = largo_get_current_url();
$this->assertTrue((bool) preg_match('/^https:\/\//', $current_url));
$_SERVER = $preserve;
}
}