ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ValidationFactoryTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2017 Stefan Hecken <stefan.hecken@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4require_once("libs/composer/vendor/autoload.php");
5
7use ILIAS\Data;
8
15{
19 protected $f = null;
20
21 protected function setUp()
22 {
23 $this->lng = $this->createMock(\ilLanguage::class);
24 $this->f = new Validation\Factory(new Data\Factory(), $this->lng);
25 }
26
27 protected function tearDown()
28 {
29 $this->f = null;
30 }
31
32 public function testIsInt()
33 {
34 $is_numeric = $this->f->isNumeric();
35 $this->assertInstanceOf(Validation\Constraint::class, $is_numeric);
36 }
37
38 public function testIsNumeric()
39 {
40 $is_int = $this->f->isInt();
41 $this->assertInstanceOf(Validation\Constraint::class, $is_int);
42 }
43
44 public function testGreaterThan()
45 {
46 $gt = $this->f->greaterThan(5);
47 $this->assertInstanceOf(Validation\Constraint::class, $gt);
48 }
49
50 public function testLessThan()
51 {
52 $lt = $this->f->lessThan(5);
53 $this->assertInstanceOf(Validation\Constraint::class, $lt);
54 }
55
56 public function testHasMinLength()
57 {
58 $min = $this->f->hasMinLength(1);
59 $this->assertInstanceOf(Validation\Constraint::class, $min);
60 }
61
62 public function testCustom()
63 {
64 $custom = $this->f->custom(function ($value) {
65 return "This was fault";
66 }, 5);
67 $this->assertInstanceOf(Validation\Constraint::class, $custom);
68 }
69
70 public function testSequential()
71 {
72 $constraints = array(
73 $this->f->greaterThan(5),
74 $this->f->lessThan(15)
75 );
76
77 $sequential = $this->f->sequential($constraints);
78 $this->assertInstanceOf(Validation\Constraint::class, $sequential);
79 }
80
81 public function testParallel()
82 {
83 $constraints = array(
84 $this->f->greaterThan(5),
85 $this->f->lessThan(15)
86 );
87
88 $parallel = $this->f->parallel($constraints);
89 $this->assertInstanceOf(Validation\Constraint::class, $parallel);
90 }
91
92 public function testNot()
93 {
94 $constraint = $this->f->greaterThan(5);
95 $not = $this->f->not($constraint);
96 $this->assertInstanceOf(Validation\Constraint::class, $not);
97 }
98
99 public function testLoadsLanguageModule()
100 {
101 $lng = $this->createMock(\ilLanguage::class);
102
103 $lng
104 ->expects($this->once())
105 ->method("loadLanguageModule")
106 ->with(Validation\Factory::LANGUAGE_MODULE);
107
108 new Validation\Factory(new Data\Factory(), $lng);
109 }
110}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:15
TestCase for the factory of constraints.
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
$lng