diff --git a/src/TypiCMS/Form/Elements/Number.php b/src/TypiCMS/Form/Elements/Number.php new file mode 100644 index 0000000..1028b22 --- /dev/null +++ b/src/TypiCMS/Form/Elements/Number.php @@ -0,0 +1,52 @@ + 'number', + ]; + + public function placeholder($placeholder) + { + $this->setAttribute('placeholder', $placeholder); + + return $this; + } + + public function max($max) + { + $this->setAttribute('max', $max); + + return $this; + } + + public function min($min) + { + $this->setAttribute('min', $min); + + return $this; + } + + public function step($step) + { + $this->setAttribute('step', $step); + + return $this; + } + + public function defaultValue($value) + { + if (!$this->hasValue()) { + $this->setValue($value); + } + + return $this; + } + + protected function hasValue() + { + return isset($this->attributes['value']); + } +} diff --git a/tests/NumberTest.php b/tests/NumberTest.php new file mode 100644 index 0000000..e4aee58 --- /dev/null +++ b/tests/NumberTest.php @@ -0,0 +1,64 @@ +defaultValue(0); + + $expected = ''; + $this->assertSame($expected, $number->render()); + } + + public function testMinValue() + { + $number = new Number('number'); + $number->min(5); + + $expected = ''; + $this->assertSame($expected, $number->render()); + } + + public function testMaxValue() + { + $number = new Number('number'); + $number->max(10); + + $expected = ''; + $this->assertSame($expected, $number->render()); + } + + public function testStepValue() + { + $number = new Number('number'); + $number->step(1); + + $expected = ''; + $this->assertSame($expected, $number->render()); + } + + public function testPlaceholderValue() + { + $number = new Number('number'); + $number->placeholder('Number'); + + $expected = ''; + $this->assertSame($expected, $number->render()); + } +}