Permalink
Browse files

Merge pull request #89 from Floby/fix-row-isset

Add test for isset on rows. Fix isset for specialGets

tests are running fine.
  • Loading branch information...
2 parents aa7c3f0 + cfcab5a commit 1370fb55a8805191a1ab7ba6cf1028e4314b5174 @Floby Floby committed Jul 25, 2012
View
8 library/Centurion/Db/Table/Row/Abstract.php
@@ -385,8 +385,12 @@ public function __isset($columnName)
//Test special get column
if (array_key_exists($columnName, $this->_specialGets)) {
- if (!method_exists($this, $this->_specialGets[$columnName])) {
- throw new Centurion_Db_Table_Exception(sprintf("Specified method \"%s\" does not exist", $this->_specialGets[$columnName]));
+ $callbackValue = $this->_specialGets[$columnName];
+ if(is_string($callbackValue)) {
+ $callbackValue = array($this, $callbackValue);
+ }
+ if(!is_callable($callbackValue)) {
+ throw new Centurion_Db_Table_Exception(sprintf("Specified callback uncallable for %s", $columnName));
}
return true;
}
View
38 tests/library/Centurion/Db/Table/RowTest.php
@@ -215,6 +215,44 @@ public function testFunction__Set()
}
/**
+ * @covers Centurion_Db_Table_Row_Abstract::__isset
+ */
+ public function testFunction__Isset()
+ {
+ $table = new Asset_Model_DbTable_Simple();
+ $row = $table->createRow();
+ $row->save();
+ $row->title = 'title';
+
+ // this column exists
+ $this->assertTrue(isset($row->title), 'calling isset on a set column returned false');
+
+ // this column doesn't exist
+ $this->assertFalse(isset($row->unexistent), 'calling isset on an unset column returned true');
+
+ $tableWithRef = new Asset_Model_DbTable_WithRef();
+ $withRef = $tableWithRef->createRow();
+ $withRef->simple_id = $row->id;
+ $withRef->save();
+
+ // this column is a referenceMap
+ $this->assertTrue(isset($withRef->simple), 'calling isset on a reference returned false');
+
+ // this column is a reference field
+ $this->assertTrue(isset($withRef->simple__title), 'calling isset on a reference\'s field returned false');
+
+ $tableSpecialGet = new Asset_Model_DbTable_WithSpecialGet();
+ $withSpecialGet = $tableSpecialGet->createRow();
+ $withSpecialGet->save();
+
+ // this column is a special get with a methodName as string
+ $this->assertTrue(isset($withSpecialGet->method), 'Calling isset on a specialget by string returned false');
+
+ // this column is a special get with a callable array as parameter
+ $this->assertTrue(isset($withSpecialGet->arrayGet), 'Calling isset on a specialget by callable array returned false');
+ }
+
+ /**
* @covers Centurion_Db_Table_Row_Abstract::getModifiedData
* @covers Centurion_Db_Table_Row_Abstract::reset
*/
View
16 tests/support/Asset/Model/DbTable/Row/SimpleWithSpecialGet.php
@@ -0,0 +1,16 @@
+<?php
+
+class Asset_Model_DbTable_Row_SimpleWithSpecialGet extends Centurion_Db_Table_Row
+{
+
+ public function __construct(array $config) {
+ $this->_specialGets['method'] = 'specialGetMethod';
+ $this->_specialGets['arrayGet'] = array($this, 'specialGetMethod');
+ parent::__construct($config);
+ }
+ public function specialGetMethod()
+ {
+ return 'success';
+ }
+}
+
View
1 tests/support/Asset/Model/DbTable/SimpleWithSlug.php
@@ -22,6 +22,5 @@ protected function _createTable()
protected function _destructTable()
{
$this->getDefaultAdapter()->query('Drop table test_simple_with_slug');
- echo 'ici';
}
}
View
32 tests/support/Asset/Model/DbTable/WithSpecialGet.php
@@ -0,0 +1,32 @@
+<?php
+
+class Asset_Model_DbTable_WithSpecialGet extends Asset_Model_DbTable_Abstract
+{
+ protected $_name = 'test_with_special_get';
+
+ protected $_rowClass = 'Asset_Model_DbTable_Row_SimpleWithSpecialGet';
+
+
+ protected function _createTable()
+ {
+ $this->getDefaultAdapter()->query(<<<EOS
+ CREATE TABLE IF NOT EXISTS test_with_special_get (
+ `id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
+ `title` VARCHAR( 255 ) NOT NULL
+ ) ENGINE = INNODB;
+EOS
+ );
+ }
+
+ protected function _destructTable()
+ {
+ $this->getDefaultAdapter()->query('Drop table test_with_special_get');
+ }
+
+ public function __construct($config = array())
+ {
+ parent::__construct($config);
+ }
+
+}
+

0 comments on commit 1370fb5

Please sign in to comment.