Skip to content

Commit

Permalink
Adding tests for table and alias methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jun 9, 2013
1 parent ead92ba commit d2ffc5f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/Cake/ORM/Table.php
Expand Up @@ -242,7 +242,6 @@ public function table($table = null) {
public function alias($alias = null) {
if ($alias !== null) {
$this->_alias = $alias;
static::instance($alias, $this);
}
if ($this->_alias === null) {
$alias = explode('\\', get_class($this));
Expand Down
44 changes: 44 additions & 0 deletions lib/Cake/Test/TestCase/ORM/TableTest.php
Expand Up @@ -158,6 +158,50 @@ public function testInstance() {
$this->assertSame($table, Table::instance('things'));
}

/**
* Tests the table method
*
* @return void
*/
public function testTableMethod() {
$table = new Table(['table' => 'things']);
$this->assertEquals('things', $table->table());

$table = new DatesTable;
$this->assertEquals('my_dates', $table->table());

$table = $this->getMockBuilder('\Cake\ORM\Table')
->setMethods(['find'])
->setMockClassName('SpecialThingTable')
->getMock();
$this->assertEquals('special_things', $table->table());

$table = new Table(['alias' => 'LoveBoat']);
$this->assertEquals('love_boats', $table->table());
}

/**
* Tests the alias method
*
* @return void
*/
public function testAliasMethod() {
$table = new Table(['alias' => 'things']);
$this->assertEquals('things', $table->alias());

$table = new Table(['table' => 'stuffs']);
$this->assertEquals('stuffs', $table->alias());

$table = new DatesTable;
$this->assertEquals('Dates', $table->alias());

$table = $this->getMockBuilder('\Cake\ORM\Table')
->setMethods(['find'])
->setMockClassName('SpecialThingTable')
->getMock();
$this->assertEquals('SpecialThing', $table->alias());
}

/**
* Tests that all fields for a table are added by default in a find when no
* other fields are specified
Expand Down

0 comments on commit d2ffc5f

Please sign in to comment.