Skip to content

Commit

Permalink
Issue #289: Converted WebTestCase fixture creation to FixtureBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
randi2kewl authored and ginatrapani committed Oct 5, 2010
1 parent eba9e46 commit 8b30b96
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 90 deletions.
1 change: 0 additions & 1 deletion tests/WebTestOfCaptchaImage.php
Expand Up @@ -34,7 +34,6 @@ class WebTestOfCaptchaImage extends ThinkUpWebTestCase {

public function setUp() {
parent::setUp();
self::buildData();
}

public function tearDown() {
Expand Down
3 changes: 2 additions & 1 deletion tests/WebTestOfCrawlerRun.php
Expand Up @@ -34,10 +34,11 @@ class WebTestOfCrawlerRun extends ThinkUpWebTestCase {

public function setUp() {
parent::setUp();
self::buildData();
$this->builders = self::buildData();
}

public function tearDown() {
$this->builders = null;
parent::tearDown();
}

Expand Down
5 changes: 2 additions & 3 deletions tests/WebTestOfDashboard.php
Expand Up @@ -31,14 +31,13 @@
require_once THINKUP_ROOT_PATH.'webapp/_lib/extlib/simpletest/web_tester.php';

class WebTestOfDashboard extends ThinkUpWebTestCase {

public function setUp() {
parent::setUp();

self::buildData();
$this->builders = self::buildData();
}

public function tearDown() {
$this->builders = null;
parent::tearDown();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/WebTestOfSignIn.php
Expand Up @@ -34,10 +34,11 @@ class WebTestOfSignIn extends ThinkUpWebTestCase {

public function setUp() {
parent::setUp();
self::buildData();
$this->builders = self::buildData();
}

public function tearDown() {
$this->builders = null;
parent::tearDown();
}

Expand Down
5 changes: 2 additions & 3 deletions tests/WebTestOfTwitterPluginViews.php
Expand Up @@ -34,11 +34,11 @@ class WebTestOfTwitterPluginViews extends ThinkUpWebTestCase {

public function setUp() {
parent::setUp();

self::buildData();
$this->builders = self::buildData();
}

public function tearDown() {
$this->builders = null;
parent::tearDown();
}

Expand All @@ -48,7 +48,6 @@ public function testDashboardWithPosts() {
$this->setField('pwd', 'secretpassword');

$this->click("Log In");
// $this->showSource();

$this->assertTitle("thinkupapp's Dashboard | ThinkUp");
$this->assertText('Logged in as: me@example.com');
Expand Down
143 changes: 62 additions & 81 deletions tests/classes/class.ThinkUpWebTestCase.php
Expand Up @@ -55,96 +55,80 @@ public function tearDown() {

/**
* Insert some test data to navigate the app
* @TODO Convert this to FixtureBuilder
*/
protected function buildData() {
$builders = array();

//Add owner
$session = new Session();
$cryptpass = $session->pwdcrypt("secretpassword");
$q = "INSERT INTO tu_owners (id, email, pwd, is_activated, is_admin) VALUES (1, 'me@example.com', '".
$cryptpass."', 1, 1)";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('owners', array('id'=>1, 'email'=>'me@example.com', 'pwd'=>$cryptpass,
'is_activated'=>1,'is_admin'=>1));

//Add instance
$q = "INSERT INTO tu_instances (id, network_user_id, network_username, is_public, network) VALUES (1, 17,
'thinkupapp', 1, 'twitter')";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('instances', array('id'=>1, 'network_user_id'=>17,
'network_username'=>'thinkupapp', 'is_public'=>1, 'network'=>'twitter'));

//Add instance_owner
$q = "INSERT INTO tu_owner_instances (owner_id, instance_id) VALUES (1, 1)";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('owner_instances', array('owner_id'=>1, 'instance_id'=>1));

//Insert test data into test table
$q = "INSERT INTO tu_users (user_id, user_name, full_name, avatar) VALUES (12, 'jack', 'Jack Dorsey',
'avatar.jpg');";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('users', array('user_id'=>12, 'user_name'=>'jack',
'full_name'=>'Jack Dorsey', 'avatar'=>'avatar.jpg', 'network'=>'twitter'));

$q = "INSERT INTO tu_users (user_id, user_name, full_name, avatar, last_updated, network) VALUES (13, 'ev',
'Ev Williams', 'avatar.jpg', '1/1/2005', 'twitter');";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('users', array('user_id'=>13, 'user_name'=>'ev',
'full_name'=>'Ev Williams', 'avatar'=>'avatar.jpg', 'last_updated'=>'1/1/2005', 'network'=>'twitter'));

$q = "INSERT INTO tu_users (user_id, user_name, full_name, avatar, is_protected) VALUES (16, 'private',
'Private Poster', 'avatar.jpg', 1);";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('users', array('user_id'=>16, 'user_name'=>'private',
'full_name'=>'Private Poster', 'avatar'=>'avatar.jpg', 'is_protected'=>1, 'network'=>'twitter'));

$q = "INSERT INTO tu_users (user_id, user_name, full_name, avatar, is_protected, follower_count, network)
VALUES (17, 'thinkupapp', 'ThinkUpers', 'avatar.jpg', 0, 10, 'twitter');";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('users', array('user_id'=>17, 'user_name'=>'thinkupapp',
'full_name'=>'ThinkUpers', 'avatar'=>'avatar.jpg', 'is_protected'=>0, 'follower_count'=>10,
'network'=>'twitter'));

$q = "INSERT INTO tu_users (user_id, user_name, full_name, avatar, is_protected, follower_count) VALUES (18,
'shutterbug', 'Shutter Bug', 'avatar.jpg', 0, 10);";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('users', array('user_id'=>18, 'user_name'=>'shutterbug',
'full_name'=>'Shutter Bug', 'avatar'=>'avatar.jpg', 'is_protected'=>0, 'follower_count'=>10,
'network'=>'twitter'));

$q = "INSERT INTO tu_users (user_id, user_name, full_name, avatar, is_protected, follower_count) VALUES (19,
'linkbaiter', 'Link Baiter', 'avatar.jpg', 0, 10);";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('users', array('user_id'=>19, 'user_name'=>'linkbaiter',
'full_name'=>'Link Baiter', 'avatar'=>'avatar.jpg', 'is_protected'=>0, 'follower_count'=>10,
'network'=>'twitter'));

$q = "INSERT INTO tu_user_errors (user_id, error_code, error_text, error_issued_to_user_id) VALUES (15, 404,
'User not found', 13);";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('user_errors', array('user_id'=>15, 'error_code'=>404,
'error_text'=>'User not found', 'error_issued_to_user_id'=>13));

$q = "INSERT INTO tu_follows (user_id, follower_id, last_seen) VALUES (13, 12, '1/1/2006');";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('follows', array('user_id'=>13, 'follower_id'=>12));

$q = "INSERT INTO tu_follows (user_id, follower_id, last_seen) VALUES (13, 14, '1/1/2006');";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('follows', array('user_id'=>13, 'follower_id'=>14));

$q = "INSERT INTO tu_follows (user_id, follower_id, last_seen) VALUES (13, 15, '1/1/2006');";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('follows', array('user_id'=>13, 'follower_id'=>15));

$q = "INSERT INTO tu_follows (user_id, follower_id, last_seen) VALUES (13, 16, '1/1/2006');";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('follows', array('user_id'=>13, 'follower_id'=>16));

$q = "INSERT INTO tu_follows (user_id, follower_id, last_seen) VALUES (16, 12, '1/1/2006');";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('follows', array('user_id'=>16, 'follower_id'=>12));

$q = "INSERT INTO tu_follows (user_id, follower_id, last_seen) VALUES (17, 13, '1/1/2006');";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('follows', array('user_id'=>19, 'follower_id'=>13));

$q = "INSERT INTO tu_follows (user_id, follower_id, last_seen) VALUES (18, 13, '1/1/2006');";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('follows', array('user_id'=>18, 'follower_id'=>13));

$q = "INSERT INTO tu_follows (user_id, follower_id, last_seen) VALUES (19, 13, '1/1/2006');";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('instances', array('network_user_id'=>13, 'network_username'=>'ev',
'is_public'=>1, 'network'=>'twitter'));

$q = "INSERT INTO tu_instances (network_user_id, network_username, is_public) VALUES (13, 'ev', 1);";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('instances', array('network_user_id'=>18,
'network_username'=>'shutterbug', 'is_public'=>1, 'network'=>'twitter'));

$q = "INSERT INTO tu_instances (network_user_id, network_username, is_public) VALUES (18, 'shutterbug', 1);";
$this->db->exec($q);

$q = "INSERT INTO tu_instances (network_user_id, network_username, is_public) VALUES (19, 'linkbaiter', 1);";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('instances', array('network_user_id'=>19,
'network_username'=>'linkbaiter', 'is_public'=>1, 'network'=>'twitter'));

$counter = 0;
while ($counter < 40) {
$reply_or_forward_count = $counter + 200;
$pseudo_minute = str_pad($counter, 2, "0", STR_PAD_LEFT);
$q = "INSERT INTO tu_posts (post_id, author_user_id, author_username, author_fullname, author_avatar,
post_text, source, pub_date, reply_count_cache, retweet_count_cache) VALUES ($counter, 13, 'ev',
'Ev Williams', 'avatar.jpg', 'This is post $counter', 'web', '2006-01-01 00:$pseudo_minute:00',
$reply_or_forward_count, $reply_or_forward_count);";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('posts', array('post_id'=>$counter, 'author_user_id'=>13,
'author_username'=>'ev', 'author_fullname'=>'Ev Williams', 'author_avatar'=>'avatar.jpg', 'source'=>'web',
'pub_date'=>'2006-01-01 00:$pseudo_minute:00', 'reply_count_cache'=>$reply_or_forward_count,
'retweet_count_cache'=>$reply_or_forward_count, 'post_text'=>'This is post '.$counter,
'network'=>'twitter'));

$counter++;
}
Expand All @@ -153,15 +137,14 @@ protected function buildData() {
while ($counter < 40) {
$post_id = $counter + 40;
$pseudo_minute = str_pad($counter, 2, "0", STR_PAD_LEFT);
$q = "INSERT INTO tu_posts (post_id, author_user_id, author_username, author_fullname, author_avatar,
post_text, source, pub_date, reply_count_cache, retweet_count_cache) VALUES ($post_id, 18, 'shutterbug',
'Shutter Bug', 'avatar.jpg', 'This is image post $counter', 'web',
'2006-01-02 00:$pseudo_minute:00', 0, 0);";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('posts', array('post_id'=>$post_id, 'author_user_id'=>18,
'author_username'=>'shutterbug', 'author_fullname'=>'Shutter Bug', 'author_avatar'=>'avatar.jpg',
'source'=>'web', 'pub_date'=>'2006-01-02 00:$pseudo_minute:00', 'reply_count_cache'=>0,
'retweet_count_cache'=>0, 'post_text'=>'This is image post '.$counter, 'network'=>'twitter'));

$q = "INSERT INTO tu_links (url, expanded_url, title, clicks, post_id, is_image)
VALUES ('http://example.com/".$counter."', 'http://example.com/".$counter.".jpg', '', 0, $post_id, 1);";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('links', array('url'=>'http://example.com/'.$counter,
'expanded_url'=>'http://example.com/'.$counter.'jpg', 'title'=>'', 'clicks'=>0, 'post_id'=>$post_id,
'is_image'=>1));

$counter++;
}
Expand All @@ -170,30 +153,28 @@ protected function buildData() {
while ($counter < 40) {
$post_id = $counter + 80;
$pseudo_minute = str_pad(($counter), 2, "0", STR_PAD_LEFT);
$q = "INSERT INTO tu_posts (post_id, author_user_id, author_username, author_fullname, author_avatar,
post_text, source, pub_date, reply_count_cache, retweet_count_cache) VALUES ($post_id, 19, 'linkbaiter',
'Link Baiter', 'avatar.jpg', 'This is link post $counter', 'web',
'2006-03-01 00:$pseudo_minute:00', 0, 0);";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('posts', array('post_id'=>$post_id, 'author_user_id'=>19,
'author_username'=>'linkbaiter', 'author_fullname'=>'Link Baiter', 'author_avatar'=>'avatar.jpg',
'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'));

$q = "INSERT INTO tu_links (url, expanded_url, title, clicks, post_id, is_image) VALUES
('http://example.com/".$counter."', 'http://example.com/".$counter.".html', 'Link $counter', 0,
$post_id, 0);";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('links', array('url'=>'http://example.com/'.$counter,
'expanded_url'=>'http://example.com/'.$counter.'html',
'title'=>'Link '.$counter, 'clicks'=>0, 'post_id'=>$post_id, 'is_image'=>0));

$counter++;
}
$counter = 0;
while ($counter < 10) {
$post_id = $counter + 120;
$pseudo_minute = str_pad(($counter), 2, "0", STR_PAD_LEFT);
$q = "INSERT INTO tu_posts (post_id, author_user_id, author_username, author_fullname, author_avatar,
post_text, source, pub_date, reply_count_cache, retweet_count_cache) VALUES ($post_id, 1234,
'thinkupapp', 'thinkupapp', 'avatar.jpg', 'This is test post $counter', 'web',
'2006-03-01 00:$pseudo_minute:00', 0, 0);";
$this->db->exec($q);
$builders[] = FixtureBuilder::build('posts', array('post_id'=>$post_id, 'author_user_id'=>1234,
'author_username'=>'thinkupapp', 'author_fullname'=>'thinkupapp', 'author_avatar'=>'avatar.jpg',
'post_text'=>'This is test post '.$counter, 'source'=>'web', 'pub_date'=>'2006-03-01 00:$pseudo_minute:00',
'reply_count_cache'=>0, 'retweet_count_cache'=>0, 'network'=>'twitter'));

$counter++;
}

return $builders;
}
}

0 comments on commit 8b30b96

Please sign in to comment.