[Propel1] Added tests for guessType() method

This commit is contained in:
William DURAND 2012-04-15 18:54:29 +02:00
parent 897a389ffe
commit b7c2d3da89
2 changed files with 59 additions and 3 deletions

View File

@ -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();
}
}

View File

@ -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),
);
}
}