From b7c2d3da89c53ee366335d2751e3da8f2a0194e4 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Sun, 15 Apr 2012 18:54:29 +0200 Subject: [PATCH] =?UTF-8?q?[Propel1]=C2=A0Added=20tests=20for=20guessType(?= =?UTF-8?q?)=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Propel1/Tests/Fixtures/ItemQuery.php | 17 +++++-- .../Tests/Form/PropelTypeGuesserTest.php | 45 +++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php index adc155546c..75d2a4f731 100644 --- a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php +++ b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php @@ -14,9 +14,12 @@ namespace Symfony\Bridge\Propel1\Tests\Fixtures; class ItemQuery { private $map = array( - 'id' => \PropelColumnTypes::INTEGER, - 'value' => \PropelColumnTypes::VARCHAR, - 'price' => \PropelColumnTypes::FLOAT, + 'id' => \PropelColumnTypes::INTEGER, + 'value' => \PropelColumnTypes::VARCHAR, + 'price' => \PropelColumnTypes::FLOAT, + 'is_active' => \PropelColumnTypes::BOOLEAN, + 'enabled' => \PropelColumnTypes::BOOLEAN_EMU, + 'updated_at' => \PropelColumnTypes::TIMESTAMP, ); public function getTableMap() @@ -50,4 +53,12 @@ class ItemQuery return null; } + + /** + * Method from the TableMap API + */ + public function getRelations() + { + return array(); + } } diff --git a/src/Symfony/Bridge/Propel1/Tests/Form/PropelTypeGuesserTest.php b/src/Symfony/Bridge/Propel1/Tests/Form/PropelTypeGuesserTest.php index 9b8eb72578..7fcbd4f711 100644 --- a/src/Symfony/Bridge/Propel1/Tests/Form/PropelTypeGuesserTest.php +++ b/src/Symfony/Bridge/Propel1/Tests/Form/PropelTypeGuesserTest.php @@ -13,11 +13,14 @@ namespace Symfony\Bridge\Propel1\Tests\Form; use Symfony\Bridge\Propel1\Form\PropelTypeGuesser; use Symfony\Bridge\Propel1\Tests\Propel1TestCase; +use Symfony\Component\Form\Guess\Guess; class PropelTypeGuesserTest extends Propel1TestCase { const CLASS_NAME = 'Symfony\Bridge\Propel1\Tests\Fixtures\Item'; + const UNKNOWN_CLASS_NAME = 'Symfony\Bridge\Propel1\Tests\Fixtures\UnknownItem'; + private $guesser; public function setUp() @@ -71,4 +74,46 @@ class PropelTypeGuesserTest extends Propel1TestCase $this->assertNotNull($value); $this->assertFalse($value->getValue()); } + + public function testGuessTypeWithoutTable() + { + $value = $this->guesser->guessType(self::UNKNOWN_CLASS_NAME, 'property'); + + $this->assertNotNull($value); + $this->assertEquals('text', $value->getType()); + $this->assertEquals(Guess::LOW_CONFIDENCE, $value->getConfidence()); + } + + public function testGuessTypeWithoutColumn() + { + $value = $this->guesser->guessType(self::CLASS_NAME, 'property'); + + $this->assertNotNull($value); + $this->assertEquals('text', $value->getType()); + $this->assertEquals(Guess::LOW_CONFIDENCE, $value->getConfidence()); + } + + /** + * @dataProvider dataProviderForGuessType + */ + public function testGuessType($property, $type, $confidence) + { + $value = $this->guesser->guessType(self::CLASS_NAME, $property); + + $this->assertNotNull($value); + $this->assertEquals($type, $value->getType()); + $this->assertEquals($confidence, $value->getConfidence()); + } + + static public function dataProviderForGuessType() + { + return array( + array('is_active', 'checkbox', Guess::HIGH_CONFIDENCE), + array('enabled', 'checkbox', Guess::HIGH_CONFIDENCE), + array('id', 'integer', Guess::MEDIUM_CONFIDENCE), + array('value', 'text', Guess::MEDIUM_CONFIDENCE), + array('price', 'number', Guess::MEDIUM_CONFIDENCE), + array('updated_at', 'datetime', Guess::HIGH_CONFIDENCE), + ); + } }