diff --git a/src/Symfony/Bridge/Propel1/Tests/Fixtures/Column.php b/src/Symfony/Bridge/Propel1/Tests/Fixtures/Column.php new file mode 100644 index 0000000000..6b03977e20 --- /dev/null +++ b/src/Symfony/Bridge/Propel1/Tests/Fixtures/Column.php @@ -0,0 +1,59 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\Propel1\Tests\Fixtures; + +class Column +{ + private $name; + + private $type; + + public function __construct($name, $type) + { + $this->name = $name; + $this->type = $type; + } + + public function getType() + { + return $this->type; + } + + public function isText() + { + if (!$this->type) { + return false; + } + + switch ($this->type) { + case \PropelColumnTypes::CHAR: + case \PropelColumnTypes::VARCHAR: + case \PropelColumnTypes::LONGVARCHAR: + case \PropelColumnTypes::BLOB: + case \PropelColumnTypes::CLOB: + case \PropelColumnTypes::CLOB_EMU: + return true; + } + + return false; + } + + public function getSize() + { + return $this->isText() ? 255 : 0; + } + + public function isNotNull() + { + return ('id' === $this->name); + } +} diff --git a/src/Symfony/Bridge/Propel1/Tests/Fixtures/Item.php b/src/Symfony/Bridge/Propel1/Tests/Fixtures/Item.php index e10e111bf2..70705b6c86 100644 --- a/src/Symfony/Bridge/Propel1/Tests/Fixtures/Item.php +++ b/src/Symfony/Bridge/Propel1/Tests/Fixtures/Item.php @@ -21,11 +21,14 @@ class Item implements \Persistent private $groupName; - public function __construct($id = null, $value = null, $groupName = null) + private $price; + + public function __construct($id = null, $value = null, $groupName = null, $price = null) { $this->id = $id; $this->value = $value; $this->groupName = $groupName; + $this->price = $price; } public function getId() @@ -48,6 +51,11 @@ class Item implements \Persistent return $this->groupName; } + public function getPrice() + { + return $this->price; + } + public function getPrimaryKey() { return $this->getId(); diff --git a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php index f06c850583..adc155546c 100644 --- a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php +++ b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php @@ -13,6 +13,12 @@ namespace Symfony\Bridge\Propel1\Tests\Fixtures; class ItemQuery { + private $map = array( + 'id' => \PropelColumnTypes::INTEGER, + 'value' => \PropelColumnTypes::VARCHAR, + 'price' => \PropelColumnTypes::FLOAT, + ); + public function getTableMap() { // Allows to define methods in this class @@ -24,4 +30,24 @@ class ItemQuery { return array('id'); } + + /** + * Method from the TableMap API + */ + public function hasColumn($column) + { + return in_array($column, array_keys($this->map)); + } + + /** + * Method from the TableMap API + */ + public function getColumn($column) + { + if ($this->hasColumn($column)) { + return new Column($column, $this->map[$column]); + } + + return null; + } } diff --git a/src/Symfony/Bridge/Propel1/Tests/Form/PropelTypeGuesserTest.php b/src/Symfony/Bridge/Propel1/Tests/Form/PropelTypeGuesserTest.php new file mode 100644 index 0000000000..9b8eb72578 --- /dev/null +++ b/src/Symfony/Bridge/Propel1/Tests/Form/PropelTypeGuesserTest.php @@ -0,0 +1,74 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\Propel1\Tests\Form; + +use Symfony\Bridge\Propel1\Form\PropelTypeGuesser; +use Symfony\Bridge\Propel1\Tests\Propel1TestCase; + +class PropelTypeGuesserTest extends Propel1TestCase +{ + const CLASS_NAME = 'Symfony\Bridge\Propel1\Tests\Fixtures\Item'; + + private $guesser; + + public function setUp() + { + $this->guesser = new PropelTypeGuesser(); + } + + public function testGuessMaxLengthWithText() + { + $value = $this->guesser->guessMaxLength(self::CLASS_NAME, 'value'); + + $this->assertNotNull($value); + $this->assertEquals(255, $value->getValue()); + } + + public function testGuessMaxLengthWithFloat() + { + $value = $this->guesser->guessMaxLength(self::CLASS_NAME, 'price'); + + $this->assertNotNull($value); + $this->assertNull($value->getValue()); + } + + public function testGuessMinLengthWithText() + { + $value = $this->guesser->guessMinLength(self::CLASS_NAME, 'value'); + + $this->assertNull($value); + } + + public function testGuessMinLengthWithFloat() + { + $value = $this->guesser->guessMinLength(self::CLASS_NAME, 'price'); + + $this->assertNotNull($value); + $this->assertNull($value->getValue()); + } + + public function testGuessRequired() + { + $value = $this->guesser->guessRequired(self::CLASS_NAME, 'id'); + + $this->assertNotNull($value); + $this->assertTrue($value->getValue()); + } + + public function testGuessRequiredWithNullableColumn() + { + $value = $this->guesser->guessRequired(self::CLASS_NAME, 'value'); + + $this->assertNotNull($value); + $this->assertFalse($value->getValue()); + } +}