Ejemplo n.º 1
0
 public function testGetSet()
 {
     $definition = $this->crudServiceProvider->getData('book')->getDefinition();
     $entity = new CRUDEntity($definition);
     $entity->set('test', 'testdata');
     $read = $entity->get('test');
     $expected = 'testdata';
     $this->assertSame($read, $expected);
     $entity->set('test', 'testdata2');
     $read = $entity->get('test');
     $expected = 'testdata2';
     $this->assertSame($read, $expected);
     $read = $entity->get('testNull');
     $this->assertNull($read);
     $entity->set('price', 3.99);
     $read = $entity->get('price');
     $expected = 3.99;
     $this->assertSame($read, $expected);
     $entity->set('pages', 111);
     $read = $entity->get('pages');
     $expected = 111;
     $this->assertSame($read, $expected);
     // Fixed values override
     $definition->setFixedValue('pages', 666);
     $entity->set('pages', 111);
     $read = $entity->get('pages');
     $expected = 666;
     $this->assertSame($read, $expected);
     $definition = $this->crudServiceProvider->getData('book')->getDefinition();
     $entity = new CRUDEntity($definition);
     $entity->set('isOpenOnSundays', true);
     $read = $entity->get('isOpenOnSundays');
     $expected = true;
     $this->assertSame($read, $expected);
 }
Ejemplo n.º 2
0
 public function testList()
 {
     $entity = $this->dataLibrary->createEmpty();
     $entity->set('name', 'nameA');
     $this->dataLibrary->create($entity);
     $entity = new CRUDEntity($this->dataBook->getDefinition());
     $entity->set('name', 'nameB');
     $this->dataLibrary->create($entity);
     $list = $this->dataLibrary->listEntries();
     $read = count($list);
     $expected = 2;
     $this->assertSame($read, $expected);
     $list = $this->dataLibrary->listEntries(array('name' => 'nameB'), array('name' => '='));
     $read = count($list);
     $expected = 1;
     $this->assertSame($read, $expected);
     $list = $this->dataLibrary->listEntries(array('name' => 'nameB', 'id' => 2), array('name' => '=', 'id' => '='));
     $read = count($list);
     $expected = 1;
     $this->assertSame($read, $expected);
     $list = $this->dataLibrary->listEntries(array('type' => null), array('type' => '='));
     $read = count($list);
     $expected = 2;
     $this->assertSame($read, $expected);
     $list = $this->dataLibrary->listEntries(array('name' => '%eB%'), array('name' => 'LIKE'));
     $read = count($list);
     $expected = 1;
     $this->assertSame($read, $expected);
     $list = $this->dataLibrary->listEntries(array(), array(), null, null, 'name');
     $expected = 'nameB';
     $this->assertSame($list[0]->get('name'), $expected);
     $expected = 'nameA';
     $this->assertSame($list[1]->get('name'), $expected);
     for ($i = 0; $i < 15; ++$i) {
         $entity->set('name', 'name' . $i);
         $this->dataLibrary->create($entity);
     }
     $list = $this->dataLibrary->listEntries(array(), array(), null, null);
     $read = count($list);
     $expected = 17;
     $this->assertSame($read, $expected);
     $list = $this->dataLibrary->listEntries(array(), array(), null, 5);
     $read = count($list);
     $expected = 5;
     $this->assertSame($read, $expected);
     $list = $this->dataLibrary->listEntries(array(), array(), 0, 5);
     $read = count($list);
     $expected = 5;
     $this->assertSame($read, $expected);
     $list = $this->dataLibrary->listEntries(array(), array(), 15, 5);
     $read = count($list);
     $expected = 2;
     $this->assertSame($read, $expected);
     $list = $this->dataLibrary->listEntries(array(), array(), 5, null);
     $read = count($list);
     $expected = 12;
     $this->assertSame($read, $expected);
 }
Ejemplo n.º 3
0
 /**
  * Creates a new, empty entity instance having all fields prefilled with
  * null or the defined value in case of fixed fields.
  *
  * @return CRUDEntity
  * the newly created entity
  */
 public function createEmpty()
 {
     $entity = new CRUDEntity($this->definition);
     $fields = $this->definition->getEditableFieldNames();
     foreach ($fields as $field) {
         $value = null;
         if ($this->definition->getType($field) == 'fixed') {
             $value = $this->definition->getFixedValue($field);
         }
         $entity->set($field, $value);
     }
     $entity->set('id', null);
     return $entity;
 }