Permalink
Browse files

Moving tests around so they can be run against different components. #…

…408 Closes #422
  • Loading branch information...
1 parent 2fd3c74 commit 643d2d8e61d12414fde47c988128d648b9c96214 @jmathai jmathai committed Jan 2, 2012
View
@@ -17,3 +17,18 @@ function getLogger()
{
return new ___L;
}
+
+/*function getBaseDir($file = null)
+{
+ if($file === null)
+ $file = __FILE__;
+
+ if(dirname($file) === $file)
+ return false; // we didn't find a 'src' direcory
+
+ echo "checking $file\n";
+ $dir = basename($file);
+ if($dir === 'src')
+ return $file;
+ return getBaseDir(dirname($file));
+}*/
@@ -0,0 +1,73 @@
+<?php
+class MySqlMockHelper
+{
+ public static function getPhoto($params = null)
+ {
+ $photo = array(
+ 'id' => 'foo',
+ 'exif' => '{"foo":"bar"}',
+ 'extra' => '{"foo":"bar"}',
+ 'tags' => 'one,two,three',
+ 'groups' => 'one,two,three'
+ );
+
+ if(!empty($params))
+ {
+ foreach($params as $key => $value)
+ $photo->{$key} = $value;
+ }
+ return $photo;
+ }
+
+ public static function getPhotos($count = 1, $params = null)
+ {
+ $photos = array();
+ for($i=0; $i<$count; $i++)
+ $photos[] = self::getPhoto($params);
+
+ return $photos;
+ }
+
+ public static function getTag($params = null)
+ {
+ $tag = array(
+ 'id' => 'foo',
+ 'exif' => '{"foo":"bar"}',
+ 'extra' => '{"foo":"bar"}',
+ 'tags' => 'one,two,three',
+ 'groups' => 'one,two,three'
+ );
+
+ if(!empty($params))
+ {
+ foreach($params as $key => $value)
+ $tag->{$key} = $value;
+ }
+ return $tag;
+ }
+
+ public static function getTags($count = 1, $params = null)
+ {
+ $tags = array();
+ for($i=0; $i<$count; $i++)
+ $tags[] = self::getTag($params);
+
+ return $tags;
+ }
+
+ public static function getUser($params = null)
+ {
+ $tag = array(
+ 'id' => 'foo',
+ 'lastPhotoId' => 'abc',
+ 'extra' => '{"foo":"bar"}'
+ );
+
+ if(!empty($params))
+ {
+ foreach($params as $key => $value)
+ $tag->{$key} = $value;
+ }
+ return $tag;
+ }
+}
@@ -1,8 +1,9 @@
<?php
-require_once 'helpers/init.php';
-require_once 'helpers/mysql.php';
-require_once './libraries/adapters/Database.php';
-require_once './libraries/adapters/DatabaseMySql.php';
+$baseDir = dirname(dirname(dirname(dirname(__FILE__))));
+require_once sprintf('%s/tests/helpers/init.php', $baseDir);
+require_once sprintf('%s/tests/helpers/mysql.php', $baseDir);
+require_once sprintf('%s/libraries/adapters/Database.php', $baseDir);
+require_once sprintf('%s/libraries/adapters/DatabaseMySql.php', $baseDir);
class DatabaseMySqlOverride extends DatabaseMySql
@@ -1,9 +1,9 @@
<?php
-require_once 'helpers/init.php';
-require_once 'helpers/mysql.php';
-require_once './libraries/adapters/Database.php';
-require_once './libraries/adapters/DatabaseSimpleDb.php';
-
+$baseDir = dirname(dirname(dirname(dirname(__FILE__))));
+require_once sprintf('%s/tests/helpers/init.php', $baseDir);
+require_once sprintf('%s/tests/helpers/mysql.php', $baseDir);
+require_once sprintf('%s/libraries/adapters/Database.php', $baseDir);
+require_once sprintf('%s/libraries/adapters/DatabaseSimpleDb.php', $baseDir);
class DatabaseSimpleDbOverride extends DatabaseSimpleDb
{
@@ -1,8 +1,12 @@
<?php
-require_once './helpers/init.php';
require_once 'vfsStream/vfsStream.php';
-require_once '../libraries/adapters/FileSystem.php';
-require_once '../libraries/adapters/FileSystemLocal.php';
+if(!class_exists('vfsStreamWrapper'))
+ return;
+
+$baseDir = dirname(dirname(dirname(dirname(__FILE__))));
+require_once sprintf('%s/tests/helpers/init.php', $baseDir);
+require_once sprintf('%s/libraries/adapters/FileSystem.php', $baseDir);
+require_once sprintf('%s/libraries/adapters/FileSystemLocal.php', $baseDir);
/*class FileSystemS3Override extends FileSystemS3
{
@@ -1,8 +1,9 @@
<?php
-require_once './helpers/init.php';
-require_once './helpers/aws.php';
-require_once '../libraries/adapters/FileSystem.php';
-require_once '../libraries/adapters/FileSystemS3.php';
+$baseDir = dirname(dirname(dirname(dirname(__FILE__))));
+require_once sprintf('%s/tests/helpers/init.php', $baseDir);
+require_once sprintf('%s/tests/helpers/aws.php', $baseDir);
+require_once sprintf('%s/libraries/adapters/FileSystem.php', $baseDir);
+require_once sprintf('%s/libraries/adapters/FileSystemS3.php', $baseDir);
class FileSystemS3Override extends FileSystemS3
{
@@ -0,0 +1,115 @@
+<?php
+$baseDir = dirname(dirname(dirname(dirname(__FILE__))));
+require_once sprintf('%s/tests/helpers/init.php', $baseDir);
+require_once sprintf('%s/libraries/models/Utility.php', $baseDir);
+require_once sprintf('%s/libraries/models/Url.php', $baseDir);
+
+class UrlTest extends PHPUnit_Framework_TestCase
+{
+ public function setUp()
+ {
+ ob_start();
+ $this->id = uniqid();
+ }
+
+ public function testActionCreate()
+ {
+ $url = Url::actionCreate($this->id, 'photo', false);
+ $this->assertEquals("/action/{$this->id}/photo/create", $url, 'Urls do not match');
+ Url::actionCreate($this->id, 'photo');
+ $url = ob_get_contents();
+ ob_clean();
+ $this->assertEquals("/action/{$this->id}/photo/create", $url, 'Urls do not match');
+ Url::actionCreate($this->id, 'photo', true);
+ $url = ob_get_contents();
+ ob_clean();
+ $this->assertEquals("/action/{$this->id}/photo/create", $url, 'Urls do not match');
+ }
+
+ public function testActionDelete()
+ {
+ $url = Url::actionDelete($this->id, false);
+ $this->assertEquals("/action/{$this->id}/delete", $url, 'Urls do not match');
+ Url::actionDelete($this->id);
+ $url = ob_get_contents();
+ ob_clean();
+ $this->assertEquals("/action/{$this->id}/delete", $url, 'Urls do not match');
+ Url::actionDelete($this->id, true);
+ $url = ob_get_contents();
+ ob_clean();
+ $this->assertEquals("/action/{$this->id}/delete", $url, 'Urls do not match');
+ }
+
+ public function testPhotoDelete()
+ {
+ $url = Url::photoDelete($this->id, false);
+ $this->assertEquals("/photo/{$this->id}/delete", $url, 'Urls do not match');
+ Url::photoDelete($this->id);
+ $url = ob_get_contents();
+ ob_clean();
+ $this->assertEquals("/photo/{$this->id}/delete", $url, 'Urls do not match');
+ Url::photoDelete($this->id, true);
+ $url = ob_get_contents();
+ ob_clean();
+ $this->assertEquals("/photo/{$this->id}/delete", $url, 'Urls do not match');
+ }
+
+ public function testPhotoEdit()
+ {
+ $url = Url::photoEdit($this->id, false);
+ $this->assertEquals("/photo/{$this->id}/edit", $url, 'Urls do not match');
+ Url::photoEdit($this->id);
+ $url = ob_get_contents();
+ ob_clean();
+ $this->assertEquals("/photo/{$this->id}/edit", $url, 'Urls do not match');
+ Url::photoEdit($this->id, true);
+ $url = ob_get_contents();
+ ob_clean();
+ $this->assertEquals("/photo/{$this->id}/edit", $url, 'Urls do not match');
+ }
+
+ public function testPhotoUpdate()
+ {
+ $url = Url::photoUpdate($this->id, false);
+ $this->assertEquals("/photo/{$this->id}/update", $url, 'Urls do not match');
+ Url::photoUpdate($this->id);
+ $url = ob_get_contents();
+ ob_clean();
+ $this->assertEquals("/photo/{$this->id}/update", $url, 'Urls do not match');
+ Url::photoUpdate($this->id, true);
+ $url = ob_get_contents();
+ ob_clean();
+ $this->assertEquals("/photo/{$this->id}/update", $url, 'Urls do not match');
+ }
+
+ public function testPhotoUrl()
+ {
+ $key = '30x30';
+ $val = uniqid();
+ $photo = array("path{$key}" => $val);
+ $url = Url::photoUrl($photo, $key, false);
+ $this->assertEquals($val, $url, 'Urls do not match');
+ Url::photoUrl($photo, $key);
+ $url = ob_get_contents();
+ ob_clean();
+ $this->assertEquals($val, $url, 'Urls do not match');
+ Url::photoUrl($photo, $key, true);
+ $url = ob_get_contents();
+ ob_clean();
+ $this->assertEquals($val, $url, 'Urls do not match');
+ }
+
+ public function testPhotoView()
+ {
+ $url = Url::photoView($this->id, null, false);
+ $this->assertEquals("/photo/{$this->id}/view", $url, 'Urls do not match');
+ Url::photoView($this->id);
+ $url = ob_get_contents();
+ ob_clean();
+ $this->assertEquals("/photo/{$this->id}/view", $url, 'Urls do not match');
+ Url::photoView($this->id, null, true);
+ $url = ob_get_contents();
+ ob_clean();
+ $this->assertEquals("/photo/{$this->id}/view", $url, 'Urls do not match');
+ }
+}

0 comments on commit 643d2d8

Please sign in to comment.