dox Executable Documentation

Select entity field

No list action given

Given the class 'EntityClass'
Given I registered an entity representer for 'EntityClass'
Given a select entity field 'test' with the entity 'EntityClass'
When I try to render the field
Then the exception 'Cannot select [EntityClass]: ' . 'The EntityRepresenter did not provide a ListAction.' should be thrown

Empty entity list

Given the class 'EntityClass'
Given I registered an entity representer for 'EntityClass'
Given I have set 'ListEntity' as the list action for 'EntityClass'
Given a select entity field 'test' with the entity 'EntityClass'
When I render the field
Then the output should be '<label for="test">Test</label> <select id="test" class="form-control" name="args[test]"> </select>'

Show entity options

Given the class 'NamedEntity' with the body ' function __construct($name) { $this->name = $name; } function getId() { return strtolower($this->name); } '
Given I registered an entity representer for 'NamedEntity'
Given I have set 'ListEntity' as the list action for 'NamedEntity'
Given a select entity field 'test' with the entity 'NamedEntity'
Given the class 'EntityHandler' with the body ' function listEntity() { return [ new NamedEntity("Bart"), new NamedEntity("Lisa"), ]; } '
Given I added the class 'EntityHandler' as handler for 'ListEntity'
When I render the field
Then the output should be '<label for="test">Test</label> <select id="test" class="form-control" name="args[test]"> <option value="bart">Named Entity [name:Bart|id:bart]</option> <option value="lisa">Named Entity [name:Lisa|id:lisa]</option> </select>'

Entities with identifier objects

Given the class 'SelectWithIdObject\\EntityId' with the body ' function __construct($id) { $this->id = $id; } function __toString() { return $this->id; }'
Given the class 'SelectWithIdObject\\Entity' with the body ' function __construct(EntityId $id) { $this->id = $id; } function __toString() { return ucfirst((string)$this->id); } '
Given I registered an entity representer for 'SelectWithIdObject\\Entity'
Given I have set 'ListEntity' as the list action for 'SelectWithIdObject\\Entity'
Given a select entity field 'test' with the entity 'SelectWithIdObject\\Entity'
Given the class 'SelectWithIdObject\\Handler' with the body ' function listEntity() { return [ new Entity(new EntityId("bart")), new Entity(new EntityId("lisa")), ]; } '
Given I added the class 'SelectWithIdObject\\Handler' as handler for 'ListEntity'
When I render the field
Then the output should be '<label for="test">Test</label> <select id="test" class="form-control" name="args[test]"> <option value="bart">Bart</option> <option value="lisa">Lisa</option> </select>'