2010-06-24 09:40:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Symfony\Tests\Components\Form;
|
|
|
|
|
|
|
|
use Symfony\Components\Form\PropertyPath;
|
|
|
|
|
|
|
|
class PropertyPathTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2010-06-24 10:24:08 +01:00
|
|
|
public function testValidPropertyPath()
|
|
|
|
{
|
|
|
|
$path = new PropertyPath('reference.traversable[index].property');
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->assertEquals('reference', $path->getCurrent());
|
|
|
|
$this->assertTrue($path->hasNext());
|
|
|
|
$this->assertTrue($path->isProperty());
|
|
|
|
$this->assertFalse($path->isIndex());
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$path->next();
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->assertEquals('traversable', $path->getCurrent());
|
|
|
|
$this->assertTrue($path->hasNext());
|
|
|
|
$this->assertTrue($path->isProperty());
|
|
|
|
$this->assertFalse($path->isIndex());
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$path->next();
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->assertEquals('index', $path->getCurrent());
|
|
|
|
$this->assertTrue($path->hasNext());
|
|
|
|
$this->assertFalse($path->isProperty());
|
|
|
|
$this->assertTrue($path->isIndex());
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$path->next();
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->assertEquals('property', $path->getCurrent());
|
|
|
|
$this->assertFalse($path->hasNext());
|
|
|
|
$this->assertTrue($path->isProperty());
|
|
|
|
$this->assertFalse($path->isIndex());
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
public function testToString()
|
|
|
|
{
|
|
|
|
$path = new PropertyPath('reference.traversable[index].property');
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->assertEquals('reference.traversable[index].property', $path->__toString());
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
public function testInvalidPropertyPath_noDotBeforeProperty()
|
|
|
|
{
|
|
|
|
$this->setExpectedException('Symfony\Components\Form\Exception\InvalidPropertyPathException');
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
new PropertyPath('[index]property');
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
public function testInvalidPropertyPath_dotAtTheBeginning()
|
|
|
|
{
|
|
|
|
$this->setExpectedException('Symfony\Components\Form\Exception\InvalidPropertyPathException');
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
new PropertyPath('.property');
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
public function testInvalidPropertyPath_unexpectedCharacters()
|
|
|
|
{
|
|
|
|
$this->setExpectedException('Symfony\Components\Form\Exception\InvalidPropertyPathException');
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
new PropertyPath('property.$field');
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
public function testInvalidPropertyPath_empty()
|
|
|
|
{
|
|
|
|
$this->setExpectedException('Symfony\Components\Form\Exception\InvalidPropertyPathException');
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
new PropertyPath('');
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
public function testNextThrowsExceptionIfNoNextElement()
|
|
|
|
{
|
|
|
|
$path = new PropertyPath('property');
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->setExpectedException('OutOfBoundsException');
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$path->next();
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
}
|