$result = $this->cObj->stdWrap_round($float, $conf);
$this->assertEquals($expected, $result);
}
-
+
+ /**
+ * Data provider for the hash test
+ *
+ * @return array multi-dimensional array with the second level like this:
+ * 0 => the plain text
+ * 1 => the conf array for the hash stdWrap function
+ * 2 => the expected result
+ *
+ * @see hash
+ */
+ public function hashDataProvider() {
+ $data = array(
+ 'testing md5' => array(
+ 'joh316',
+ array(
+ 'hash' => 'md5'
+ ),
+ 'bacb98acf97e0b6112b1d1b650b84971'
+ ),
+ 'testing sha1' => array(
+ 'joh316',
+ array(
+ 'hash' => 'sha1'
+ ),
+ '063b3d108bed9f88fa618c6046de0dccadcf3158'
+ ),
+ 'testing non-existing hashing algorithm' => array(
+ 'joh316',
+ array(
+ 'hash' => 'non-existing'
+ ),
+ 'joh316'
+ ),
+ 'testing stdWrap capability' => array(
+ 'joh316',
+ array(
+ 'hash.' => array(
+ 'cObject' => 'TEXT',
+ 'cObject.' => array(
+ 'value' => 'md5'
+ )
+ )
+ ),
+ 'bacb98acf97e0b6112b1d1b650b84971'
+ )
+ );
+ return $data;
+ }
+
+ /**
+ * Test for the stdWrap function "hash"
+ *
+ * @param string $text
+ * @param array $conf
+ * @param string $expected
+ * @return void
+ *
+ * @dataProvider hashDataProvider
+ * @test
+ */
+ public function stdWrap_hash($text, array $conf, $expected) {
+ $result = $this->cObj->stdWrap_hash($text, $conf);
+ $this->assertEquals($expected, $result);
+ }
+
/**
* Data provider for the numberFormat test
*
);
return $data;
}
-
+
/**
* Check if stdWrap.numberFormat and all of its properties work properly
*
'char.' => 'array',
'intval' => 'boolean',
'intval.' => 'array',
+ 'hash' => 'string',
+ 'hash.' => 'array',
'round' => 'boolean',
'round.' => 'array',
'numberFormat.' => 'array',
return $content;
}
+ /**
+ * Will return a hashed value of the current content
+ *
+ * @param string Input value undergoing processing in this function.
+ * @param array stdWrap properties for hash.
+ * @return string The processed input value
+ * @link http://php.net/manual/de/function.hash-algos.php for a list of supported hash algorithms
+ */
+ public function stdWrap_hash($content = '', array $conf = array()) {
+ $algorithm = isset($conf['hash.'])
+ ? $this->stdWrap($conf['hash'], $conf['hash.'])
+ : $conf['hash'];
+ if (function_exists('hash') && in_array($algorithm, hash_algos())) {
+ $content = hash($algorithm, $content);
+ }
+ return $content;
+ }
+
/**
* stdWrap_round will return a rounded number with ceil(), floor() or round(), defaults to round()
* Only the english number format is supported . (dot) as decimal point