Example #1
0
 function testIncompleteApply()
 {
     $check = new Incomplete\Check(['incompleteExportKey' => 'check', 'incompleteType' => 'foo']);
     $check->apply('foo', $ctx = new Context(['allowIncomplete' => true]));
     $this->assertTrue($ctx->allValid());
     $this->assertFalse($ctx->flatten()->complete);
 }
Example #2
0
 function assertFormValid($in, $check, $value, $config = [])
 {
     $fs = $this->createFormSchema($check, $config);
     $out = $fs->applyValue($this->form($in), $ctx = new Context());
     if (is_object($value)) {
         $this->assertEquals($value, $out['foo']);
     } else {
         $this->assertSame($value, $out['foo']);
     }
     $this->assertTrue($ctx->flatten()->valid);
 }
Example #3
0
 function testDefault()
 {
     $list = new Check\List_(['items' => [new Check\Int_()], 'defaultItem' => new Check\String_()]);
     $list->apply([1], $ctx = new Context());
     $this->assertTrue($ctx->allValid());
     $list->apply([1, '1', '1'], $ctx = new Context());
     $this->assertTrue($ctx->allValid());
     $list->apply([null, null], $ctx = new Context());
     $this->assertTrue($ctx->allValid());
     $list->apply(['1'], $ctx = new Context());
     $flat = $ctx->flatten();
     $this->assertFalse($flat->valid);
     $this->assertCount(1, $flat->messages);
     $this->assertEquals(['int', 'invalidType'], $flat->messages[0]->id);
 }
Example #4
0
 function testNest()
 {
     $ctx = new Context();
     $ctx->push('a', 'a');
     $ctx->push('b', 'b');
     $ctx->push('c', 'c');
     $ctx->addReason(new Check\Basic(), ['id' => 'test.foo']);
     $ctx->pop('c');
     $ctx->push('d', 'd');
     $ctx->push('e', 'e');
     $ctx->addReason(new Check\Basic(), ['id' => 'test.bar']);
     $ctx->pop('e');
     $ctx->pop('d');
     $ctx->pop('b');
     $ctx->pop('a');
     $flat = $ctx->flatten();
     $this->assertCount(2, $flat->messages);
     $this->assertEquals(['test', 'foo'], $flat->messages[0]->id);
     $this->assertEquals(['test', 'bar'], $flat->messages[1]->id);
 }