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:
parent
514777e8d2
commit
b11cbd8159
4546 changed files with 138 additions and 51 deletions
|
@ -0,0 +1,141 @@
|
|||
<?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/map/ColumnMap.php';
|
||||
require_once dirname(__FILE__) . '/../../../../runtime/lib/map/TableMap.php';
|
||||
|
||||
/**
|
||||
* Test class for TableMap.
|
||||
*
|
||||
* @author François Zaninotto
|
||||
* @version $Id: ColumnMapTest.php 1773 2010-05-25 10:25:06Z francois $
|
||||
* @package runtime.map
|
||||
*/
|
||||
class ColumnMapTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $databaseMap;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->dmap = new DatabaseMap('foodb');
|
||||
$this->tmap = new TableMap('foo', $this->dmap);
|
||||
$this->columnName = 'bar';
|
||||
$this->cmap = new ColumnMap($this->columnName, $this->tmap);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// nothing to do for now
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$this->assertEquals($this->columnName, $this->cmap->getName(), 'constructor sets the column name');
|
||||
$this->assertEquals($this->tmap, $this->cmap->getTable(), 'Constructor sets the table map');
|
||||
$this->assertNull($this->cmap->getType(), 'A new column map has no type');
|
||||
}
|
||||
|
||||
public function testPhpName()
|
||||
{
|
||||
$this->assertNull($this->cmap->getPhpName(), 'phpName is empty until set');
|
||||
$this->cmap->setPhpName('FooBar');
|
||||
$this->assertEquals('FooBar', $this->cmap->getPhpName(), 'phpName is set by setPhpName()');
|
||||
}
|
||||
|
||||
public function testType()
|
||||
{
|
||||
$this->assertNull($this->cmap->getType(), 'type is empty until set');
|
||||
$this->cmap->setType('FooBar');
|
||||
$this->assertEquals('FooBar', $this->cmap->getType(), 'type is set by setType()');
|
||||
}
|
||||
|
||||
public function tesSize()
|
||||
{
|
||||
$this->assertEquals(0, $this->cmap->getSize(), 'size is empty until set');
|
||||
$this->cmap->setSize(123);
|
||||
$this->assertEquals(123, $this->cmap->getSize(), 'size is set by setSize()');
|
||||
}
|
||||
|
||||
public function testPrimaryKey()
|
||||
{
|
||||
$this->assertFalse($this->cmap->isPrimaryKey(), 'primaryKey is false by default');
|
||||
$this->cmap->setPrimaryKey(true);
|
||||
$this->assertTrue($this->cmap->isPrimaryKey(), 'primaryKey is set by setPrimaryKey()');
|
||||
}
|
||||
|
||||
public function testNotNull()
|
||||
{
|
||||
$this->assertFalse($this->cmap->isNotNull(), 'notNull is false by default');
|
||||
$this->cmap->setNotNull(true);
|
||||
$this->assertTrue($this->cmap->isNotNull(), 'notNull is set by setPrimaryKey()');
|
||||
}
|
||||
|
||||
public function testDefaultValue()
|
||||
{
|
||||
$this->assertNull($this->cmap->getDefaultValue(), 'defaultValue is empty until set');
|
||||
$this->cmap->setDefaultValue('FooBar');
|
||||
$this->assertEquals('FooBar', $this->cmap->getDefaultValue(), 'defaultValue is set by setDefaultValue()');
|
||||
}
|
||||
|
||||
public function testGetForeignKey()
|
||||
{
|
||||
$this->assertFalse($this->cmap->isForeignKey(), 'foreignKey is false by default');
|
||||
try
|
||||
{
|
||||
$this->cmap->getRelatedTable();
|
||||
$this->fail('getRelatedTable throws an exception when called on a column with no foreign key');
|
||||
} catch(PropelException $e) {
|
||||
$this->assertTrue(true, 'getRelatedTable throws an exception when called on a column with no foreign key');
|
||||
}
|
||||
try
|
||||
{
|
||||
$this->cmap->getRelatedColumn();
|
||||
$this->fail('getRelatedColumn throws an exception when called on a column with no foreign key');
|
||||
} catch(PropelException $e) {
|
||||
$this->assertTrue(true, 'getRelatedColumn throws an exception when called on a column with no foreign key');
|
||||
}
|
||||
$relatedTmap = $this->dmap->addTable('foo2');
|
||||
// required to let the database map use the foreign TableMap
|
||||
$relatedCmap = $relatedTmap->addColumn('BAR2', 'Bar2', 'INTEGER');
|
||||
$this->cmap->setForeignKey('foo2', 'BAR2');
|
||||
$this->assertTrue($this->cmap->isForeignKey(), 'foreignKey is true after setting the foreign key via setForeignKey()');
|
||||
$this->assertEquals($relatedTmap, $this->cmap->getRelatedTable(), 'getRelatedTable returns the related TableMap object');
|
||||
$this->assertEquals($relatedCmap, $this->cmap->getRelatedColumn(), 'getRelatedColumn returns the related ColumnMap object');
|
||||
}
|
||||
|
||||
public function testGetRelation()
|
||||
{
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . "fixtures/bookstore/build/classes");
|
||||
Propel::init('fixtures/bookstore/build/conf/bookstore-conf.php');
|
||||
$bookTable = BookPeer::getTableMap();
|
||||
$titleColumn = $bookTable->getColumn('TITLE');
|
||||
$this->assertNull($titleColumn->getRelation(), 'getRelation() returns null for non-foreign key columns');
|
||||
$publisherColumn = $bookTable->getColumn('PUBLISHER_ID');
|
||||
$this->assertEquals($publisherColumn->getRelation(), $bookTable->getRelation('Publisher'), 'getRelation() returns the RelationMap object for this foreign key');
|
||||
$bookstoreTable = BookstoreEmployeePeer::getTableMap();
|
||||
$supervisorColumn = $bookstoreTable->getColumn('SUPERVISOR_ID');
|
||||
$this->assertEquals($supervisorColumn->getRelation(), $supervisorColumn->getRelation('Supervisor'), 'getRelation() returns the RelationMap object even whit ha specific refPhpName');
|
||||
|
||||
}
|
||||
|
||||
public function testNormalizeName()
|
||||
{
|
||||
$this->assertEquals('', ColumnMap::normalizeName(''), 'normalizeColumnName() returns an empty string when passed an empty string');
|
||||
$this->assertEquals('BAR', ColumnMap::normalizeName('bar'), 'normalizeColumnName() uppercases the input');
|
||||
$this->assertEquals('BAR_BAZ', ColumnMap::normalizeName('bar_baz'), 'normalizeColumnName() does not mind underscores');
|
||||
$this->assertEquals('BAR', ColumnMap::normalizeName('FOO.BAR'), 'normalizeColumnName() removes table prefix');
|
||||
$this->assertEquals('BAR', ColumnMap::normalizeName('BAR'), 'normalizeColumnName() leaves normalized column names unchanged');
|
||||
$this->assertEquals('BAR_BAZ', ColumnMap::normalizeName('foo.bar_baz'), 'normalizeColumnName() can do all the above at the same time');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,171 @@
|
|||
<?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/map/ColumnMap.php';
|
||||
require_once dirname(__FILE__) . '/../../../../runtime/lib/map/TableMap.php';
|
||||
require_once dirname(__FILE__) . '/../../../../runtime/lib/map/DatabaseMap.php';
|
||||
|
||||
class TestDatabaseBuilder
|
||||
{
|
||||
protected static $dmap = null;
|
||||
protected static $tmap = null;
|
||||
public static function getDmap()
|
||||
{
|
||||
if (is_null(self::$dmap)) {
|
||||
self::$dmap = new DatabaseMap('foodb');
|
||||
}
|
||||
return self::$dmap;
|
||||
}
|
||||
public static function setTmap($tmap)
|
||||
{
|
||||
self::$tmap = $tmap;
|
||||
}
|
||||
public static function getTmap()
|
||||
{
|
||||
return self::$tmap;
|
||||
}
|
||||
}
|
||||
|
||||
class BazTableMap extends TableMap
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
$this->setName('baz');
|
||||
$this->setPhpName('Baz');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test class for DatabaseMap.
|
||||
*
|
||||
* @author François Zaninotto
|
||||
* @version $Id: DatabaseMapTest.php 1773 2010-05-25 10:25:06Z francois $
|
||||
* @package runtime.map
|
||||
*/
|
||||
class DatabaseMapTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $databaseMap;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->databaseName = 'foodb';
|
||||
$this->databaseMap = TestDatabaseBuilder::getDmap();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// nothing to do for now
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$this->assertEquals($this->databaseName, $this->databaseMap->getName(), 'constructor sets the table name');
|
||||
}
|
||||
|
||||
public function testAddTable()
|
||||
{
|
||||
$this->assertFalse($this->databaseMap->hasTable('foo'), 'tables are empty by default');
|
||||
try
|
||||
{
|
||||
$this->databaseMap->getTable('foo');
|
||||
$this->fail('getTable() throws an exception when called on an inexistent table');
|
||||
} catch(PropelException $e) {
|
||||
$this->assertTrue(true, 'getTable() throws an exception when called on an inexistent table');
|
||||
}
|
||||
$tmap = $this->databaseMap->addTable('foo');
|
||||
$this->assertTrue($this->databaseMap->hasTable('foo'), 'hasTable() returns true when the table was added by way of addTable()');
|
||||
$this->assertEquals($tmap, $this->databaseMap->getTable('foo'), 'getTable() returns a table by name when the table was added by way of addTable()');
|
||||
}
|
||||
|
||||
public function testAddTableObject()
|
||||
{
|
||||
$this->assertFalse($this->databaseMap->hasTable('foo2'), 'tables are empty by default');
|
||||
try
|
||||
{
|
||||
$this->databaseMap->getTable('foo2');
|
||||
$this->fail('getTable() throws an exception when called on a table with no builder');
|
||||
} catch(PropelException $e) {
|
||||
$this->assertTrue(true, 'getTable() throws an exception when called on a table with no builder');
|
||||
}
|
||||
$tmap = new TableMap('foo2');
|
||||
$this->databaseMap->addTableObject($tmap);
|
||||
$this->assertTrue($this->databaseMap->hasTable('foo2'), 'hasTable() returns true when the table was added by way of addTableObject()');
|
||||
$this->assertEquals($tmap, $this->databaseMap->getTable('foo2'), 'getTable() returns a table by name when the table was added by way of addTableObject()');
|
||||
}
|
||||
|
||||
public function testAddTableFromMapClass()
|
||||
{
|
||||
$table1 = $this->databaseMap->addTableFromMapClass('BazTableMap');
|
||||
try
|
||||
{
|
||||
$table2 = $this->databaseMap->getTable('baz');
|
||||
$this->assertEquals($table1, $table2, 'addTableFromMapClass() adds a table from a map class');
|
||||
} catch(PropelException $e) {
|
||||
$this->fail('addTableFromMapClass() adds a table from a map class');
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetColumn()
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->databaseMap->getColumn('foo.BAR');
|
||||
$this->fail('getColumn() throws an exception when called on column of an inexistent table');
|
||||
} catch(PropelException $e) {
|
||||
$this->assertTrue(true, 'getColumn() throws an exception when called on column of an inexistent table');
|
||||
}
|
||||
$tmap = $this->databaseMap->addTable('foo');
|
||||
try
|
||||
{
|
||||
$this->databaseMap->getColumn('foo.BAR');
|
||||
$this->fail('getColumn() throws an exception when called on an inexistent column of an existent table');
|
||||
} catch(PropelException $e) {
|
||||
$this->assertTrue(true, 'getColumn() throws an exception when called on an inexistent column of an existent table');
|
||||
}
|
||||
$column = $tmap->addColumn('BAR', 'Bar', 'INTEGER');
|
||||
$this->assertEquals($column, $this->databaseMap->getColumn('foo.BAR'), 'getColumn() returns a ColumnMap object based on a fully qualified name');
|
||||
}
|
||||
|
||||
public function testGetTableByPhpName()
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->databaseMap->getTableByPhpName('Foo1');
|
||||
$this->fail('getTableByPhpName() throws an exception when called on an inexistent table');
|
||||
} catch(PropelException $e) {
|
||||
$this->assertTrue(true, 'getTableByPhpName() throws an exception when called on an inexistent table');
|
||||
}
|
||||
$tmap = $this->databaseMap->addTable('foo1');
|
||||
try
|
||||
{
|
||||
$this->databaseMap->getTableByPhpName('Foo1');
|
||||
$this->fail('getTableByPhpName() throws an exception when called on a table with no phpName');
|
||||
} catch(PropelException $e) {
|
||||
$this->assertTrue(true, 'getTableByPhpName() throws an exception when called on a table with no phpName');
|
||||
}
|
||||
$tmap2 = new TableMap('foo2');
|
||||
$tmap2->setClassname('Foo2');
|
||||
$this->databaseMap->addTableObject($tmap2);
|
||||
$this->assertEquals($tmap2, $this->databaseMap->getTableByPhpName('Foo2'), 'getTableByPhpName() returns tableMap when phpName was set by way of TableMap::setPhpName()');
|
||||
}
|
||||
|
||||
public function testGetTableByPhpNameNotLoaded()
|
||||
{
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . "fixtures/bookstore/build/classes");
|
||||
require_once 'bookstore/map/BookTableMap.php';
|
||||
require_once 'bookstore/om/BaseBookPeer.php';
|
||||
require_once 'bookstore/BookPeer.php';
|
||||
$this->assertEquals('book', Propel::getDatabaseMap('bookstore')->getTableByPhpName('Book')->getName(), 'getTableByPhpName() can autoload a TableMap when the Peer class is generated and autoloaded');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
<?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';
|
||||
|
||||
/**
|
||||
* Test class for PHP5TableMapBuilder.
|
||||
*
|
||||
* @author François Zaninotto
|
||||
* @version $Id: GeneratedRelationMapTest.php 1612 2010-03-16 22:56:21Z francois $
|
||||
* @package runtime.map
|
||||
*/
|
||||
class GeneratedRelationMapTest extends BookstoreTestBase
|
||||
{
|
||||
protected $databaseMap;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->databaseMap = Propel::getDatabaseMap('bookstore');
|
||||
}
|
||||
|
||||
public function testGetRightTable()
|
||||
{
|
||||
$bookTable = $this->databaseMap->getTableByPhpName('Book');
|
||||
$authorTable = $this->databaseMap->getTableByPhpName('Author');
|
||||
$this->assertEquals($authorTable, $bookTable->getRelation('Author')->getRightTable(), 'getRightTable() returns correct table when called on a many to one relationship');
|
||||
$this->assertEquals($bookTable, $authorTable->getRelation('Book')->getRightTable(), 'getRightTable() returns correct table when called on a one to many relationship');
|
||||
$bookEmpTable = $this->databaseMap->getTableByPhpName('BookstoreEmployee');
|
||||
$bookEmpAccTable = $this->databaseMap->getTableByPhpName('BookstoreEmployeeAccount');
|
||||
$this->assertEquals($bookEmpAccTable, $bookEmpTable->getRelation('BookstoreEmployeeAccount')->getRightTable(), 'getRightTable() returns correct table when called on a one to one relationship');
|
||||
$this->assertEquals($bookEmpTable, $bookEmpAccTable->getRelation('BookstoreEmployee')->getRightTable(), 'getRightTable() returns correct table when called on a one to one relationship');
|
||||
}
|
||||
|
||||
public function testColumnMappings()
|
||||
{
|
||||
$bookTable = $this->databaseMap->getTableByPhpName('Book');
|
||||
$this->assertEquals(array('book.AUTHOR_ID' => 'author.ID'), $bookTable->getRelation('Author')->getColumnMappings(), 'getColumnMappings returns local to foreign by default');
|
||||
$this->assertEquals(array('book.AUTHOR_ID' => 'author.ID'), $bookTable->getRelation('Author')->getColumnMappings(RelationMap::LEFT_TO_RIGHT), 'getColumnMappings returns local to foreign when asked left to right for a many to one relationship');
|
||||
|
||||
$authorTable = $this->databaseMap->getTableByPhpName('Author');
|
||||
$this->assertEquals(array('book.AUTHOR_ID' => 'author.ID'), $authorTable->getRelation('Book')->getColumnMappings(), 'getColumnMappings returns local to foreign by default');
|
||||
$this->assertEquals(array('author.ID' => 'book.AUTHOR_ID'), $authorTable->getRelation('Book')->getColumnMappings(RelationMap::LEFT_TO_RIGHT), 'getColumnMappings returns foreign to local when asked left to right for a one to many relationship');
|
||||
|
||||
$bookEmpTable = $this->databaseMap->getTableByPhpName('BookstoreEmployee');
|
||||
$this->assertEquals(array('bookstore_employee_account.EMPLOYEE_ID' => 'bookstore_employee.ID'), $bookEmpTable->getRelation('BookstoreEmployeeAccount')->getColumnMappings(), 'getColumnMappings returns local to foreign by default');
|
||||
$this->assertEquals(array('bookstore_employee.ID' => 'bookstore_employee_account.EMPLOYEE_ID'), $bookEmpTable->getRelation('BookstoreEmployeeAccount')->getColumnMappings(RelationMap::LEFT_TO_RIGHT), 'getColumnMappings returns foreign to local when asked left to right for a one to one relationship');
|
||||
}
|
||||
|
||||
public function testCountColumnMappings()
|
||||
{
|
||||
$bookTable = $this->databaseMap->getTableByPhpName('Book');
|
||||
$this->assertEquals(1, $bookTable->getRelation('Author')->countColumnMappings());
|
||||
|
||||
$rfTable = $this->databaseMap->getTableByPhpName('ReaderFavorite');
|
||||
$this->assertEquals(2, $rfTable->getRelation('BookOpinion')->countColumnMappings());
|
||||
}
|
||||
|
||||
public function testIsComposite()
|
||||
{
|
||||
$bookTable = $this->databaseMap->getTableByPhpName('Book');
|
||||
$this->assertFalse($bookTable->getRelation('Author')->isComposite());
|
||||
|
||||
$rfTable = $this->databaseMap->getTableByPhpName('ReaderFavorite');
|
||||
$this->assertTrue($rfTable->getRelation('BookOpinion')->isComposite());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<?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';
|
||||
|
||||
/**
|
||||
* Test class for RelatedMap::getSymmetricalRelation.
|
||||
*
|
||||
* @author François Zaninotto
|
||||
* @version $Id: GeneratedRelationMapTest.php 1347 2009-12-03 21:06:36Z francois $
|
||||
* @package runtime.map
|
||||
*/
|
||||
class RelatedMapSymmetricalTest extends BookstoreTestBase
|
||||
{
|
||||
protected $databaseMap;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->databaseMap = Propel::getDatabaseMap('bookstore');
|
||||
}
|
||||
|
||||
public function testOneToMany()
|
||||
{
|
||||
$bookTable = $this->databaseMap->getTableByPhpName('Book');
|
||||
$bookToAuthor = $bookTable->getRelation('Author');
|
||||
$authorTable = $this->databaseMap->getTableByPhpName('Author');
|
||||
$authorToBook = $authorTable->getRelation('Book');
|
||||
$this->assertEquals($authorToBook, $bookToAuthor->getSymmetricalRelation());
|
||||
$this->assertEquals($bookToAuthor, $authorToBook->getSymmetricalRelation());
|
||||
}
|
||||
|
||||
public function testOneToOne()
|
||||
{
|
||||
$accountTable = $this->databaseMap->getTableByPhpName('BookstoreEmployeeAccount');
|
||||
$accountToEmployee = $accountTable->getRelation('BookstoreEmployee');
|
||||
$employeeTable = $this->databaseMap->getTableByPhpName('BookstoreEmployee');
|
||||
$employeeToAccount = $employeeTable->getRelation('BookstoreEmployeeAccount');
|
||||
$this->assertEquals($accountToEmployee, $employeeToAccount->getSymmetricalRelation());
|
||||
$this->assertEquals($employeeToAccount, $accountToEmployee->getSymmetricalRelation());
|
||||
}
|
||||
|
||||
public function testSeveralRelationsOnSameTable()
|
||||
{
|
||||
$authorTable = $this->databaseMap->getTableByPhpName('Author');
|
||||
$authorToEssay = $authorTable->getRelation('EssayRelatedByFirstAuthor');
|
||||
$essayTable = $this->databaseMap->getTableByPhpName('Essay');
|
||||
$essayToAuthor = $essayTable->getRelation('AuthorRelatedByFirstAuthor');
|
||||
$this->assertEquals($authorToEssay, $essayToAuthor->getSymmetricalRelation());
|
||||
$this->assertEquals($essayToAuthor, $authorToEssay->getSymmetricalRelation());
|
||||
}
|
||||
|
||||
public function testCompositeForeignKey()
|
||||
{
|
||||
$favoriteTable = $this->databaseMap->getTableByPhpName('ReaderFavorite');
|
||||
$favoriteToOpinion = $favoriteTable->getRelation('BookOpinion');
|
||||
$opinionTable = $this->databaseMap->getTableByPhpName('BookOpinion');
|
||||
$opinionToFavorite = $opinionTable->getRelation('ReaderFavorite');
|
||||
$this->assertEquals($favoriteToOpinion, $opinionToFavorite->getSymmetricalRelation());
|
||||
$this->assertEquals($opinionToFavorite, $favoriteToOpinion->getSymmetricalRelation());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?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/map/RelationMap.php';
|
||||
require_once dirname(__FILE__) . '/../../../../runtime/lib/map/TableMap.php';
|
||||
|
||||
/**
|
||||
* Test class for RelationMap.
|
||||
*
|
||||
* @author François Zaninotto
|
||||
* @version $Id: RelationMapTest.php 1773 2010-05-25 10:25:06Z francois $
|
||||
* @package runtime.map
|
||||
*/
|
||||
class RelationMapTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $databaseMap, $relationName, $rmap;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->databaseMap = new DatabaseMap('foodb');
|
||||
$this->relationName = 'foo';
|
||||
$this->rmap = new RelationMap($this->relationName);
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$this->assertEquals($this->relationName, $this->rmap->getName(), 'constructor sets the relation name');
|
||||
}
|
||||
|
||||
public function testLocalTable()
|
||||
{
|
||||
$this->assertNull($this->rmap->getLocalTable(), 'A new relation has no local table');
|
||||
$tmap1 = new TableMap('foo', $this->databaseMap);
|
||||
$this->rmap->setLocalTable($tmap1);
|
||||
$this->assertEquals($tmap1, $this->rmap->getLocalTable(), 'The local table is set by setLocalTable()');
|
||||
}
|
||||
|
||||
public function testForeignTable()
|
||||
{
|
||||
$this->assertNull($this->rmap->getForeignTable(), 'A new relation has no foreign table');
|
||||
$tmap2 = new TableMap('bar', $this->databaseMap);
|
||||
$this->rmap->setForeignTable($tmap2);
|
||||
$this->assertEquals($tmap2, $this->rmap->getForeignTable(), 'The foreign table is set by setForeignTable()');
|
||||
}
|
||||
|
||||
public function testProperties()
|
||||
{
|
||||
$properties = array('type', 'onUpdate', 'onDelete');
|
||||
foreach ($properties as $property)
|
||||
{
|
||||
$getter = 'get' . ucfirst($property);
|
||||
$setter = 'set' . ucfirst($property);
|
||||
$this->assertNull($this->rmap->$getter(), "A new relation has no $property");
|
||||
$this->rmap->$setter('foo_value');
|
||||
$this->assertEquals('foo_value', $this->rmap->$getter(), "The $property is set by setType()");
|
||||
}
|
||||
}
|
||||
|
||||
public function testColumns()
|
||||
{
|
||||
$this->assertEquals(array(), $this->rmap->getLocalColumns(), 'A new relation has no local columns');
|
||||
$this->assertEquals(array(), $this->rmap->getForeignColumns(), 'A new relation has no foreign columns');
|
||||
$tmap1 = new TableMap('foo', $this->databaseMap);
|
||||
$col1 = $tmap1->addColumn('FOO1', 'Foo1PhpName', 'INTEGER');
|
||||
$tmap2 = new TableMap('bar', $this->databaseMap);
|
||||
$col2 = $tmap2->addColumn('BAR1', 'Bar1PhpName', 'INTEGER');
|
||||
$this->rmap->addColumnMapping($col1, $col2);
|
||||
$this->assertEquals(array($col1), $this->rmap->getLocalColumns(), 'addColumnMapping() adds a local table');
|
||||
$this->assertEquals(array($col2), $this->rmap->getForeignColumns(), 'addColumnMapping() adds a foreign table');
|
||||
$expected = array('foo.FOO1' => 'bar.BAR1');
|
||||
$this->assertEquals($expected, $this->rmap->getColumnMappings(), 'getColumnMappings() returns an associative array of column mappings');
|
||||
$col3 = $tmap1->addColumn('FOOFOO', 'FooFooPhpName', 'INTEGER');
|
||||
$col4 = $tmap2->addColumn('BARBAR', 'BarBarPhpName', 'INTEGER');
|
||||
$this->rmap->addColumnMapping($col3, $col4);
|
||||
$this->assertEquals(array($col1, $col3), $this->rmap->getLocalColumns(), 'addColumnMapping() adds a local table');
|
||||
$this->assertEquals(array($col2, $col4), $this->rmap->getForeignColumns(), 'addColumnMapping() adds a foreign table');
|
||||
$expected = array('foo.FOO1' => 'bar.BAR1', 'foo.FOOFOO' => 'bar.BARBAR');
|
||||
$this->assertEquals($expected, $this->rmap->getColumnMappings(), 'getColumnMappings() returns an associative array of column mappings');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,286 @@
|
|||
<?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/map/ColumnMap.php';
|
||||
require_once dirname(__FILE__) . '/../../../../runtime/lib/map/TableMap.php';
|
||||
|
||||
class TestableTableMap extends TableMap
|
||||
{
|
||||
public function hasPrefix($data)
|
||||
{
|
||||
return parent::hasPrefix($data);
|
||||
}
|
||||
|
||||
public function removePrefix($data)
|
||||
{
|
||||
return parent::removePrefix($data);
|
||||
}
|
||||
|
||||
public function normalizeColName($name)
|
||||
{
|
||||
return parent::normalizeColName($name);
|
||||
}
|
||||
}
|
||||
|
||||
class FooTableMap extends TableMap
|
||||
{
|
||||
public $rmap;
|
||||
public function buildRelations()
|
||||
{
|
||||
$this->rmap = $this->addRelation('Bar', 'Bar', RelationMap::MANY_TO_ONE);
|
||||
}
|
||||
}
|
||||
|
||||
class BarTableMap extends TableMap
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
$this->setName('bar');
|
||||
$this->setPhpName('Bar');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Test class for TableMap.
|
||||
*
|
||||
* @author François Zaninotto
|
||||
* @version $Id: TableMapTest.php 1773 2010-05-25 10:25:06Z francois $
|
||||
* @package runtime.map
|
||||
*/
|
||||
class TableMapTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $databaseMap;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->databaseMap = new DatabaseMap('foodb');
|
||||
$this->tableName = 'foo';
|
||||
$this->tmap = new TableMap($this->tableName, $this->databaseMap);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// nothing to do for now
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$this->assertEquals(array(), $this->tmap->getColumns(), 'A new table map has no columns');
|
||||
$this->assertEquals($this->tableName, $this->tmap->getName(), 'constructor can set the table name');
|
||||
$this->assertEquals($this->databaseMap, $this->tmap->getDatabaseMap(), 'Constructor can set the database map');
|
||||
try {
|
||||
$tmap = new TableMap();
|
||||
$this->assertTrue(true, 'A table map can be instanciated with no parameters');
|
||||
} catch (Exception $e) {
|
||||
$this->fail('A table map can be instanciated with no parameters');
|
||||
}
|
||||
}
|
||||
|
||||
public function testProperties()
|
||||
{
|
||||
$tmap = new TableMap();
|
||||
$properties = array('name', 'phpName', 'className', 'package');
|
||||
foreach ($properties as $property)
|
||||
{
|
||||
$getter = 'get' . ucfirst($property);
|
||||
$setter = 'set' . ucfirst($property);
|
||||
$this->assertNull($tmap->$getter(), "A new relation has no $property");
|
||||
$tmap->$setter('foo_value');
|
||||
$this->assertEquals('foo_value', $tmap->$getter(), "The $property is set by setType()");
|
||||
}
|
||||
}
|
||||
|
||||
public function testHasColumn()
|
||||
{
|
||||
$this->assertFalse($this->tmap->hasColumn('BAR'), 'hascolumn() returns false when the column is not in the table map');
|
||||
$column = $this->tmap->addColumn('BAR', 'Bar', 'INTEGER');
|
||||
$this->assertTrue($this->tmap->hasColumn('BAR'), 'hascolumn() returns true when the column is in the table map');
|
||||
$this->assertTrue($this->tmap->hasColumn('foo.bar'), 'hascolumn() accepts a denormalized column name');
|
||||
$this->assertFalse($this->tmap->hasColumn('foo.bar', false), 'hascolumn() accepts a $normalize parameter to skip name normalization');
|
||||
$this->assertTrue($this->tmap->hasColumn('BAR', false), 'hascolumn() accepts a $normalize parameter to skip name normalization');
|
||||
$this->assertTrue($this->tmap->hasColumn($column), 'hascolumn() accepts a ColumnMap object as parameter');
|
||||
}
|
||||
|
||||
public function testGetColumn()
|
||||
{
|
||||
$column = $this->tmap->addColumn('BAR', 'Bar', 'INTEGER');
|
||||
$this->assertEquals($column, $this->tmap->getColumn('BAR'), 'getColumn returns a ColumnMap according to a column name');
|
||||
try
|
||||
{
|
||||
$this->tmap->getColumn('FOO');
|
||||
$this->fail('getColumn throws an exception when called on an inexistent column');
|
||||
} catch(PropelException $e) {}
|
||||
$this->assertEquals($column, $this->tmap->getColumn('foo.bar'), 'getColumn accepts a denormalized column name');
|
||||
try
|
||||
{
|
||||
$this->tmap->getColumn('foo.bar', false);
|
||||
$this->fail('getColumn accepts a $normalize parameter to skip name normalization');
|
||||
} catch(PropelException $e) {}
|
||||
}
|
||||
|
||||
public function testGetColumnByPhpName()
|
||||
{
|
||||
$column = $this->tmap->addColumn('BAR_BAZ', 'BarBaz', 'INTEGER');
|
||||
$this->assertEquals($column, $this->tmap->getColumnByPhpName('BarBaz'), 'getColumnByPhpName() returns a ColumnMap according to a column phpName');
|
||||
try
|
||||
{
|
||||
$this->tmap->getColumn('Foo');
|
||||
$this->fail('getColumnByPhpName() throws an exception when called on an inexistent column');
|
||||
} catch(PropelException $e) {}
|
||||
}
|
||||
|
||||
public function testGetColumns()
|
||||
{
|
||||
$this->assertEquals(array(), $this->tmap->getColumns(), 'getColumns returns an empty array when no columns were added');
|
||||
$column1 = $this->tmap->addColumn('BAR', 'Bar', 'INTEGER');
|
||||
$column2 = $this->tmap->addColumn('BAZ', 'Baz', 'INTEGER');
|
||||
$this->assertEquals(array('BAR' => $column1, 'BAZ' => $column2), $this->tmap->getColumns(), 'getColumns returns the columns indexed by name');
|
||||
}
|
||||
|
||||
public function testAddPrimaryKey()
|
||||
{
|
||||
$column1 = $this->tmap->addPrimaryKey('BAR', 'Bar', 'INTEGER');
|
||||
$this->assertTrue($column1->isPrimaryKey(), 'Columns added by way of addPrimaryKey() are primary keys');
|
||||
$column2 = $this->tmap->addColumn('BAZ', 'Baz', 'INTEGER');
|
||||
$this->assertFalse($column2->isPrimaryKey(), 'Columns added by way of addColumn() are not primary keys by default');
|
||||
$column3 = $this->tmap->addColumn('BAZZ', 'Bazz', 'INTEGER', null, null, null, true);
|
||||
$this->assertTrue($column3->isPrimaryKey(), 'Columns added by way of addColumn() can be defined as primary keys');
|
||||
$column4 = $this->tmap->addForeignKey('BAZZZ', 'Bazzz', 'INTEGER', 'Table1', 'column1');
|
||||
$this->assertFalse($column4->isPrimaryKey(), 'Columns added by way of addForeignKey() are not primary keys');
|
||||
$column5 = $this->tmap->addForeignPrimaryKey('BAZZZZ', 'Bazzzz', 'INTEGER', 'table1', 'column1');
|
||||
$this->assertTrue($column5->isPrimaryKey(), 'Columns added by way of addForeignPrimaryKey() are primary keys');
|
||||
}
|
||||
|
||||
public function testGetPrimaryKeyColumns()
|
||||
{
|
||||
$this->assertEquals(array(), $this->tmap->getPrimaryKeyColumns(), 'getPrimaryKeyColumns() returns an empty array by default');
|
||||
$column1 = $this->tmap->addPrimaryKey('BAR', 'Bar', 'INTEGER');
|
||||
$column3 = $this->tmap->addColumn('BAZZ', 'Bazz', 'INTEGER', null, null, null, true);
|
||||
$expected = array($column1, $column3);
|
||||
$this->assertEquals($expected, $this->tmap->getPrimaryKeyColumns(), 'getPrimaryKeyColumns() returns an array of the table primary keys');
|
||||
}
|
||||
|
||||
public function testGetPrimaryKeys()
|
||||
{
|
||||
$this->assertEquals(array(), $this->tmap->getPrimaryKeys(), 'getPrimaryKeys() returns an empty array by default');
|
||||
$column1 = $this->tmap->addPrimaryKey('BAR', 'Bar', 'INTEGER');
|
||||
$column3 = $this->tmap->addColumn('BAZZ', 'Bazz', 'INTEGER', null, null, null, true);
|
||||
$expected = array('BAR' => $column1, 'BAZZ' => $column3);
|
||||
$this->assertEquals($expected, $this->tmap->getPrimaryKeys(), 'getPrimaryKeys() returns an array of the table primary keys');
|
||||
}
|
||||
|
||||
public function testAddForeignKey()
|
||||
{
|
||||
$column1 = $this->tmap->addForeignKey('BAR', 'Bar', 'INTEGER', 'Table1', 'column1');
|
||||
$this->assertTrue($column1->isForeignKey(), 'Columns added by way of addForeignKey() are foreign keys');
|
||||
$column2 = $this->tmap->addColumn('BAZ', 'Baz', 'INTEGER');
|
||||
$this->assertFalse($column2->isForeignKey(), 'Columns added by way of addColumn() are not foreign keys by default');
|
||||
$column3 = $this->tmap->addColumn('BAZZ', 'Bazz', 'INTEGER', null, null, null, false, 'Table1', 'column1');
|
||||
$this->assertTrue($column3->isForeignKey(), 'Columns added by way of addColumn() can be defined as foreign keys');
|
||||
$column4 = $this->tmap->addPrimaryKey('BAZZZ', 'Bazzz', 'INTEGER');
|
||||
$this->assertFalse($column4->isForeignKey(), 'Columns added by way of addPrimaryKey() are not foreign keys');
|
||||
$column5 = $this->tmap->addForeignPrimaryKey('BAZZZZ', 'Bazzzz', 'INTEGER', 'table1', 'column1');
|
||||
$this->assertTrue($column5->isForeignKey(), 'Columns added by way of addForeignPrimaryKey() are foreign keys');
|
||||
}
|
||||
|
||||
public function testGetForeignKeys()
|
||||
{
|
||||
$this->assertEquals(array(), $this->tmap->getForeignKeys(), 'getForeignKeys() returns an empty array by default');
|
||||
$column1 = $this->tmap->addForeignKey('BAR', 'Bar', 'INTEGER', 'Table1', 'column1');
|
||||
$column3 = $this->tmap->addColumn('BAZZ', 'Bazz', 'INTEGER', null, null, null, false, 'Table1', 'column1');
|
||||
$expected = array('BAR' => $column1, 'BAZZ' => $column3);
|
||||
$this->assertEquals($expected, $this->tmap->getForeignKeys(), 'getForeignKeys() returns an array of the table foreign keys');
|
||||
}
|
||||
|
||||
public function testLazyLoadRelations()
|
||||
{
|
||||
try {
|
||||
$this->tmap->getRelation('Bar');
|
||||
$this->fail('getRelation() throws an exception when called on a table with no relations');
|
||||
} catch (PropelException $e) {
|
||||
$this->assertTrue(true, 'getRelation() throws an exception when called on a table with no relations');
|
||||
}
|
||||
$foreigntmap = new BarTableMap();
|
||||
$this->databaseMap->addTableObject($foreigntmap);
|
||||
$localtmap = new FooTableMap();
|
||||
$this->databaseMap->addTableObject($localtmap);
|
||||
$rmap = $localtmap->getRelation('Bar');
|
||||
$this->assertEquals($rmap, $localtmap->rmap, 'getRelation() returns the relations lazy loaded by buildRelations()');
|
||||
}
|
||||
|
||||
public function testAddRelation()
|
||||
{
|
||||
$foreigntmap1 = new TableMap('bar');
|
||||
$foreigntmap1->setClassname('Bar');
|
||||
$this->databaseMap->addTableObject($foreigntmap1);
|
||||
$foreigntmap2 = new TableMap('baz');
|
||||
$foreigntmap2->setClassname('Baz');
|
||||
$this->databaseMap->addTableObject($foreigntmap2);
|
||||
$this->rmap1 = $this->tmap->addRelation('Bar', 'Bar', RelationMap::MANY_TO_ONE);
|
||||
$this->rmap2 = $this->tmap->addRelation('Bazz', 'Baz', RelationMap::ONE_TO_MANY);
|
||||
$this->tmap->getRelations();
|
||||
// now on to the test
|
||||
$this->assertEquals($this->rmap1->getLocalTable(), $this->tmap, 'adding a relation with HAS_ONE sets the local table to the current table');
|
||||
$this->assertEquals($this->rmap1->getForeignTable(), $foreigntmap1, 'adding a relation with HAS_ONE sets the foreign table according to the name given');
|
||||
$this->assertEquals(RelationMap::MANY_TO_ONE, $this->rmap1->getType(), 'adding a relation with HAS_ONE sets the foreign table type accordingly');
|
||||
|
||||
$this->assertEquals($this->rmap2->getForeignTable(), $this->tmap, 'adding a relation with HAS_MANY sets the foreign table to the current table');
|
||||
$this->assertEquals($this->rmap2->getLocalTable(), $foreigntmap2, 'adding a relation with HAS_MANY sets the local table according to the name given');
|
||||
$this->assertEquals(RelationMap::ONE_TO_MANY, $this->rmap2->getType(), 'adding a relation with HAS_MANY sets the foreign table type accordingly');
|
||||
|
||||
$expectedRelations = array('Bar' => $this->rmap1, 'Bazz' => $this->rmap2);
|
||||
$this->assertEquals($expectedRelations, $this->tmap->getRelations(), 'getRelations() returns an associative array of all the relations');
|
||||
}
|
||||
|
||||
// deprecated method
|
||||
public function testNormalizeColName()
|
||||
{
|
||||
$tmap = new TestableTableMap();
|
||||
$this->assertEquals('', $tmap->normalizeColName(''), 'normalizeColName returns an empty string when passed an empty string');
|
||||
$this->assertEquals('BAR', $tmap->normalizeColName('bar'), 'normalizeColName uppercases the input');
|
||||
$this->assertEquals('BAR_BAZ', $tmap->normalizeColName('bar_baz'), 'normalizeColName does not mind underscores');
|
||||
$this->assertEquals('BAR', $tmap->normalizeColName('FOO.BAR'), 'normalizeColName removes table prefix');
|
||||
$this->assertEquals('BAR', $tmap->normalizeColName('BAR'), 'normalizeColName leaves normalized column names unchanged');
|
||||
$this->assertEquals('BAR_BAZ', $tmap->normalizeColName('foo.bar_baz'), 'normalizeColName can do all the above at the same time');
|
||||
}
|
||||
|
||||
// deprecated method
|
||||
public function testContainsColumn()
|
||||
{
|
||||
$this->assertFalse($this->tmap->containsColumn('BAR'), 'containsColumn returns false when the column is not in the table map');
|
||||
$column = $this->tmap->addColumn('BAR', 'Bar', 'INTEGER');
|
||||
$this->assertTrue($this->tmap->containsColumn('BAR'), 'containsColumn returns true when the column is in the table map');
|
||||
$this->assertTrue($this->tmap->containsColumn('foo.bar'), 'containsColumn accepts a denormalized column name');
|
||||
$this->assertFalse($this->tmap->containsColumn('foo.bar', false), 'containsColumn accepts a $normalize parameter to skip name normalization');
|
||||
$this->assertTrue($this->tmap->containsColumn('BAR', false), 'containsColumn accepts a $normalize parameter to skip name normalization');
|
||||
$this->assertTrue($this->tmap->containsColumn($column), 'containsColumn accepts a ColumnMap object as parameter');
|
||||
}
|
||||
|
||||
// deprecated methods
|
||||
public function testPrefix()
|
||||
{
|
||||
$tmap = new TestableTableMap();
|
||||
$this->assertNull($tmap->getPrefix(), 'prefix is empty until set');
|
||||
$this->assertFalse($tmap->hasPrefix('barbaz'), 'hasPrefix returns false when prefix is not set');
|
||||
$tmap->setPrefix('bar');
|
||||
$this->assertEquals('bar', $tmap->getPrefix(), 'prefix is set by setPrefix()');
|
||||
$this->assertTrue($tmap->hasPrefix('barbaz'), 'hasPrefix returns true when prefix is set and found in string');
|
||||
$this->assertFalse($tmap->hasPrefix('baz'), 'hasPrefix returns false when prefix is set and not found in string');
|
||||
$this->assertFalse($tmap->hasPrefix('bazbar'), 'hasPrefix returns false when prefix is set and not found anywhere in string');
|
||||
$this->assertEquals('baz', $tmap->removePrefix('barbaz'), 'removePrefix returns string without prefix if found at the beginning');
|
||||
$this->assertEquals('bazbaz', $tmap->removePrefix('bazbaz'), 'removePrefix returns original string when prefix is not found');
|
||||
$this->assertEquals('bazbar', $tmap->removePrefix('bazbar'), 'removePrefix returns original string when prefix is not found at the beginning');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue