Example #1
0
 public function testCreatingLoading()
 {
     $m = new Model();
     $m->_setName('Product');
     $this->assertEquals('Product', $m->_getName(), 'Internal change name ok');
     $object = $m->getModel('Product');
     $this->assertInstanceOf('Product', $object, 'getModel returns model Instance');
     $object = \Product::loadOne(1);
     $this->assertInstanceOf('Product', $object, 'loadOne returns model Instance');
     $data = $object->getArray();
     $this->assertEquals(array('id' => 1, 'title' => 'Macbook air', 'id_brand' => null), $data, 'User get array returns actual array');
     $this->assertEquals(1, $object->id, 'Getter of model object is works');
     $object->title = 'Test';
     $this->assertTrue($object->isChanged(), 'isChanged is true after changing');
     $this->assertEquals('Test', $object->title, 'Property changed after setter');
     $this->assertEquals('Test', $object['title'], 'Array accessor works');
     $res = $object->save();
     $this->assertTrue($res, 'Saved without errors');
     $this->assertFalse($object->isNew(), 'Object is not new after saving');
     $this->assertFalse($object->isChanged(), 'Object is not changed after saving');
     $object->setTitle('new title');
     $this->assertEquals('new title', $object->getTitle(), 'setter and getter works fine');
     $product = \Product::loadOne(QC::create()->where('id = :d', 1));
     $this->assertEquals('1', $product->id, 'loaded by QC');
     $product = \Product::loadOne(QC::create()->rawSelect('select * from products where id = 1'));
     $this->assertEquals('1', $product->id, 'loaded by QC raw select');
 }