-
Notifications
You must be signed in to change notification settings - Fork 665
Expand file tree
/
Copy pathTestOfFavoritePostMySQLDAO.php
More file actions
705 lines (653 loc) · 22.1 KB
/
TestOfFavoritePostMySQLDAO.php
File metadata and controls
705 lines (653 loc) · 22.1 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
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
<?php
/**
*
* ThinkUp/tests/TestOfFavoritePostMySQLDAO.php
*
* Copyright (c) 2009-2013 Amy Unruh, Gina Trapani
*
* LICENSE:
*
* This file is part of ThinkUp (http://thinkup.com).
*
* ThinkUp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any
* later version.
*
* ThinkUp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with ThinkUp. If not, see
* <http://www.gnu.org/licenses/>.
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2013 Amy Unruh, Gina Trapani
* @author Amy Unruh
*/
require_once dirname ( __FILE__ ) . '/init.tests.php';
require_once THINKUP_WEBAPP_PATH . '_lib/extlib/simpletest/autorun.php';
require_once THINKUP_WEBAPP_PATH . 'config.inc.php';
require_once THINKUP_WEBAPP_PATH . 'plugins/twitter/model/class.TwitterPlugin.php';
require_once THINKUP_WEBAPP_PATH . 'plugins/facebook/model/class.FacebookPlugin.php';
class TestOfFavoritePostMySQLDAO extends ThinkUpUnitTestCase {
/**
*
* @var FavoritePostMySQLDAO
*/
protected $dao;
public function setUp() {
parent::setUp ();
$config = Config::getInstance ();
$this->builders = self::buildData ();
$this->dao = new FavoritePostMySQLDAO ();
}
protected function buildData() {
$builders = array ();
$builders [] = FixtureBuilder::build ( 'owner_instances', array (
'owner_id' => 1,
'instance_id' => 1
) );
$builders [] = FixtureBuilder::build ( 'users', array (
'user_id' => 13,
'user_name' => 'ev',
'full_name' => 'Ev Williams',
'avatar' => 'avatar.jpg',
'is_protected' => 0,
'follower_count' => 10,
'last_updated' => '2005-01-01 13:48:05',
'network' => 'twitter'
) );
$builders [] = FixtureBuilder::build ( 'users', array (
'user_id' => 19,
'user_name' => 'linkbaiter',
'full_name' => 'Link Baiter',
'avatar' => 'avatar.jpg',
'is_protected' => 0,
'follower_count' => 70,
'network' => 'twitter'
) );
$builders [] = FixtureBuilder::build ( 'users', array (
'user_id' => 20,
'user_name' => 'user1',
'full_name' => 'User 1',
'avatar' => 'avatar.jpg',
'is_protected' => 0,
'follower_count' => 90,
'network' => 'twitter'
) );
// protected user
$builders [] = FixtureBuilder::build ( 'users', array (
'user_id' => 21,
'user_name' => 'user2',
'full_name' => 'User 2',
'avatar' => 'avatar.jpg',
'is_protected' => 1,
'follower_count' => 80,
'network' => 'twitter'
) );
$builders [] = FixtureBuilder::build ( 'users', array (
'user_id' => 22,
'user_name' => 'quoter',
'full_name' => 'Quotables',
'is_protected' => 0,
'follower_count' => 80,
'network' => 'twitter'
) );
$builders [] = FixtureBuilder::build ( 'users', array (
'user_id' => 23,
'user_name' => 'user3',
'full_name' => 'User 3',
'is_protected' => 0,
'follower_count' => 100,
'network' => 'twitter'
) );
$builders [] = FixtureBuilder::build ( 'users', array (
'user_id' => 24,
'user_name' => 'notonpublictimeline',
'full_name' => 'Not on Public Timeline',
'is_protected' => 1,
'network' => 'twitter',
'follower_count' => 100
) );
// Make public
$builders [] = FixtureBuilder::build ( 'instances', array (
'network_user_id' => 13,
'network_username' => 'ev',
'is_public' => 1,
'network' => 'twitter'
) );
$builders [] = FixtureBuilder::build ( 'instances', array (
'network_user_id' => 19,
'network_username' => 'linkbaiter',
'is_public' => 1,
'network' => 'twitter'
) );
$builders [] = FixtureBuilder::build ( 'instances', array (
'network_user_id' => 23,
'network_username' => 'user3',
'is_public' => 1,
'network' => 'twitter'
) );
$builders [] = FixtureBuilder::build ( 'instances', array (
'network_user_id' => 24,
'network_username' => 'notonpublictimeline',
'is_public' => 0,
'network' => 'twitter'
) );
// Add straight text posts from ev
$counter = 0;
while ( $counter < 40 ) {
$pseudo_minute = str_pad ( $counter, 2, "0", STR_PAD_LEFT );
if ($counter % 3 == 0) {
$source = '<a href="http://twitter.com" rel="nofollow">Tweetie for Mac</a>';
} else if ($counter % 3 == 1) {
$source = '<a href="http://twitter.com/tweetbutton" rel="nofollow">Tweet Button</a>';
} else {
$source = 'web';
}
$is_protected = $counter == 18 ? 1 : 0; // post with id 18 is protected
$builders [] = FixtureBuilder::build ( 'posts', array (
'post_id' => $counter,
'author_user_id' => 13,
'author_username' => 'ev',
'author_fullname' => 'Ev Williams',
'author_avatar' => 'avatar.jpg',
'post_text' => 'This is post ' . $counter,
'source' => $source,
'pub_date' => '2006-01-01 00:' . $pseudo_minute . ':00',
'reply_count_cache' => rand ( 0, 4 ),
'retweet_count_cache' => 5,
'network' => 'twitter',
'in_reply_to_post_id' => null,
'in_retweet_of_post_id' => null,
'is_geo_encoded' => 0,
'is_protected' => $is_protected
) );
$counter ++;
}
// Add link posts from 'linkbaiter'
$counter = 0;
while ( $counter < 40 ) {
$post_id = $counter + 80;
$is_protected = $counter == 18 ? 1 : 0; // post with id 18 is protected
$pseudo_minute = str_pad ( ($counter), 2, "0", STR_PAD_LEFT );
$builders [] = FixtureBuilder::build ( 'posts', array (
'post_id' => $post_id,
'author_user_id' => 19,
'author_username' => 'linkbaiter',
'author_fullname' => 'Link Baiter',
'is_geo_encoded' => 0,
'post_text' => 'This is link post ' . $counter,
'source' => 'web',
'pub_date' => '2006-03-01 00:' . $pseudo_minute . ':00',
'reply_count_cache' => 0,
'retweet_count_cache' => 0,
'network' => 'twitter',
'is_protected' => $is_protected
) );
$builders [] = FixtureBuilder::build ( 'links', array (
'url' => 'http://example.com/' . $counter,
'explanded_url' => 'http://example.com/' . $counter . '.html',
'title' => 'Link $counter',
'clicks' => 0,
'post_id' => $post_id,
'image_src' => ''
) );
$counter ++;
}
$builders [] = FixtureBuilder::build ( 'posts', array (
'post_id' => 10822735852740608,
'author_user_id' => 23,
'author_username' => 'user3',
'author_fullname' => 'User 3',
'network' => 'twitter',
'post_text' => '@nytimes has posted an interactive panoramic photo that shows how Times Square has changed over' . ' the last 20 years http://nyti.ms/hmTVzP',
'source' => 'web',
'pub_date' => '-300s',
'reply_count_cache' => 0,
'retweet_count_cache' => 0,
'location' => 'New York City',
'is_geo_encoded' => 0,
'is_protected' => 0
) );
// have 'user1' favorite some of ev's posts
for($i = 0; $i < 20; $i ++) {
$builders [] = FixtureBuilder::build ( 'favorites', array (
'post_id' => $i,
'author_user_id' => 13,
'fav_of_user_id' => 20,
'network' => 'twitter'
) );
}
// have 'user1' favorite some linkbaiter posts
for($i = 80; $i < 100; $i ++) {
$builders [] = FixtureBuilder::build ( 'favorites', array (
'post_id' => $i,
'author_user_id' => 19,
'fav_of_user_id' => 20,
'network' => 'twitter'
) );
}
// have 'user2' favorite one of the same linkbaiter posts
$builders [] = FixtureBuilder::build ( 'favorites', array (
'post_id' => 87,
'author_user_id' => 19,
'fav_of_user_id' => 21,
'network' => 'twitter'
) );
return $builders;
}
public function tearDown() {
$this->builders = null;
parent::tearDown ();
}
/**
* Test constructor both directly and via factory
*/
public function testConstructor() {
$dao = new FavoritePostMySQLDAO ();
$this->assertTrue ( isset ( $dao ) );
$dao = DAOFactory::getDAO ( 'FavoritePostDAO' );
$this->assertTrue ( isset ( $dao ) );
}
/**
* Test creation of fav post, where the post has not yet been saved to database.
*/
public function testAddFavoriteFullPost() {
$favoriter_id = 21; // user 2
$vals = $this->buildPostArray1 ();
$res = $this->dao->addFavorite ( $favoriter_id, $vals );
$this->assertEqual ( $res, 1 );
}
public function testAddFavoriteMissingPostData() {
$favoriter_id = 21; // user 2
$vals = $this->buildFavoriteArray ();
$this->expectException ( 'Exception', 'Error: Favorited post ID 345840895515801 is not in storage and could not be inserted.' );
$res = $this->dao->addFavorite ( $favoriter_id, $vals );
$this->assertEqual ( $res, 1 );
}
/**
* Test creation of fav post, where post already exists in db, but not favorite bookkeeping,
* and so we are just adding an entry to the favorites table.
*/
public function testAddFavoritePostExists() {
$favoriter_id = 21; // user 2
$vals = $this->buildPostArray2 ();
$res = $this->dao->addFavorite ( $favoriter_id, $vals );
$this->assertEqual ( $res, 1 );
// now try again-- this time the 'add' should return 0
$res = $this->dao->addFavorite ( $favoriter_id, $vals );
$this->assertEqual ( $res, 0 );
}
/**
* Test unfavoriting of fav'd post
*/
public function testFavPostUnfav() {
$res = $this->dao->unFavorite ( 81, 20, 'twitter' );
$this->assertEqual ( $res, 1 );
}
/**
* Test attempted unfav of a post that is favorited, but not by the given user
*/
public function testNonFavPostUnfav() {
$res = $this->dao->unFavorite ( 82, 19, 'twitter' );
$this->assertEqual ( $res, 0 );
}
/**
* Check unfavoriting the same post by multiple users
*/
public function testMultipleFavsOfPost() {
$this->dao = new FavoritePostMySQLDAO ();
$res = $this->dao->unFavorite ( 87, 20, 'twitter' );
$this->assertEqual ( $res, 1 );
$res = $this->dao->unFavorite ( 87, 21, 'twitter' );
$this->assertEqual ( $res, 1 );
$res = $this->dao->unFavorite ( 87, 20, 'twitter' );
$this->assertEqual ( $res, 0 );
}
/**
* Test fetch of N favorited posts for a given user by userid
*/
public function testGetAllFavsForUserID() {
$this->dao = new FavoritePostMySQLDAO ();
$res = $this->dao->getAllFavoritePosts ( 20, 'twitter', 6, 1, false ); // not public
$this->assertIsA ( $res, "array" );
$this->assertEqual ( count ( $res ), 6 );
$this->assertEqual ( $res [0]->post_text, 'This is link post 19' );
$this->assertEqual ( $res [1]->post_text, 'This is link post 18' );
$i = 0;
while ( $i < 6 ) {
$this->debug ( $res [$i]->post_text );
$i ++;
}
// just check that we get the same result w/out the explicit arg
$res = $this->dao->getAllFavoritePosts ( 20, 'twitter', 6 ); // not public
$this->assertIsA ( $res, "array" );
$this->assertEqual ( count ( $res ), 6 );
$this->assertEqual ( $res [0]->post_text, 'This is link post 19' );
$this->assertEqual ( $res [1]->post_text, 'This is link post 18' );
// iterator
$res = $this->dao->getAllFavoritePostsIterator ( 20, 'twitter', 6 );
$this->assertIsA ( $res, "PostIterator" );
$i = 0;
while ( $i < 6 ) {
$this->assertTrue ( $res->valid () );
$seeme = $res->current ();
$this->debug ( $seeme->post_text );
$res->next ();
$i ++;
}
$this->assertFalse ( $res->valid () );
}
/**
* Test fetch of N favorited posts for a given user by userid, but where public = true.
* post with id 18 should not be fetched this time
*/
public function testGetAllFavsForUserID2() {
$this->dao = new FavoritePostMySQLDAO ();
$res = $this->dao->getAllFavoritePosts ( 20, 'twitter', 6, 1, true ); // public
$this->assertIsA ( $res, "array" );
$this->assertEqual ( count ( $res ), 6 );
$this->assertEqual ( $res [0]->post_text, 'This is link post 19' );
$this->assertEqual ( $res [1]->post_text, 'This is link post 17' );
$i = 0;
while ( $i < 6 ) {
$this->debug ( $res [$i]->post_text );
$i ++;
}
}
/**
* Test fetch of all favorited posts for a given user by username
*/
public function testGetAllFavsForUsername() {
$dao = new FavoritePostMySQLDAO ();
$res = $this->dao->getAllFavoritePostsByUsername ( 'user1', 'twitter', 100 );
$this->assertIsA ( $res, "array" );
$this->assertEqual ( count ( $res ), 40 );
// iterator
$res = $this->dao->getAllFavoritePostsByUsernameIterator ( 'user1', 'twitter', 100 );
$this->assertIsA ( $res, "PostIterator" );
$i = 0;
while ( $i < 40 ) {
$this->assertTrue ( $res->valid () );
$res->next ();
$i ++;
}
$this->assertFalse ( $res->valid () );
}
/**
* Test fetch of all favorited posts for a given user with post # less than a given upper bound.
*/
public function testGetAllFavsForUserUpperBound() {
$res = $this->dao->getAllFavoritePostsUpperBound ( 20, 'twitter', 100, 10 );
$this->assertIsA ( $res, "array" );
$this->assertEqual ( count ( $res ), 10 );
}
/**
* Test pagination
*/
public function testFavoritesPagination() {
$res = $this->dao->getAllFavoritePosts ( 20, 'twitter', 10, 3 ); // fetch page 3
$this->assertIsA ( $res, "array" );
$this->assertEqual ( count ( $res ), 10 );
$this->assertEqual ( $res [0]->post_text, 'This is post 19' );
}
/**
* test fetch of all posts of a given owner that have been favorited by others
*/
public function testGetAllFavoritedPosts() {
$res = $this->dao->getAllFavoritedPosts ( 19, 'twitter', 30 );
$this->assertIsA ( $res, "array" );
$this->assertEqual ( count ( $res ), 20 );
$this->assertEqual ( $res [0]->post_text, 'This is link post 7' );
$this->assertEqual ( $res [1]->post_text, 'This is link post 19' );
}
/**
* test fetch of information for all users who have favorited a given post
*/
public function testGetFavdsOfPost() {
$res = $this->dao->getUsersWhoFavedPost ( 87 ); // twitter is default network
$this->assertIsA ( $res, "array" );
$this->assertEqual ( count ( $res ), 2 );
$res = $this->dao->getUsersWhoFavedPost ( 87, 'twitter', true );
$this->assertIsA ( $res, "array" );
$this->assertEqual ( count ( $res ), 2 );
}
public function testGetFavoritesFromOneYearAgo() {
// build post published one year ago today
$builders [] = FixtureBuilder::build ( 'posts', array (
'post_id' => 'abadadfd1212',
'author_user_id' => '19',
'author_username' => 'linkbaiter',
'author_fullname' => 'Link Baiter',
'is_geo_encoded' => 0,
'post_text' => 'This is link post ' . $counter,
'source' => 'web',
'pub_date' => '-365d',
'reply_count_cache' => 0,
'retweet_count_cache' => 0,
'network' => 'twitter',
'is_protected' => 0
) );
// build favorite of that post by test user ev
$builders [] = FixtureBuilder::build ( 'favorites', array (
'post_id' => 'abadadfd1212',
'author_user_id' => '19',
'fav_of_user_id' => '13',
'network' => 'twitter'
) );
// get favorites from one year ago today
$result = $this->dao->getFavoritesFromOneYearAgo ( '13', 'twitter' );
// assert post is returned
$this->assertEqual ( sizeof ( $result ), 1 );
$this->assertEqual ( $result [0]->post_id, 'abadadfd1212' );
// build post published one year and 4 days ago today
$builders [] = FixtureBuilder::build ( 'posts', array (
'post_id' => 'abadadfd1213',
'author_user_id' => '19',
'author_username' => 'linkbaiter',
'author_fullname' => 'Link Baiter',
'is_geo_encoded' => 0,
'post_text' => 'This is link post ' . $counter,
'source' => 'web',
'pub_date' => '-369d',
'reply_count_cache' => 0,
'retweet_count_cache' => 0,
'network' => 'twitter',
'is_protected' => 0
) );
// build favorite of that post by test user ev
$builders [] = FixtureBuilder::build ( 'favorites', array (
'post_id' => 'abadadfd1213',
'author_user_id' => '19',
'fav_of_user_id' => '13',
'network' => 'twitter'
) );
$since_date = date ( "Y-m-d", strtotime ( "-4 day" ) );
// get favorites from one year ago today
$result = $this->dao->getFavoritesFromOneYearAgo ( '13', 'twitter', $since_date );
// assert post is returned
$this->assertEqual ( sizeof ( $result ), 1 );
$this->assertEqual ( $result [0]->post_id, 'abadadfd1213' );
}
public function testGetUsersWhoFavoritedMostOfYourPosts() {
// build post published 3 days ago
$builders [] = FixtureBuilder::build ( 'posts', array (
'post_id' => 'abadadfd1212',
'author_user_id' => '19',
'author_username' => 'linkbaiter',
'author_fullname' => 'Link Baiter',
'is_geo_encoded' => 0,
'post_text' => 'This is link post ' . $counter,
'source' => 'web',
'pub_date' => '-3d',
'reply_count_cache' => 0,
'retweet_count_cache' => 0,
'network' => 'twitter',
'is_protected' => 0
) );
// build post published 4 days ago
$builders [] = FixtureBuilder::build ( 'posts', array (
'post_id' => 'abadadfd1213',
'author_user_id' => '19',
'author_username' => 'linkbaiter',
'author_fullname' => 'Link Baiter',
'is_geo_encoded' => 0,
'post_text' => 'This is link post ' . $counter,
'source' => 'web',
'pub_date' => '-4d',
'reply_count_cache' => 0,
'retweet_count_cache' => 0,
'network' => 'twitter',
'is_protected' => 0
) );
// build favorite of those posts by test user ev
$builders [] = FixtureBuilder::build ( 'favorites', array (
'post_id' => 'abadadfd1212',
'author_user_id' => '19',
'fav_of_user_id' => '13',
'network' => 'twitter'
) );
$builders [] = FixtureBuilder::build ( 'favorites', array (
'post_id' => 'abadadfd1213',
'author_user_id' => '19',
'fav_of_user_id' => '13',
'network' => 'twitter'
) );
// build favorite of that post by test user user1
$builders [] = FixtureBuilder::build ( 'favorites', array (
'post_id' => 'abadadfd1212',
'author_user_id' => '19',
'fav_of_user_id' => '20',
'network' => 'twitter'
) );
// build favorite of that post by test user user2
$builders [] = FixtureBuilder::build ( 'favorites', array (
'post_id' => 'abadadfd1212',
'author_user_id' => '19',
'fav_of_user_id' => '21',
'network' => 'twitter'
) );
$result = $this->dao->getUsersWhoFavoritedMostOfYourPosts ( '19', 'twitter', 7 );
$this->debug ( Utils::varDumpToString ( $result ) );
$this->assertEqual ( sizeof ( $result ), 1 );
$this->assertEqual ( $result [0]->username, 'ev' );
}
public function testGetGenderOfFavoriters() {
$builders [] = FixtureBuilder::build ( 'favorites', array (
'post_id' => 111,
'fav_of_user_id' => 133,
'network' => 'facebook'
) );
$builders [] = FixtureBuilder::build ( 'favorites', array (
'post_id' => 111,
'fav_of_user_id' => 193,
'network' => 'facebook'
) );
$builders [] = FixtureBuilder::build ( 'favorites', array (
'post_id' => 111,
'fav_of_user_id' => 203,
'network' => 'facebook'
) );
$builders [] = FixtureBuilder::build ( 'favorites', array (
'post_id' => 222,
'fav_of_user_id' => 203,
'network' => 'facebook'
) );
$builders [] = FixtureBuilder::build ( 'users', array (
'user_id' => 133,
'gender'=>'male'
) );
$builders [] = FixtureBuilder::build ( 'users', array (
'user_id' => 193,
'gender'=>'male'
) );
$builders [] = FixtureBuilder::build ( 'users', array (
'user_id' => 203,
'gender'=>'female'
) );
$result = $this->dao->getGenderOfFavoriters ( '111');
$this->debug ( Utils::varDumpToString ( $result ) );
$this->assertEqual ( $result ['female_likes_count'] , '1' );
$this->assertEqual ( $result ['male_likes_count'], '2' );
}
public function testGetGenderOfCommenters() {
$builders [] = FixtureBuilder::build ( 'posts', array (
'post_id' => 'abadadfd12123',
'author_user_id' => '203',
'in_reply_to_post_id' => '111'
) );
$builders [] = FixtureBuilder::build ( 'posts', array (
'post_id' => 'abadad',
'author_user_id' => '193',
'in_reply_to_post_id' => '111'
) );
$builders [] = FixtureBuilder::build ( 'posts', array (
'post_id' => 'd12123',
'author_user_id' => '133',
'in_reply_to_post_id' => '111'
) );
$builders [] = FixtureBuilder::build ( 'posts', array (
'post_id' => 'abawertyfd12123',
'author_user_id' => '203',
'in_reply_to_post_id' => '222'
) );
$builders [] = FixtureBuilder::build ( 'users', array (
'user_id' => 133,
'gender'=>'male'
) );
$builders [] = FixtureBuilder::build ( 'users', array (
'user_id' => 193,
'gender'=>'male'
) );
$builders [] = FixtureBuilder::build ( 'users', array (
'user_id' => 203,
'gender'=>'female'
) );
$result = $this->dao->getGenderOfCommenters ( '111' );
$this->debug ( Utils::varDumpToString ( $result ) );
$this->assertEqual ( $result ['female_comm_count'] , '1' );
$this->assertEqual ( $result ['male_comm_count'], '2' );
}
/**
* helper method to build a post
*/
private function buildPostArray1() {
$vals = array ();
$vals ['post_id'] = '2904';
$vals ['author_username'] = 'quoter';
$vals ['author_fullname'] = "Quoter of Quotables";
$vals ['author_avatar'] = 'avatar.jpg';
$vals ['author_user_id'] = 22;
$vals ['post_text'] = "Go confidently in the direction of your dreams! Live the life you've imagined.";
$vals ['pub_date'] = '3/1/2010';
$vals ['source'] = 'web';
$vals ['network'] = 'twitter';
$vals ['is_protected'] = 0;
return $vals;
}
/**
* helper method to build a post
*/
private function buildPostArray2() {
$vals = array ();
$vals ['post_id'] = '10822735852740608';
$vals ['author_username'] = 'user3';
$vals ['author_fullname'] = "User 3";
$vals ['author_avatar'] = 'avatar.jpg';
$vals ['author_user_id'] = 23;
$vals ['post_text'] = "@nytimes has posted an interactive panoramic photo that shows how Times Square has " . "changed over the last 20 years http://nyti.ms/hmTVzP";
$vals ['pub_date'] = '-200s';
$vals ['source'] = 'web';
$vals ['network'] = 'twitter';
$vals ['is_protected'] = 0;
return $vals;
}
private function buildFavoriteArray() {
$vals = array ();
$vals ["favoriter_id"] = "1075560752";
$vals ["network"] = "facebook page";
$vals ["author_user_id"] = "340319429401281";
$vals ["post_id"] = "345840895515801";
return $vals;
}
}