Пример #1
0
 function testRuleRegexp()
 {
     $dataspace = new A_Collection();
     $rule = new A_Rule_Regexp('/123$/', 'test', 'error');
     $dataspace->set('test', 'test123');
     $result = $rule->isValid($dataspace);
     $this->assertTrue($result);
     $dataspace->set('test', 'test234');
     $result = $rule->isValid($dataspace);
     $this->assertFalse($result);
 }
Пример #2
0
 function testRuleLength()
 {
     $dataspace = new A_Collection();
     $rule = new A_Rule_Length(5, 10, 'test', 'error');
     $dataspace->set('test', 'TEST123');
     $this->assertTrue($rule->isValid($dataspace));
     $dataspace->set('test', 'TEST');
     $this->assertFalse($rule->isValid($dataspace));
     $dataspace->set('test', 'TEST1234567890');
     $this->assertFalse($rule->isValid($dataspace));
 }
Пример #3
0
 function testRule_MatchParams()
 {
     $dataspace = new A_Collection();
     $rule = new A_Rule_Match();
     $dataspace->set('foo', 'TEST123');
     $dataspace->set('bar', 'TEST123');
     $this->assertTrue($rule->isValid($dataspace));
     $rule = new A_Rule_Match('foo');
     $dataspace->set('foo', 'TEST123');
     $dataspace->set('bar', 'TEST123');
     $this->assertFalse($rule->isValid($dataspace));
 }
Пример #4
0
 function testRuleRange()
 {
     $dataspace = new A_Collection();
     $rule = new A_Rule_Range(5, 10, 'test', 'error');
     foreach (array(5, 7, 10) as $value) {
         $dataspace->set('test', $value);
         $result = $rule->isValid($dataspace);
         $this->assertTrue($result);
     }
     foreach (array(2, 3, 11, 13) as $value) {
         $dataspace->set('test', $value);
         $result = $rule->isValid($dataspace);
         $this->assertFalse($result);
     }
 }
Пример #5
0
 function testModelCheckRules()
 {
     $model = new A_Model();
     $datasource = new A_Collection();
     $datasource->set('foo', 'barBAR');
     $datasource->set('bar', 'baz');
     $rule = new A_Rule_Regexp('/^[a-z]*$/', '', 'not all lowercase letters. ');
     // add rule to check both fields
     $model->addRule($rule, array('foo', 'bar'));
     #		$model->excludeRules(array('foo', 'bar'));
     $this->assertFalse($model->isValid($datasource));
     // only check bar
     $model->excludeRules(array('foo'));
     $this->assertTrue($model->isValid($datasource));
     // only check foo
     $model->excludeRules(array());
     $model->includeRules(array('foo'));
     $this->assertFalse($model->isValid($datasource));
     #dump($model, 'Model: ', 1);
     #echo '<pre>' . print_r($model->getErrorMsg(), 1) . '</pre>';
     #echo '<pre>' . print_r($model->isValid($datasource), 1) . '</pre>';
 }
Пример #6
0
 public function test__Set()
 {
     $collection = new A_Collection();
     $collection->foo = 'bar';
     $this->assertEqual($collection->get('foo'), 'bar');
     $collection->foo = null;
     $this->assertFalse($collection->has('foo'));
 }
Пример #7
0
<?php

include 'config.php';
$configdata = array('APP' => '/path/to/app/', 'BASE' => 'http://www.example.com');
$config = new A_Collection($configdata);
$config->import(simplexml_load_file("example.xml"), 'xml');
$config->import(parse_ini_file("example.ini", true), 'ini');
echo "\$config->xml->first_section->animal = {$config->xml->first_section->animal}<br/>";
echo "\$config->ini->first_section->animal = {$config->ini->first_section->animal}<br/>";
dump($config);
Пример #8
0
$form->text(array('name' => 'blogPost[title]', 'val:regex' => '\\w{1,255}'));
$form->text(array('name' => 'blogPost[body]', 'val:regex' => '\\w{1,65535}'));
$form->submit('submit', 'login');
echo $form->render();
exit;
echo '<br/>Object usage:';
$model = array('username' => 'foo');
$form = new A_Html_Form();
$form->setModel($model);
$form->setWrapper('A_Html_Div', array('class' => 'fieldclass', 'style' => 'border:1px solid red;'));
$form->text('username', 'Enter Username:'******'passwd', 'Enter Password:'******'submit', 'login');
echo $form->render();
$form->reset();
$model = new A_Collection();
$model->set('username', 'bar');
$form->setModel($model);
echo '<br/>Fluent usage:';
echo $form->text(array('name' => 'username', 'label' => 'Enter Username:'******'passwd', 'Enter Password:'******'submit', 'login')->render();
echo '<br/>Static usage';
echo A_Html_Form::render(array('action' => 'foo', 'class' => 'bar'), 'Form inputs go here');
echo '<br/>Fieldset usage:';
$fields1 = new A_Html_Form();
$fields1->text('username', 'Enter Username:'******'passwd', 'Enter Password:'******'email', 'Enter Email:');
$fields2->password('phone', 'Enter Phone:');
$form = new A_Html_Form();
$form->fieldset('set1', $fields1->partial());