/**
  * Install hstore
  * /usr/share/postgresql/contrib # cat hstore.sql | psql -U pgsql -d onphp
  **/
 public function testHstore()
 {
     foreach (DBTestPool::me()->getPool() as $connector => $db) {
         DBPool::me()->setDefault($db);
         $properties = array('age' => '23', 'weight' => 80, 'comment' => null);
         $user = TestUser::create()->setCity($moscow = TestCity::create()->setName('Moscow'))->setCredentials(Credentials::create()->setNickname('fake')->setPassword(sha1('passwd')))->setLastLogin(Timestamp::create(time()))->setRegistered(Timestamp::create(time())->modify('-1 day'))->setProperties(Hstore::make($properties));
         $moscow = TestCity::dao()->add($moscow);
         $user = TestUser::dao()->add($user);
         Cache::me()->clean();
         TestUser::dao()->dropIdentityMap();
         $user = TestUser::dao()->getById('1');
         $this->assertInstanceOf('Hstore', $user->getProperties());
         $this->assertEquals($properties, $user->getProperties()->getList());
         $form = TestUser::proto()->makeForm();
         $form->get('properties')->setFormMapping(array(Primitive::string('age'), Primitive::integer('weight'), Primitive::string('comment')));
         $form->import(array('id' => $user->getId()));
         $this->assertNotNull($form->getValue('id'));
         $object = $user;
         FormUtils::object2form($object, $form);
         $this->assertInstanceOf('Hstore', $form->getValue('properties'));
         $this->assertEquals(array_filter($properties), $form->getValue('properties')->getList());
         $subform = $form->get('properties')->getInnerForm();
         $this->assertEquals($subform->getValue('age'), '23');
         $this->assertEquals($subform->getValue('weight'), 80);
         $this->assertNull($subform->getValue('comment'));
         $user = new TestUser();
         FormUtils::form2object($form, $user, false);
         $this->assertEquals($user->getProperties()->getList(), array_filter($properties));
     }
 }
 public function testImport()
 {
     $prm = Primitive::string('name');
     $nullValues = array(null, '');
     foreach ($nullValues as $value) {
         $this->assertNull($prm->importValue($value));
     }
     $prm->clean();
     $falseValues = array(array(), true, false, $prm);
     foreach ($falseValues as $value) {
         $this->assertFalse($prm->importValue($value));
     }
     $prm->clean();
     $trueValues = array('some string', -100500, 2011.09);
     foreach ($trueValues as $value) {
         $this->assertTrue($prm->importValue($value));
     }
     $prm->setAllowedPattern(PrimitiveString::MAIL_PATTERN);
     $prm->clean();
     $trueValues = array('*****@*****.**', '*****@*****.**', '*****@*****.**');
     foreach ($trueValues as $value) {
         $this->assertTrue($prm->importValue($value));
     }
     $prm->clean();
     $falseValues = array('example.com', 100500, 2012.04);
     foreach ($falseValues as $value) {
         $this->assertFalse($prm->importValue($value));
     }
 }
 public function testImport()
 {
     $realPrimitive = Primitive::string('stringPrimitive')->required();
     $form = Form::create()->add($realPrimitive)->add(Primitive::alias('alias', $realPrimitive))->import(array('alias' => 'Йа строка'));
     $errors = $form->getErrors();
     $this->assertFalse(isset($errors['stringPrimitive']));
     $enumPrimitive = Primitive::enumeration('enumerationPrimitive')->of('DataType')->required();
     $form = Form::create()->add($enumPrimitive)->add(Primitive::alias('alias', $enumPrimitive))->import(array('alias' => DataType::getAnyId()));
     $errors = $form->getErrors();
     $this->assertFalse(isset($errors['enumerationPrimitive']));
 }
 public function testImport()
 {
     $prm = Primitive::string('name');
     $nullValues = array(null, '');
     foreach ($nullValues as $value) {
         $this->assertNull($prm->importValue($value));
     }
     $falseValues = array(array(), true, false, $prm);
     foreach ($falseValues as $value) {
         $this->assertFalse($prm->importValue($value));
     }
     $trueValues = array('some string', -100500, 2011.09);
     foreach ($trueValues as $value) {
         $this->assertTrue($prm->importValue($value));
     }
 }
 public function handleRequest(HttpRequest $request)
 {
     $form = Form::create()->add(Primitive::string('username')->setMax(64)->required())->add(Primitive::string('password')->addImportFilter(Filter::hash())->required())->import($request->getPost());
     if (!$form->getErrors()) {
         try {
             $admin = Administrator::dao()->logIn($form->getValue('username'), $form->getValue('password'));
         } catch (ObjectNotFoundException $e) {
             // failed to log in
             return ModelAndView::create()->setView('error');
         }
         if (!Session::isStarted()) {
             Session::start();
         }
         Session::assign(Administrator::LABEL, $admin);
         return ModelAndView::create()->setView(new RedirectToView('main'));
     }
     return ModelAndView::create()->setView('login');
 }
 public function testCallbackLogicalObject()
 {
     if (mb_substr(PHP_VERSION, 0, 3) < '5.3') {
         $this->markTestSkipped('only php 5.3 or later');
     }
     $callBack = function (Form $form) {
         return $form->getValue('repository') == 'git';
     };
     $form = Form::create()->add(Primitive::string('repository'))->addRule('isOurRepository', CallbackLogicalObject::create($callBack));
     $form->import(array('repository' => 'svn'))->checkRules();
     $this->assertEquals(array('isOurRepository' => Form::WRONG), $form->getErrors());
     $form->clean()->dropAllErrors();
     $form->import(array('repository' => 'git'))->checkRules();
     $this->assertEquals(array(), $form->getErrors());
 }
 /**
  * @return PrimitiveHstore
  **/
 protected function create()
 {
     return Primitive::hstore('properties')->setFormMapping(array(Primitive::string('age'), Primitive::integer('weight'), Primitive::string('comment')));
 }
 public function getFormMapping()
 {
     return array('items' => Primitive::formsList('items')->of('DirectoryItem')->required(), 'textField' => Primitive::string('textField')->setMax(256)->optional(), 'fileName' => Primitive::file('contents')->required(), 'inner' => Primitive::form('inner')->of('DirectoryItem')->optional());
 }