CC-2166: Packaging Improvements. Moved the Zend app into airtime_mvc. It is now installed to /var/www/airtime. Storage is now set to /srv/airtime/stor. Utils are now installed to /usr/lib/airtime/utils/. Added install/airtime-dircheck.php as a simple test to see if everything is install/uninstalled correctly.

This commit is contained in:
Paul Baranowski 2011-04-14 18:55:04 -04:00
parent 514777e8d2
commit b11cbd8159
4546 changed files with 138 additions and 51 deletions

View file

@ -0,0 +1,94 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'tools/helpers/bookstore/BookstoreTestBase.php';
/**
* Tests the exceptions thrown by the BasePeer classes.
*
* @see BookstoreDataPopulator
* @author Francois Zaninotto
* @package runtime.util
*/
class BasePeerExceptionsTest extends BookstoreTestBase
{
public function testDoSelect()
{
try {
$c = new Criteria();
$c->add(BookPeer::ID, 12, ' BAD SQL');
BookPeer::addSelectColumns($c);
BasePeer::doSelect($c);
} catch (PropelException $e) {
$this->assertContains('[SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` WHERE book.ID BAD SQL:p1]', $e->getMessage(), 'SQL query is written in the exception message');
}
}
public function testDoCount()
{
try {
$c = new Criteria();
$c->add(BookPeer::ID, 12, ' BAD SQL');
BookPeer::addSelectColumns($c);
BasePeer::doCount($c);
} catch (PropelException $e) {
$this->assertContains('[SELECT COUNT(*) FROM `book` WHERE book.ID BAD SQL:p1]', $e->getMessage(), 'SQL query is written in the exception message');
}
}
public function testDoDelete()
{
try {
$c = new Criteria();
$c->setPrimaryTableName(BookPeer::TABLE_NAME);
$c->add(BookPeer::ID, 12, ' BAD SQL');
BasePeer::doDelete($c, Propel::getConnection());
} catch (PropelException $e) {
$this->assertContains('[DELETE FROM `book` WHERE book.ID BAD SQL:p1]', $e->getMessage(), 'SQL query is written in the exception message');
}
}
public function testDoDeleteAll()
{
try {
BasePeer::doDeleteAll('BAD TABLE', Propel::getConnection());
} catch (PropelException $e) {
$this->assertContains('[DELETE FROM `BAD` `TABLE`]', $e->getMessage(), 'SQL query is written in the exception message');
}
}
public function testDoUpdate()
{
try {
$c1 = new Criteria();
$c1->setPrimaryTableName(BookPeer::TABLE_NAME);
$c1->add(BookPeer::ID, 12, ' BAD SQL');
$c2 = new Criteria();
$c2->add(BookPeer::TITLE, 'Foo');
BasePeer::doUpdate($c1, $c2, Propel::getConnection());
} catch (PropelException $e) {
$this->assertContains('[UPDATE `book` SET `TITLE`=:p1 WHERE book.ID BAD SQL:p2]', $e->getMessage(), 'SQL query is written in the exception message');
}
}
public function testDoInsert()
{
try {
$c = new Criteria();
$c->setPrimaryTableName(BookPeer::TABLE_NAME);
$c->add(BookPeer::AUTHOR_ID, 'lkhlkhj');
BasePeer::doInsert($c, Propel::getConnection());
} catch (PropelException $e) {
$this->assertContains('[INSERT INTO `book` (`AUTHOR_ID`) VALUES (:p1)]', $e->getMessage(), 'SQL query is written in the exception message');
}
}
}

View file

@ -0,0 +1,413 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'tools/helpers/bookstore/BookstoreTestBase.php';
/**
* Tests the BasePeer classes.
*
* @see BookstoreDataPopulator
* @author Hans Lellelid <hans@xmpl.org>
* @package runtime.util
*/
class BasePeerTest extends BookstoreTestBase
{
/**
* @link http://propel.phpdb.org/trac/ticket/425
*/
public function testMultipleFunctionInCriteria()
{
$db = Propel::getDB(BookPeer::DATABASE_NAME);
try {
$c = new Criteria();
$c->setDistinct();
if ($db instanceof DBPostgres) {
$c->addSelectColumn("substring(".BookPeer::TITLE." from position('Potter' in ".BookPeer::TITLE.")) AS col");
} else {
$this->markTestSkipped();
}
$stmt = BookPeer::doSelectStmt( $c );
} catch (PropelException $x) {
$this->fail("Paring of nested functions failed: " . $x->getMessage());
}
}
public function testNeedsSelectAliases()
{
$c = new Criteria();
$this->assertFalse(BasePeer::needsSelectAliases($c), 'Empty Criterias dont need aliases');
$c = new Criteria();
$c->addSelectColumn(BookPeer::ID);
$c->addSelectColumn(BookPeer::TITLE);
$this->assertFalse(BasePeer::needsSelectAliases($c), 'Criterias with distinct column names dont need aliases');
$c = new Criteria();
BookPeer::addSelectColumns($c);
$this->assertFalse(BasePeer::needsSelectAliases($c), 'Criterias with only the columns of a model dont need aliases');
$c = new Criteria();
$c->addSelectColumn(BookPeer::ID);
$c->addSelectColumn(AuthorPeer::ID);
$this->assertTrue(BasePeer::needsSelectAliases($c), 'Criterias with common column names do need aliases');
}
public function testTurnSelectColumnsToAliases()
{
$c1 = new Criteria();
$c1->addSelectColumn(BookPeer::ID);
BasePeer::turnSelectColumnsToAliases($c1);
$c2 = new Criteria();
$c2->addAsColumn('book_ID', BookPeer::ID);
$this->assertTrue($c1->equals($c2));
}
public function testTurnSelectColumnsToAliasesPreservesAliases()
{
$c1 = new Criteria();
$c1->addSelectColumn(BookPeer::ID);
$c1->addAsColumn('foo', BookPeer::TITLE);
BasePeer::turnSelectColumnsToAliases($c1);
$c2 = new Criteria();
$c2->addAsColumn('book_ID', BookPeer::ID);
$c2->addAsColumn('foo', BookPeer::TITLE);
$this->assertTrue($c1->equals($c2));
}
public function testTurnSelectColumnsToAliasesExisting()
{
$c1 = new Criteria();
$c1->addSelectColumn(BookPeer::ID);
$c1->addAsColumn('book_ID', BookPeer::ID);
BasePeer::turnSelectColumnsToAliases($c1);
$c2 = new Criteria();
$c2->addAsColumn('book_ID_1', BookPeer::ID);
$c2->addAsColumn('book_ID', BookPeer::ID);
$this->assertTrue($c1->equals($c2));
}
public function testTurnSelectColumnsToAliasesDuplicate()
{
$c1 = new Criteria();
$c1->addSelectColumn(BookPeer::ID);
$c1->addSelectColumn(BookPeer::ID);
BasePeer::turnSelectColumnsToAliases($c1);
$c2 = new Criteria();
$c2->addAsColumn('book_ID', BookPeer::ID);
$c2->addAsColumn('book_ID_1', BookPeer::ID);
$this->assertTrue($c1->equals($c2));
}
public function testDoCountDuplicateColumnName()
{
$con = Propel::getConnection();
$c = new Criteria();
$c->addSelectColumn(BookPeer::ID);
$c->addJoin(BookPeer::AUTHOR_ID, AuthorPeer::ID);
$c->addSelectColumn(AuthorPeer::ID);
$c->setLimit(3);
try {
$count = BasePeer::doCount($c, $con);
} catch (Exception $e) {
$this->fail('doCount() cannot deal with a criteria selecting duplicate column names ');
}
}
public function testCreateSelectSqlPart()
{
$c = new Criteria();
$c->addSelectColumn(BookPeer::ID);
$c->addAsColumn('book_ID', BookPeer::ID);
$fromClause = array();
$selectSql = BasePeer::createSelectSqlPart($c, $fromClause);
$this->assertEquals('SELECT book.ID, book.ID AS book_ID', $selectSql, 'createSelectSqlPart() returns a SQL SELECT clause with both select and as columns');
$this->assertEquals(array('book'), $fromClause, 'createSelectSqlPart() adds the tables from the select columns to the from clause');
}
public function testCreateSelectSqlPartSelectModifier()
{
$c = new Criteria();
$c->addSelectColumn(BookPeer::ID);
$c->addAsColumn('book_ID', BookPeer::ID);
$c->setDistinct();
$fromClause = array();
$selectSql = BasePeer::createSelectSqlPart($c, $fromClause);
$this->assertEquals('SELECT DISTINCT book.ID, book.ID AS book_ID', $selectSql, 'createSelectSqlPart() includes the select modifiers in the SELECT clause');
$this->assertEquals(array('book'), $fromClause, 'createSelectSqlPart() adds the tables from the select columns to the from clause');
}
public function testCreateSelectSqlPartAliasAll()
{
$c = new Criteria();
$c->addSelectColumn(BookPeer::ID);
$c->addAsColumn('book_ID', BookPeer::ID);
$fromClause = array();
$selectSql = BasePeer::createSelectSqlPart($c, $fromClause, true);
$this->assertEquals('SELECT book.ID AS book_ID_1, book.ID AS book_ID', $selectSql, 'createSelectSqlPart() aliases all columns if passed true as last parameter');
$this->assertEquals(array(), $fromClause, 'createSelectSqlPart() does not add the tables from an all-aliased list of select columns');
}
public function testBigIntIgnoreCaseOrderBy()
{
BookstorePeer::doDeleteAll();
// Some sample data
$b = new Bookstore();
$b->setStoreName("SortTest1")->setPopulationServed(2000)->save();
$b = new Bookstore();
$b->setStoreName("SortTest2")->setPopulationServed(201)->save();
$b = new Bookstore();
$b->setStoreName("SortTest3")->setPopulationServed(302)->save();
$b = new Bookstore();
$b->setStoreName("SortTest4")->setPopulationServed(10000000)->save();
$c = new Criteria();
$c->setIgnoreCase(true);
$c->add(BookstorePeer::STORE_NAME, 'SortTest%', Criteria::LIKE);
$c->addAscendingOrderByColumn(BookstorePeer::POPULATION_SERVED);
$rows = BookstorePeer::doSelect($c);
$this->assertEquals('SortTest2', $rows[0]->getStoreName());
$this->assertEquals('SortTest3', $rows[1]->getStoreName());
$this->assertEquals('SortTest1', $rows[2]->getStoreName());
$this->assertEquals('SortTest4', $rows[3]->getStoreName());
}
/**
*
*/
public function testMixedJoinOrder()
{
$this->markTestSkipped('Famous cross join problem, to be solved one day');
$c = new Criteria(BookPeer::DATABASE_NAME);
$c->addSelectColumn(BookPeer::ID);
$c->addSelectColumn(BookPeer::TITLE);
$c->addJoin(BookPeer::PUBLISHER_ID, PublisherPeer::ID, Criteria::LEFT_JOIN);
$c->addJoin(BookPeer::AUTHOR_ID, AuthorPeer::ID);
$params = array();
$sql = BasePeer::createSelectSql($c, $params);
$expectedSql = "SELECT book.ID, book.TITLE FROM book LEFT JOIN publisher ON (book.PUBLISHER_ID=publisher.ID), author WHERE book.AUTHOR_ID=author.ID";
$this->assertEquals($expectedSql, $sql);
}
public function testMssqlApplyLimitNoOffset()
{
$db = Propel::getDB(BookPeer::DATABASE_NAME);
if(! ($db instanceof DBMSSQL))
{
$this->markTestSkipped();
}
$c = new Criteria(BookPeer::DATABASE_NAME);
$c->addSelectColumn(BookPeer::ID);
$c->addSelectColumn(BookPeer::TITLE);
$c->addSelectColumn(PublisherPeer::NAME);
$c->addAsColumn('PublisherName','(SELECT MAX(publisher.NAME) FROM publisher WHERE publisher.ID = book.PUBLISHER_ID)');
$c->addJoin(BookPeer::PUBLISHER_ID, PublisherPeer::ID, Criteria::LEFT_JOIN);
$c->setOffset(0);
$c->setLimit(20);
$params = array();
$sql = BasePeer::createSelectSql($c, $params);
$expectedSql = "SELECT TOP 20 book.ID, book.TITLE, publisher.NAME, (SELECT MAX(publisher.NAME) FROM publisher WHERE publisher.ID = book.PUBLISHER_ID) AS PublisherName FROM book LEFT JOIN publisher ON (book.PUBLISHER_ID=publisher.ID)";
$this->assertEquals($expectedSql, $sql);
}
public function testMssqlApplyLimitWithOffset()
{
$db = Propel::getDB(BookPeer::DATABASE_NAME);
if(! ($db instanceof DBMSSQL))
{
$this->markTestSkipped();
}
$c = new Criteria(BookPeer::DATABASE_NAME);
$c->addSelectColumn(BookPeer::ID);
$c->addSelectColumn(BookPeer::TITLE);
$c->addSelectColumn(PublisherPeer::NAME);
$c->addAsColumn('PublisherName','(SELECT MAX(publisher.NAME) FROM publisher WHERE publisher.ID = book.PUBLISHER_ID)');
$c->addJoin(BookPeer::PUBLISHER_ID, PublisherPeer::ID, Criteria::LEFT_JOIN);
$c->setOffset(20);
$c->setLimit(20);
$params = array();
$expectedSql = "SELECT [book.ID], [book.TITLE], [publisher.NAME], [PublisherName] FROM (SELECT ROW_NUMBER() OVER(ORDER BY book.ID) AS RowNumber, book.ID AS [book.ID], book.TITLE AS [book.TITLE], publisher.NAME AS [publisher.NAME], (SELECT MAX(publisher.NAME) FROM publisher WHERE publisher.ID = book.PUBLISHER_ID) AS [PublisherName] FROM book LEFT JOIN publisher ON (book.PUBLISHER_ID=publisher.ID)) AS derivedb WHERE RowNumber BETWEEN 21 AND 40";
$sql = BasePeer::createSelectSql($c, $params);
$this->assertEquals($expectedSql, $sql);
}
public function testMssqlApplyLimitWithOffsetOrderByAggregate()
{
$db = Propel::getDB(BookPeer::DATABASE_NAME);
if(! ($db instanceof DBMSSQL))
{
$this->markTestSkipped();
}
$c = new Criteria(BookPeer::DATABASE_NAME);
$c->addSelectColumn(BookPeer::ID);
$c->addSelectColumn(BookPeer::TITLE);
$c->addSelectColumn(PublisherPeer::NAME);
$c->addAsColumn('PublisherName','(SELECT MAX(publisher.NAME) FROM publisher WHERE publisher.ID = book.PUBLISHER_ID)');
$c->addJoin(BookPeer::PUBLISHER_ID, PublisherPeer::ID, Criteria::LEFT_JOIN);
$c->addDescendingOrderByColumn('PublisherName');
$c->setOffset(20);
$c->setLimit(20);
$params = array();
$expectedSql = "SELECT [book.ID], [book.TITLE], [publisher.NAME], [PublisherName] FROM (SELECT ROW_NUMBER() OVER(ORDER BY (SELECT MAX(publisher.NAME) FROM publisher WHERE publisher.ID = book.PUBLISHER_ID) DESC) AS RowNumber, book.ID AS [book.ID], book.TITLE AS [book.TITLE], publisher.NAME AS [publisher.NAME], (SELECT MAX(publisher.NAME) FROM publisher WHERE publisher.ID = book.PUBLISHER_ID) AS [PublisherName] FROM book LEFT JOIN publisher ON (book.PUBLISHER_ID=publisher.ID)) AS derivedb WHERE RowNumber BETWEEN 21 AND 40";
$sql = BasePeer::createSelectSql($c, $params);
$this->assertEquals($expectedSql, $sql);
}
public function testMssqlApplyLimitWithOffsetMultipleOrderBy()
{
$db = Propel::getDB(BookPeer::DATABASE_NAME);
if(! ($db instanceof DBMSSQL))
{
$this->markTestSkipped();
}
$c = new Criteria(BookPeer::DATABASE_NAME);
$c->addSelectColumn(BookPeer::ID);
$c->addSelectColumn(BookPeer::TITLE);
$c->addSelectColumn(PublisherPeer::NAME);
$c->addAsColumn('PublisherName','(SELECT MAX(publisher.NAME) FROM publisher WHERE publisher.ID = book.PUBLISHER_ID)');
$c->addJoin(BookPeer::PUBLISHER_ID, PublisherPeer::ID, Criteria::LEFT_JOIN);
$c->addDescendingOrderByColumn('PublisherName');
$c->addAscendingOrderByColumn(BookPeer::TITLE);
$c->setOffset(20);
$c->setLimit(20);
$params = array();
$expectedSql = "SELECT [book.ID], [book.TITLE], [publisher.NAME], [PublisherName] FROM (SELECT ROW_NUMBER() OVER(ORDER BY (SELECT MAX(publisher.NAME) FROM publisher WHERE publisher.ID = book.PUBLISHER_ID) DESC, book.TITLE ASC) AS RowNumber, book.ID AS [book.ID], book.TITLE AS [book.TITLE], publisher.NAME AS [publisher.NAME], (SELECT MAX(publisher.NAME) FROM publisher WHERE publisher.ID = book.PUBLISHER_ID) AS [PublisherName] FROM book LEFT JOIN publisher ON (book.PUBLISHER_ID=publisher.ID)) AS derivedb WHERE RowNumber BETWEEN 21 AND 40";
$sql = BasePeer::createSelectSql($c, $params);
$this->assertEquals($expectedSql, $sql);
}
/**
* @expectedException PropelException
*/
public function testDoDeleteNoCondition()
{
$con = Propel::getConnection();
$c = new Criteria(BookPeer::DATABASE_NAME);
BasePeer::doDelete($c, $con);
}
public function testDoDeleteSimpleCondition()
{
$con = Propel::getConnection();
$c = new Criteria(BookPeer::DATABASE_NAME);
$c->add(BookPeer::TITLE, 'War And Peace');
BasePeer::doDelete($c, $con);
$expectedSQL = "DELETE FROM `book` WHERE book.TITLE='War And Peace'";
$this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'doDelete() translates a contition into a WHERE');
}
public function testDoDeleteSeveralConditions()
{
$con = Propel::getConnection();
$c = new Criteria(BookPeer::DATABASE_NAME);
$c->add(BookPeer::TITLE, 'War And Peace');
$c->add(BookPeer::ID, 12);
BasePeer::doDelete($c, $con);
$expectedSQL = "DELETE FROM `book` WHERE book.TITLE='War And Peace' AND book.ID=12";
$this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'doDelete() combines conditions in WHERE whith an AND');
}
public function testDoDeleteTableAlias()
{
$con = Propel::getConnection();
$c = new Criteria(BookPeer::DATABASE_NAME);
$c->addAlias('b', BookPeer::TABLE_NAME);
$c->add('b.TITLE', 'War And Peace');
BasePeer::doDelete($c, $con);
$expectedSQL = "DELETE b FROM `book` AS b WHERE b.TITLE='War And Peace'";
$this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'doDelete() accepts a Criteria with a table alias');
}
/**
* Not documented anywhere, and probably wrong
* @see http://www.propelorm.org/ticket/952
*/
public function testDoDeleteSeveralTables()
{
$con = Propel::getConnection();
$count = $con->getQueryCount();
$c = new Criteria(BookPeer::DATABASE_NAME);
$c->add(BookPeer::TITLE, 'War And Peace');
$c->add(AuthorPeer::FIRST_NAME, 'Leo');
BasePeer::doDelete($c, $con);
$expectedSQL = "DELETE FROM `author` WHERE author.FIRST_NAME='Leo'";
$this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'doDelete() issues two DELETE queries when passed conditions on two tables');
$this->assertEquals($count + 2, $con->getQueryCount(), 'doDelete() issues two DELETE queries when passed conditions on two tables');
$c = new Criteria(BookPeer::DATABASE_NAME);
$c->add(AuthorPeer::FIRST_NAME, 'Leo');
$c->add(BookPeer::TITLE, 'War And Peace');
BasePeer::doDelete($c, $con);
$expectedSQL = "DELETE FROM `book` WHERE book.TITLE='War And Peace'";
$this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'doDelete() issues two DELETE queries when passed conditions on two tables');
$this->assertEquals($count + 4, $con->getQueryCount(), 'doDelete() issues two DELETE queries when passed conditions on two tables');
}
public function testCommentDoSelect()
{
$c = new Criteria();
$c->setComment('Foo');
$c->addSelectColumn(BookPeer::ID);
$expected = 'SELECT /* Foo */ book.ID FROM `book`';
$params = array();
$this->assertEquals($expected, BasePeer::createSelectSQL($c, $params), 'Criteria::setComment() adds a comment to select queries');
}
public function testCommentDoUpdate()
{
$c1 = new Criteria();
$c1->setPrimaryTableName(BookPeer::TABLE_NAME);
$c1->setComment('Foo');
$c2 = new Criteria();
$c2->add(BookPeer::TITLE, 'Updated Title');
$con = Propel::getConnection(BookPeer::DATABASE_NAME);
BasePeer::doUpdate($c1, $c2, $con);
$expected = 'UPDATE /* Foo */ `book` SET `TITLE`=\'Updated Title\'';
$this->assertEquals($expected, $con->getLastExecutedQuery(), 'Criteria::setComment() adds a comment to update queries');
}
public function testCommentDoDelete()
{
$c = new Criteria();
$c->setComment('Foo');
$c->add(BookPeer::TITLE, 'War And Peace');
$con = Propel::getConnection(BookPeer::DATABASE_NAME);
BasePeer::doDelete($c, $con);
$expected = 'DELETE /* Foo */ FROM `book` WHERE book.TITLE=\'War And Peace\'';
$this->assertEquals($expected, $con->getLastExecutedQuery(), 'Criteria::setComment() adds a comment to delete queries');
}
}

View file

@ -0,0 +1,69 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'PHPUnit/Framework/TestCase.php';
require_once dirname(__FILE__) . '/../../../../runtime/lib/config/PropelConfiguration.php';
/**
* Test for PropelConfiguration class
*
* @author Francois Zaninotto
* @package runtime.util
*/
class PropelConfigurationTest extends PHPUnit_Framework_TestCase
{
protected $testArray = array('foo' => array('fooo' => 'bar', 'fi' => array('fooooo' => 'bara')), 'baz' => 'bar2');
public function testConstruct()
{
$conf = new PropelConfiguration($this->testArray);
$this->assertEquals($this->testArray, $conf->getParameters(), 'constructor sets values from an associative array');
}
public function testGetParameters()
{
$conf = new PropelConfiguration($this->testArray);
$expected = array('foo.fooo' => 'bar', 'foo.fi.fooooo' => 'bara', 'baz' => 'bar2');
$this->assertEquals($expected, $conf->getParameters(PropelConfiguration::TYPE_ARRAY_FLAT), 'getParameters can return a flat array');
}
public function testGetParameter()
{
$conf = new PropelConfiguration($this->testArray);
$this->assertEquals('bar', $conf->getParameter('foo.fooo'), 'getParameter accepts a flat key');
$this->assertEquals('bara', $conf->getParameter('foo.fi.fooooo'), 'getParameter accepts a flat key');
$this->assertEquals('bar2', $conf->getParameter('baz'), 'getParameter accepts a flat key');
}
public function testGetParameterDefault()
{
$conf = new PropelConfiguration($this->testArray);
$this->assertEquals('bar', $conf->getParameter('foo.fooo'), 'getParameter accepts a flat key');
$this->assertEquals('', $conf->getParameter('foo.fooo2'), 'getParameter returns null for nonexistent keys');
$this->assertEquals('babar', $conf->getParameter('foo.fooo3', 'babar'), 'getParameter accepts a default value');
}
public function testSetParameter()
{
$conf = new PropelConfiguration(array());
$conf->setParameter('foo.fooo', 'bar');
$conf->setParameter('foo.fi.fooooo', 'bara');
$conf->setParameter('baz', 'bar2');
$this->assertEquals($this->testArray, $conf->getParameters(), 'setParameter accepts a flat array');
}
public function testArrayAccess()
{
$conf = new PropelConfiguration($this->testArray);
$expected = array('fooo' => 'bar', 'fi' => array('fooooo' => 'bara'));
$this->assertEquals($expected, $conf['foo'], 'PropelConfiguration implements ArrayAccess for OffsetGet');
$this->assertEquals('bar', $conf['foo']['fooo'], 'Array access allows deep access');
}
}

View file

@ -0,0 +1,139 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'tools/helpers/BaseTestCase.php';
require_once dirname(__FILE__) . '/../../../../runtime/lib/util/PropelDateTime.php';
/**
* Test for DateTime subclass to support serialization.
*
* @author Alan Pinstein
* @author Soenke Ruempler
* @package runtime.util
*/
class PropelDateTimeTest extends BaseTestCase
{
/**
* Assert that two dates are identical (equal and have same time zone).
*/
protected function assertDatesIdentical(DateTime $dt1, DateTime $dt2, $msg = "Expected DateTime1 IDENTICAL to DateTime2: %s")
{
$this->assertEquals($dt1->format('Y-m-d H:i:s'), $dt1->format('Y-m-d H:i:s'), sprintf($msg, "Dates w/ no timezone resolution were not the same."));
$this->assertEquals($dt1->getTimeZone()->getName(), $dt2->getTimeZone()->getName(), sprintf($msg, "timezones were not the same."));
// We do this last, because a PHP bug will make this true while the dates
// may not truly be equal.
// See: http://bugs.php.net/bug.php?id=40743
$this->assertTrue($dt1 == $dt2, sprintf($msg, "dates did not pass equality check (==)."));
}
/**
* Assert that two dates are equal.
*/
protected function assertDatesEqual(DateTime $dt1, DateTime $dt2, $msg = "Expected DateTime1 == DateTime2: %s")
{
if ($dt1 != $dt2) {
if ($dt1->getTimeZone()->getName() != $dt2->getTimeZone()->getName()) {
$this->fail(sprintf($msg, "Timezones were not the same."));
} else {
$this->fail(sprintf($msg, "Timezones were the same, but date values were different."));
}
}
}
/**
* Assert that two dates are not equal.
*/
protected function assertDatesNotEqual(DateTime $dt1, DateTime $dt2, $msg = "Expected DateTime1 != DateTime2: %s")
{
$this->assertTrue($dt1 != $dt2, $msg);
}
/**
* Ensure that our constructor matches DateTime constructor signature.
*/
public function testConstruct()
{
// Because of a PHP bug ()
// we cannot use a timestamp format that includes a timezone. It gets weird. :)
$now = date('Y-m-d H:i:s');
$dt = new DateTime($now);
$pdt = new PropelDateTime($now);
$this->assertDatesEqual($dt, $pdt, "Expected DateTime == PropelDateTime: %s");
$dt = new DateTime($now, new DateTimeZone('UTC'));
$pdt = new PropelDateTime($now, new DateTimeZone('America/New_York'));
$this->assertDatesNotEqual($dt, $pdt, "Expected DateTime != PropelDateTime: %s");
}
/**
* Tests the ability to serialize() a PropelDateTime object.
*/
public function testSerialize_NoTZ()
{
$now = date('Y-m-d H:i:s');
$dt = new DateTime($now);
$pdt = new PropelDateTime($now);
$this->assertDatesIdentical($dt, $pdt);
// We expect these to be the same -- there's no time zone info
$ser = serialize($pdt);
unset($pdt);
$pdt = unserialize($ser);
$this->assertDatesIdentical($dt, $pdt);
}
/**
* Tests the ability to serialize() a PropelDateTime object.
*/
public function testSerialize_SameTZ()
{
$now = date('Y-m-d H:i:s');
$dt = new DateTime($now, new DateTimeZone('America/New_York'));
$pdt = new PropelDateTime($now, new DateTimeZone('America/New_York'));
$this->assertDatesIdentical($dt, $pdt);
// We expect these to be the same -- there's no time zone info
$ser = serialize($pdt);
unset($pdt);
$pdt = unserialize($ser);
$this->assertDatesIdentical($dt, $pdt);
}
/**
* Tests the ability to serialize() a PropelDateTime object.
*/
public function testSerialize_DiffTZ()
{
$now = date('Y-m-d H:i:s');
$dt = new DateTime($now, new DateTimeZone('UTC'));
$pdt = new PropelDateTime($now, new DateTimeZone('America/New_York'));
$this->assertDatesNotEqual($dt, $pdt);
// We expect these to be the same -- there's no time zone info
$ser = serialize($pdt);
unset($pdt);
$pdt = unserialize($ser);
$this->assertDatesNotEqual($dt, $pdt);
}
}

View file

@ -0,0 +1,149 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'tools/helpers/bookstore/BookstoreEmptyTestBase.php';
/**
* Test the utility class PropelPager
*
* @author Francois Zaninotto
* @version $Id: PropelModelPagerTest.php
* @package runtime.util
*/
class PropelModelPagerTest extends BookstoreEmptyTestBase
{
private $authorId;
private $books;
protected function createBooks($nb = 15, $con = null)
{
BookQuery::create()->deleteAll($con);
$books = new PropelObjectCollection();
$books->setModel('Book');
for ($i=0; $i < $nb; $i++) {
$b = new Book();
$b->setTitle('Book' . $i);
$books[]= $b;
}
$books->save($con);
}
protected function getPager($maxPerPage, $page = 1)
{
$pager = new PropelModelPager(BookQuery::create(), $maxPerPage);
$pager->setPage($page);
$pager->init();
return $pager;
}
public function testHaveToPaginate()
{
BookQuery::create()->deleteAll();
$this->assertEquals(false, $this->getPager(0)->haveToPaginate(), 'haveToPaginate() returns false when there is no result');
$this->createBooks(5);
$this->assertEquals(false, $this->getPager(0)->haveToPaginate(), 'haveToPaginate() returns false when the maxPerPage is null');
$this->assertEquals(true, $this->getPager(2)->haveToPaginate(), 'haveToPaginate() returns true when the maxPerPage is less than the number of results');
$this->assertEquals(false, $this->getPager(6)->haveToPaginate(), 'haveToPaginate() returns false when the maxPerPage is greater than the number of results');
$this->assertEquals(false, $this->getPager(5)->haveToPaginate(), 'haveToPaginate() returns false when the maxPerPage is equal to the number of results');
}
public function testGetNbResults()
{
BookQuery::create()->deleteAll();
$pager = $this->getPager(4, 1);
$this->assertEquals(0, $pager->getNbResults(), 'getNbResults() returns 0 when there are no results');
$this->createBooks(5);
$pager = $this->getPager(4, 1);
$this->assertEquals(5, $pager->getNbResults(), 'getNbResults() returns the total number of results');
$pager = $this->getPager(2, 1);
$this->assertEquals(5, $pager->getNbResults(), 'getNbResults() returns the total number of results');
$pager = $this->getPager(2, 2);
$this->assertEquals(5, $pager->getNbResults(), 'getNbResults() returns the total number of results');
$pager = $this->getPager(7, 6);
$this->assertEquals(5, $pager->getNbResults(), 'getNbResults() returns the total number of results');
$pager = $this->getPager(0, 0);
$this->assertEquals(5, $pager->getNbResults(), 'getNbResults() returns the total number of results');
}
public function testGetResults()
{
$this->createBooks(5);
$pager = $this->getPager(4, 1);
$this->assertTrue($pager->getResults() instanceof PropelObjectCollection, 'getResults() returns a PropelObjectCollection');
$this->assertEquals(4, count($pager->getResults()), 'getResults() returns at most $maxPerPage results');
$pager = $this->getPager(4, 2);
$this->assertEquals(1, count($pager->getResults()), 'getResults() returns the remaining results when in the last page');
$pager = $this->getPager(4, 3);
$this->assertEquals(1, count($pager->getResults()), 'getResults() returns the results of the last page when called on nonexistent pages');
}
public function testGetIterator()
{
$this->createBooks(5);
$pager = $this->getPager(4, 1);
$i = 0;
foreach ($pager as $book) {
$this->assertEquals('Book' . $i, $book->getTitle(), 'getIterator() returns an iterator');
$i++;
}
$this->assertEquals(4, $i, 'getIterator() uses the results collection');
}
public function testIterateTwice()
{
$this->createBooks(5);
$pager = $this->getPager(4, 1);
$i = 0;
foreach ($pager as $book) {
$this->assertEquals('Book' . $i, $book->getTitle(), 'getIterator() returns an iterator');
$i++;
}
$this->assertEquals(4, $i, 'getIterator() uses the results collection');
$i = 0;
foreach ($pager as $book) {
$this->assertEquals('Book' . $i, $book->getTitle());
$i++;
}
$this->assertEquals(4, $i, 'getIterator() can be called several times');
}
public function testSetPage()
{
$this->createBooks(5);
$pager = $this->getPager(2, 2);
$i = 2;
foreach ($pager as $book) {
$this->assertEquals('Book' . $i, $book->getTitle(), 'setPage() sets the list to start on a given page');
$i++;
}
$this->assertEquals(4, $i, 'setPage() doesn\'t change the page count');
}
public function testIsFirstPage()
{
$this->createBooks(5);
$pager = $this->getPager(4, 1);
$this->assertTrue($pager->isFirstPage(), 'isFirstPage() returns true on the first page');
$pager = $this->getPager(4, 2);
$this->assertFalse($pager->isFirstPage(), 'isFirstPage() returns false when not on the first page');
}
public function testIsLastPage()
{
$this->createBooks(5);
$pager = $this->getPager(4, 1);
$this->assertFalse($pager->isLastPage(), 'isLastPage() returns false when not on the last page');
$pager = $this->getPager(4, 2);
$this->assertTrue($pager->isLastPage(), 'isLastPage() returns true on the last page');
}
}

View file

@ -0,0 +1,162 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'tools/helpers/bookstore/BookstoreEmptyTestBase.php';
/**
* Test the utility class PropelPager
*
* @author Niklas Närhinen <niklas@narhinen.net>
* @version $Id: PropelPagerTest.php
* @package runtime.util
*/
class PropelPagerTest extends BookstoreEmptyTestBase
{
private $authorId;
private $books;
protected function setUp()
{
parent::setUp();
BookstoreDataPopulator::populate();
$cr = new Criteria();
$cr->add(AuthorPeer::LAST_NAME, "Rowling");
$cr->add(AuthorPeer::FIRST_NAME, "J.K.");
$rowling = AuthorPeer::doSelectOne($cr);
$this->authorId = $rowling->getId();
$book = new Book();
$book->setTitle("Harry Potter and the Philosopher's Stone");
$book->setISBN("1234");
$book->setAuthor($rowling);
$book->save();
$this->books[] = $book->getId();
$book = new Book();
$book->setTitle("Harry Potter and the Chamber of Secrets");
$book->setISBN("1234");
$book->setAuthor($rowling);
$book->save();
$this->books[] = $book->getId();
$book = new Book();
$book->setTitle("Harry Potter and the Prisoner of Azkaban");
$book->setISBN("1234");
$book->setAuthor($rowling);
$book->save();
$this->books[] = $book->getId();
$book = new Book();
$book->setTitle("Harry Potter and the Goblet of Fire");
$book->setISBN("1234");
$book->setAuthor($rowling);
$book->save();
$this->books[] = $book->getId();
$book = new Book();
$book->setTitle("Harry Potter and the Half-Blood Prince");
$book->setISBN("1234");
$book->setAuthor($rowling);
$book->save();
$this->books[] = $book->getId();
$book = new Book();
$book->setTitle("Harry Potter and the Deathly Hallows");
$book->setISBN("1234");
$book->setAuthor($rowling);
$book->save();
$this->books[] = $book->getId();
}
protected function tearDown()
{
parent::tearDown();
$cr = new Criteria();
$cr->add(BookPeer::ID, $this->books, Criteria::IN);
BookPeer::doDelete($cr);
}
public function testCountNoPageNoLimit()
{
$cr = new Criteria();
$cr->add(BookPeer::AUTHOR_ID, $this->authorId);
$pager = new PropelPager($cr, "BookPeer", "doSelect");
$this->assertEquals(7, count($pager));
}
public function testCountFirstPageWithLimits()
{
$cr = new Criteria();
$cr->add(BookPeer::AUTHOR_ID, $this->authorId);
$pager = new PropelPager($cr, "BookPeer", "doSelect", 1, 5);
$this->assertEquals(5, count($pager));
}
public function testCountLastPageWithLimits()
{
$cr = new Criteria();
$cr->add(BookPeer::AUTHOR_ID, $this->authorId);
$pager = new PropelPager($cr, "BookPeer", "doSelect", 2, 5);
$this->assertEquals(2, count($pager));
}
public function testIterateAll()
{
$cr = new Criteria();
$cr->add(BookPeer::AUTHOR_ID, $this->authorId);
$pager = new PropelPager($cr, "BookPeer", "doSelect");
$i = 0;
foreach ($pager as $key => $book) {
$i++;
}
$this->assertEquals(7, $i);
}
public function testIterateWithLimits()
{
$cr = new Criteria();
$cr->add(BookPeer::AUTHOR_ID, $this->authorId);
$pager = new PropelPager($cr, "BookPeer", "doSelect", 2, 5);
$i = 0;
foreach ($pager as $key => $book) {
$i++;
}
$this->assertEquals(2, $i);
}
public function testIterateCheckSecond()
{
$cr = new Criteria();
$cr->add(BookPeer::AUTHOR_ID, $this->authorId);
$cr->addAscendingOrderByColumn(BookPeer::TITLE);
$pager = new PropelPager($cr, "BookPeer", "doSelect");
$books = array();
foreach($pager as $book) {
$books[] = $book;
}
$this->assertEquals("Harry Potter and the Goblet of Fire", $books[2]->getTitle());
}
public function testIterateTwice()
{
$cr = new Criteria();
$cr->add(BookPeer::AUTHOR_ID, $this->authorId);
$cr->addAscendingOrderByColumn(BookPeer::TITLE);
$pager = new PropelPager($cr, "BookPeer", "doSelect");
$i = 0;
foreach($pager as $book) {
$i++;
}
foreach($pager as $book) {
$i++;
}
$this->assertEquals(14, $i);
}
}