Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…408 Closes #422
  • Loading branch information...
commit 643d2d8e61d12414fde47c988128d648b9c96214 1 parent 2fd3c74
Jaisen Mathai jmathai authored
15 src/tests/helpers/init.php
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));
+}*/
73 src/tests/helpers/mysql.php
View
@@ -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;
+ }
+}
9 src/tests/libraries/adapters/DatabaseMySqlTest.php
View
@@ -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
10 src/tests/libraries/adapters/DatabaseSimpleDbTest.php
View
@@ -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
{
10 src/tests/libraries/adapters/FileSystemLocalTest.php
View
@@ -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
{
9 src/tests/libraries/adapters/FileSystemS3Test.php
View
@@ -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
{
115 src/tests/libraries/models/UrlTest.php
View
@@ -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');
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.