removed Integer type

Instead the more flexible Decimal type (with roundto:0) can be used.
This commit is contained in:
Andreas Gohr
2016-08-10 14:34:28 +02:00
parent 21e6384c78
commit 328db41b8b
4 changed files with 6 additions and 121 deletions

View File

@ -1,64 +0,0 @@
<?php
namespace dokuwiki\plugin\struct\test;
use dokuwiki\plugin\struct\types\Integer;
/**
* Testing the Integer Type
*
* @group plugin_struct
* @group plugins
*/
class Type_Integer_struct_test extends StructTest {
/**
* Provides failing validation data
*
* @return array
*/
public function validateFailProvider() {
return array(
array('foo', '', ''),
array('foo222', '', ''),
array('-5', '0', ''),
array('5', '', '0'),
array('500', '100', '200'),
array('50', '100', '200'),
);
}
/**
* Provides successful validation data
*
* @return array
*/
public function validateSuccessProvider() {
return array(
array('0', '', ''),
array('-5', '', ''),
array('5', '', ''),
array('5', '0', ''),
array('-5', '', '0'),
array('150', '100', '200'),
);
}
/**
* @expectedException \dokuwiki\plugin\struct\meta\ValidationException
* @dataProvider validateFailProvider
*/
public function test_validate_fail($value, $min, $max) {
$integer = new Integer(array('min' => $min, 'max' => $max));
$integer->validate($value);
}
/**
* @dataProvider validateSuccessProvider
*/
public function test_validate_success($value, $min, $max) {
$integer = new Integer(array('min' => $min, 'max' => $max));
$integer->validate($value);
$this->assertTrue(true); // we simply check that no exceptions are thrown
}
}

2
deleted.files Normal file
View File

@ -0,0 +1,2 @@
_test/Type_Integer.test.php
types/Integer.php

View File

@ -101,6 +101,10 @@ class Schema {
$this->sqlite->res_close($res);
foreach($rows as $row) {
if($row['class'] == 'Integer') {
$row['class'] = 'Decimal';
}
$class = 'dokuwiki\\plugin\\struct\\types\\' . $row['class'];
if(!class_exists($class)) {
// This usually never happens, except during development

View File

@ -1,57 +0,0 @@
<?php
namespace dokuwiki\plugin\struct\types;
use dokuwiki\plugin\struct\meta\ValidationException;
/**
* Class Integer
*
* A field accepting integer numbers only
*
* @package dokuwiki\plugin\struct\types
*/
class Integer extends AbstractMultiBaseType {
protected $config = array(
'format' => '%d',
'min' => '',
'max' => ''
);
/**
* Output the stored data
*
* @param string|int $value the value stored in the database
* @param \Doku_Renderer $R the renderer currently used to render the data
* @param string $mode The mode the output is rendered in (eg. XHTML)
* @return bool true if $mode could be satisfied
*/
public function renderValue($value, \Doku_Renderer $R, $mode) {
$R->cdata(sprintf($this->config['format'], $value));
return true;
}
/**
* @param int|string $value
* @return int|string
* @throws ValidationException
*/
public function validate($value) {
$value = parent::validate($value);
if((string) $value != (string) intval($value)) {
throw new ValidationException('Integer needed');
}
if($this->config['min'] !== '' && intval($value) <= intval($this->config['min'])) {
throw new ValidationException('Integer min', intval($this->config['min']));
}
if($this->config['max'] !== '' && intval($value) >= intval($this->config['max'])) {
throw new ValidationException('Integer max', intval($this->config['max']));
}
return $value;
}
}