Skip to content

Commit

Permalink
Merge pull request #52 from ghousseyn/alpha
Browse files Browse the repository at this point in the history
Beta RC 1
  • Loading branch information
ghousseyn committed Aug 20, 2014
2 parents e474e34 + 8f67e70 commit c308728
Show file tree
Hide file tree
Showing 19 changed files with 1,421 additions and 1,002 deletions.
75 changes: 24 additions & 51 deletions Tests/library/oosql/oosqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function setUp()
public function testSelect()
{
$return = $this->invokeMethod($this->oosql, 'select');
$sql = $this->getProperty($this->oosql, 'oosql_sql');
$sql = $this->invokeMethod($this->oosql, 'sql');
$flag = $this->getProperty($this->oosql, 'oosql_fromFlag');
$select = $this->getProperty($this->oosql, 'oosql_select');
$this->assertEquals('SELECT table.* ', $sql);
Expand All @@ -30,7 +30,7 @@ public function testSelect()
public function testSelectColumnsSpecified()
{
$return = $this->invokeMethod($this->oosql, 'select',array('column1','column2'));
$sql = $this->getProperty($this->oosql, 'oosql_sql');
$sql = $this->invokeMethod($this->oosql, 'sql');
$flag = $this->getProperty($this->oosql, 'oosql_fromFlag');
$select = $this->getProperty($this->oosql, 'oosql_select');
$this->assertEquals('SELECT column1,column2', $sql);
Expand All @@ -41,14 +41,14 @@ public function testSelectColumnsSpecified()
public function testInsert()
{
$return = $this->invokeMethod($this->oosql, 'insert');
$sql = $this->getProperty($this->oosql, 'oosql_sql');
$sql = $this->invokeMethod($this->oosql, 'sql');
$this->assertEquals('INSERT INTO table', $sql);
$this->assertInstanceOf('Phiber\\oosql\\oosql', $return);
}
public function testInsertColumnsSpecified()
{
$return = $this->invokeMethod($this->oosql, 'insert',array('column1','column2'));
$sql = $this->getProperty($this->oosql, 'oosql_sql');
$sql = $this->invokeMethod($this->oosql, 'sql');
$numargs = $this->getProperty($this->oosql, 'oosql_numargs');
$this->assertEquals(2, $numargs);
$this->assertEquals('INSERT INTO table (column1,column2)', $sql);
Expand All @@ -57,7 +57,7 @@ public function testInsertColumnsSpecified()
public function testUpdate()
{
$return = $this->invokeMethod($this->oosql, 'update');
$sql = $this->getProperty($this->oosql, 'oosql_sql');
$sql = $this->invokeMethod($this->oosql, 'sql');
$flag = $this->getProperty($this->oosql, 'oosql_multiFlag');
$this->assertFalse($flag);
$this->assertEquals('UPDATE table SET ', $sql);
Expand All @@ -66,7 +66,7 @@ public function testUpdate()
public function testUpdateMultiple()
{
$return = $this->invokeMethod($this->oosql, 'update',array('table1', 'table2'));
$sql = $this->getProperty($this->oosql, 'oosql_sql');
$sql = $this->invokeMethod($this->oosql, 'sql');
$flag = $this->getProperty($this->oosql, 'oosql_multiFlag');
$this->assertTrue($flag);
$this->assertEquals('UPDATE table1, table2 SET ', $sql);
Expand All @@ -75,29 +75,17 @@ public function testUpdateMultiple()
public function testDelete()
{
$return = $this->invokeMethod($this->oosql, 'delete');
$sql = $this->getProperty($this->oosql, 'oosql_sql');
$sql = $this->invokeMethod($this->oosql, 'sql');
$flag = $this->getProperty($this->oosql, 'oosql_fromFlag');
$this->assertTrue($flag);
$this->assertEquals('DELETE', $sql);
$this->assertInstanceOf('Phiber\\oosql\\oosql', $return);
}
public function testDeleteMulti()
{
$return = $this->invokeMethod($this->oosql, 'delete',array('table1','table2'));
$sql = $this->getProperty($this->oosql, 'oosql_sql');
$flagFrom = $this->getProperty($this->oosql, 'oosql_fromFlag');
$flagMulti = $this->getProperty($this->oosql, 'oosql_del_multiFlag');
$flagArgs = $this->getProperty($this->oosql, 'oosql_del_numargs');
$this->assertFalse($flagFrom);
$this->assertTrue($flagMulti);
$this->assertEquals(2,$flagArgs);
$this->assertEquals('DELETE FROM table1, table2', $sql);
$this->assertInstanceOf('Phiber\\oosql\\oosql', $return);
}

public function testDeleteShortCut()
{
$return = $this->invokeMethod($this->oosql, 'delete',array(array('id',1)));
$sql = $this->getProperty($this->oosql, 'oosql_sql');
$sql = $this->invokeMethod($this->oosql, 'sql');
$flag = $this->getProperty($this->oosql, 'oosql_fromFlag');
$value = $this->getProperty($this->oosql, 'oosql_conValues');
$this->assertFalse($flag);
Expand All @@ -110,7 +98,7 @@ public function testSet()
$data = array('field1'=>'value','field2'=>12);
$this->invokeMethod($this->oosql, 'update');
$return = $this->invokeMethod($this->oosql, 'set', array($data));
$sql = $this->getProperty($this->oosql, 'oosql_sql');
$sql = $this->invokeMethod($this->oosql, 'sql');
$values = $this->getProperty($this->oosql, 'oosql_conValues');

$this->assertEquals('UPDATE table SET field1 = ?,field2 = ?', $sql);
Expand Down Expand Up @@ -152,7 +140,7 @@ public function testCreateAndWhere()
}
/**
* @expectedException Exception
* @expectedExceptionCode 9807
* @expectedExceptionCode 9809
*/
public function testValuesNoArgs()
{
Expand All @@ -161,7 +149,7 @@ public function testValuesNoArgs()

/**
* @expectedException Exception
* @expectedExceptionCode 9807
* @expectedExceptionCode 9809
*/
public function testValuesArgsNotMatching()
{
Expand All @@ -172,7 +160,7 @@ public function testValues()
{
$this->invokeMethod($this->oosql,'insert', array('field1','field2'));
$return = $this->invokeMethod($this->oosql, 'values',array('value1',3));
$sql = $this->getProperty($this->oosql, 'oosql_sql');
$sql = $this->invokeMethod($this->oosql, 'sql');
$values = $this->getProperty($this->oosql, 'oosql_conValues');
$flag = $this->getProperty($this->oosql, 'oosql_fromFlag');

Expand All @@ -182,30 +170,22 @@ public function testValues()
$this->assertcontains(3,$values);
$this->assertInstanceOf('Phiber\\oosql\\oosql', $return);
}
/**
* @expectedException Exception
* @expectedExceptionCode 9807
*/
public function testFromArgsNotMatching()
{
$this->invokeMethod($this->oosql,'delete', array('field1','field2'));
$this->invokeMethod($this->oosql, 'from',array('table1'));
}

public function testFromWithArgs()
{
$return = $this->invokeMethod($this->oosql, 'from',array('table1','table2'));

$sql = $this->getProperty($this->oosql, 'oosql_sql');
$sql = $this->invokeMethod($this->oosql, 'sql');
$flag = $this->getProperty($this->oosql, 'oosql_fromFlag');
$this->assertEquals(' FROM table1, table2', $sql);
$this->assertEquals(' FROM table, table1, table2', $sql);
$this->assertFalse($flag);
$this->assertInstanceOf('Phiber\\oosql\\oosql', $return);
}
public function testFromNoArgs()
{
$return = $this->invokeMethod($this->oosql, 'from');

$sql = $this->getProperty($this->oosql, 'oosql_sql');
$sql = $this->invokeMethod($this->oosql, 'sql');
$flag = $this->getProperty($this->oosql, 'oosql_fromFlag');
$this->assertEquals(' FROM table', $sql);
$this->assertFalse($flag);
Expand Down Expand Up @@ -279,11 +259,11 @@ public function testOrWhere()
}
public function testValidInteger()
{
$return1 = $this->invokeMethod($this->oosql, 'valid_int',array(1.2304e6));
$return2 = $this->invokeMethod($this->oosql, 'valid_int',array(16));
$return3 = $this->invokeMethod($this->oosql, 'valid_int',array('16'));
$return4 = $this->invokeMethod($this->oosql, 'valid_int',array('1.2304e6'));
$return5 = $this->invokeMethod($this->oosql, 'valid_int',array(16.2));
$return1 = $this->invokeMethod($this->oosql, 'validInt',array(1.2304e6));
$return2 = $this->invokeMethod($this->oosql, 'validInt',array(16));
$return3 = $this->invokeMethod($this->oosql, 'validInt',array('16'));
$return4 = $this->invokeMethod($this->oosql, 'validInt',array('1.2304e6'));
$return5 = $this->invokeMethod($this->oosql, 'validInt',array(16.2));

$this->assertTrue($return1);
$this->assertTrue($return2);
Expand All @@ -293,20 +273,13 @@ public function testValidInteger()
}
/**
* @expectedException InvalidArgumentException
* @expectedExceptionCode 9808
* @expectedExceptionCode 9812
*/
public function testFetchWrongArgs()
{
$this->invokeMethod($this->oosql, 'fetch',array(0,1,2));
}
/**
* @expectedException Exception
* @expectedExceptionCode 9809
*/
public function testFetchNoResults()
{
$this->invokeMethod($this->oosql, 'fetch');
}

public function testLimit()
{
$return = $this->invokeMethod($this->oosql, 'limit',array(0,10));
Expand Down
86 changes: 6 additions & 80 deletions Tests/library/phiberTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

require_once 'Tests/PhiberTests.php';
require_once 'library/wire.php';
require_once 'library/phiber.php';

class phiberTest extends PhiberTests
Expand All @@ -22,7 +23,7 @@ public function setUp(){

public function testIsValidURI($uri,$out)
{
$this->invokeMethod($this->main,'isValidURI',array(&$uri));
$uri = $this->invokeMethod($this->main,'uriNormalize',array($uri));
$this->assertEquals($uri,$out);

}
Expand All @@ -38,13 +39,7 @@ public function testIsNotValidURI($uri)
$this->assertFalse($return);
}

public function testGetView(){

$route = array('module' => 'default', 'controller' => 'index', 'action' => 'main');
$this->invokeMethod($this->main,'register',array('route',$route));
$this->invokeMethod($this->main,'getView');
$this->assertEquals('application'.DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.'index'.DIRECTORY_SEPARATOR.'main.php',$this->main->view->viewPath);
}

public function testGet()
{
$value = 'test';
Expand All @@ -53,39 +48,14 @@ public function testGet()
$return = $this->invokeMethod($this->main,'get',array($index));
$this->assertEquals($return, $value);
}
public function test_request()
{
$this->invokeMethod($this->main,'register',array('_request',array('var1'=>'val1','var2'=>'val2')));
$return = $this->invokeMethod($this->main,'_requestParam',array('var1'));
$this->assertEquals($return, 'val1');
}

public function test_requestDefault()
{
$this->invokeMethod($this->main,'register',array('_request',array('var1'=>'val1','var2'=>'val2')));
$return = $this->invokeMethod($this->main,'_requestParam',array('var3','val3'));
$this->assertEquals($return, 'val3');
}


public function testLoad()
{
$class = 'config';
$return = $this->invokeMethod($this->main,'load',array($class));
$this->assertInstanceOf($class, $return);
}

public function testLoadReturnClassNameAfterInclusion()
{
$class = 'config';
$return = $this->invokeMethod($this->main,'load',array($class,null,null,false));
$this->assertTrue(class_exists($return));
}

public function testLoadFalse(){
$class = 'Phiber\\controller';
$return = $this->invokeMethod($this->main,'load',array($class));
$this->assertFalse($return);
}
public function testAutoloadSimple()
{
$class = 'Phiber\\controller';
Expand All @@ -95,18 +65,11 @@ public function testAutoloadSimple()

public function testAutoloadOneLevel()
{
$class = 'Phiber\\oosql\\oosql';
$class = 'Phiber\\flag\\flag';
$this->invokeMethod($this->main,'autoload',array($class));
$this->assertTrue(class_exists($class));
}

public function testAutoloadOneLevelGlobalShifted()
{
$class = 'Phiber\\oosql\\oosql';
$this->invokeMethod($this->main,'autoload',array($class));
$this->assertTrue(class_exists('Phiber\\oosql\\oosql'));
}

public function testHasActionDefault()
{
$controller = 'index';
Expand All @@ -125,24 +88,6 @@ public function testHasAction()
$this->assertEquals('main',$return);
}

public function testHasController()
{
$module = 'default';
$parts = array('index','main');
$return = $this->invokeMethod($this->main,'hasController',array(&$parts,$module));

$this->assertEquals('index',$return);
}

public function testHasControllerDefault()
{
$module = 'default';
$parts = array('nonExistant','main');
$return = $this->invokeMethod($this->main,'hasController',array(&$parts,$module));
$this->assertEquals(2,count($parts));
$this->assertEquals('index',$return);
}

public function testSetVars()
{
$expected = array('var1'=>'val1','var2'=>'val2');
Expand All @@ -154,29 +99,10 @@ public function testSetVars()
public function testAddRoute()
{
$route = array('/route'=>'to/something');
$this->invokeMethod($this->main,'addRoute',array($route));
$this->invokeMethod($this->main,'addRoute',array('/route','to/something'));
$routes = $this->getProperty($this->main,'routes');
$this->assertEquals(1,count($routes));
}
public function testRouteMatchSimple()
{
$routes = array('/info'=>'/default/index/main');
$this->setProperty($this->main, 'phiber_bootstrap', \bootstrap::getInstance(\config::getInstance()));
$_SERVER['REQUEST_METHOD'] = 'GET';
$ret = $this->invokeMethod($this->main, 'routeMatchSimple',array($routes,'/info'));
$this->assertTrue($ret);
$this->assertEquals('/default/index/main',$_SERVER['REQUEST_URI']);
}

public function testRouteMatchRegex()
{
$routes = array('~/info/(\d+)/(\d+)~'=>'/default/index/main/:cat/:id');
$this->setProperty($this->main, 'phiber_bootstrap', \bootstrap::getInstance(\config::getInstance()));
$_SERVER['REQUEST_METHOD'] = 'GET';
$ret = $this->invokeMethod($this->main, 'routeMatchRegex',array($routes,'/info/14/13'));
$this->assertTrue($ret);
$this->assertEquals('/default/index/main/cat/14/id/13',$_SERVER['REQUEST_URI']);
}

public function providerURI()
{
Expand Down
Loading

0 comments on commit c308728

Please sign in to comment.