|
|
@@ -11,6 +11,7 @@ class NumberFormatBehaviorTest extends MyCakeTestCase {
|
|
|
public function setUp() {
|
|
|
parent::setUp();
|
|
|
|
|
|
+ Configure::delete('Localization');
|
|
|
$this->Model = ClassRegistry::init('PaymentMethod');
|
|
|
|
|
|
$this->Model->Behaviors->load('Tools.NumberFormat', array('fields' => array('rel_rate', 'set_rate'), 'output' => true));
|
|
|
@@ -60,8 +61,12 @@ class NumberFormatBehaviorTest extends MyCakeTestCase {
|
|
|
$this->assertSame($res[$this->Model->alias]['rel_rate'], -0.02);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * NumberFormatBehaviorTest::testFind()
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
public function testFind() {
|
|
|
- //echo $this->_header(__FUNCTION__);
|
|
|
$data = array(
|
|
|
'name' => 'some Name',
|
|
|
'set_rate' => '0,1',
|
|
|
@@ -74,19 +79,24 @@ class NumberFormatBehaviorTest extends MyCakeTestCase {
|
|
|
// find all
|
|
|
$res = $this->Model->find('all', array('order' => array('created' => 'DESC')));
|
|
|
$this->assertTrue(!empty($res));
|
|
|
- $this->assertSame(substr($res[0][$this->Model->alias]['set_rate'], 0, 4), '0,10');
|
|
|
- $this->assertSame(substr($res[0][$this->Model->alias]['rel_rate'], 0, 5), '-0,02');
|
|
|
+ $this->assertSame('0,10', substr($res[0][$this->Model->alias]['set_rate'], 0, 4));
|
|
|
+ $this->assertSame('-0,02', substr($res[0][$this->Model->alias]['rel_rate'], 0, 5));
|
|
|
|
|
|
// find first
|
|
|
$res = $this->Model->find('first', array('order' => array('created' => 'DESC')));
|
|
|
$this->assertTrue(!empty($res));
|
|
|
- $this->assertSame($res[$this->Model->alias]['set_rate'], '0,10');
|
|
|
- $this->assertSame($res[$this->Model->alias]['rel_rate'], '-0,0200');
|
|
|
+ $this->assertSame('0,10', $res[$this->Model->alias]['set_rate']);
|
|
|
+ $this->assertSame('-0,0200', $res[$this->Model->alias]['rel_rate']);
|
|
|
|
|
|
$res = $this->Model->find('count', array());
|
|
|
- $this->assertSame($res, 8);
|
|
|
+ $this->assertSame(8, $res);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * NumberFormatBehaviorTest::testStrict()
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
public function testStrict() {
|
|
|
$this->Model->Behaviors->unload('NumberFormat');
|
|
|
$this->Model->Behaviors->load('Tools.NumberFormat', array('fields' => array('rel_rate', 'set_rate'), 'strict' => true));
|
|
|
@@ -102,10 +112,15 @@ class NumberFormatBehaviorTest extends MyCakeTestCase {
|
|
|
|
|
|
$res = $this->Model->data;
|
|
|
//debug($res);
|
|
|
- $this->assertSame($res[$this->Model->alias]['set_rate'], '0#1');
|
|
|
- $this->assertSame($res[$this->Model->alias]['rel_rate'], -0.02);
|
|
|
+ $this->assertSame('0#1', $res[$this->Model->alias]['set_rate']);
|
|
|
+ $this->assertSame(-0.02, $res[$this->Model->alias]['rel_rate']);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * NumberFormatBehaviorTest::testBeforeSave()
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
public function testBeforeSave() {
|
|
|
$this->Model->Behaviors->unload('NumberFormat');
|
|
|
$this->Model->Behaviors->load('Tools.NumberFormat', array('fields' => array('rel_rate', 'set_rate'), 'before' => 'save', 'output' => false));
|
|
|
@@ -120,14 +135,19 @@ class NumberFormatBehaviorTest extends MyCakeTestCase {
|
|
|
|
|
|
$res = $this->Model->find('first', array('order' => array('created' => 'DESC')));
|
|
|
$this->assertTrue(!empty($res));
|
|
|
- $this->assertSame(substr($res[$this->Model->alias]['set_rate'], 0, 4), '2.11');
|
|
|
- $this->assertSame(substr($res[$this->Model->alias]['rel_rate'], 0, 5), '-1.22');
|
|
|
+ $this->assertSame('2.11', substr($res[$this->Model->alias]['set_rate'], 0, 4));
|
|
|
+ $this->assertSame('-1.22', substr($res[$this->Model->alias]['rel_rate'], 0, 5));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * NumberFormatBehaviorTest::testLocaleConv()
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
public function testLocaleConv() {
|
|
|
$res = setlocale(LC_NUMERIC, 'de_DE.utf8', 'german');
|
|
|
$this->skipIf(empty($res));
|
|
|
-
|
|
|
+ debug($res);ob_flush();
|
|
|
$this->assertTrue(!empty($res));
|
|
|
|
|
|
$this->Model->Behaviors->unload('NumberFormat');
|
|
|
@@ -144,8 +164,9 @@ class NumberFormatBehaviorTest extends MyCakeTestCase {
|
|
|
|
|
|
$res = $this->Model->find('first', array('conditions' => array('name' => 'german')));
|
|
|
$this->assertTrue(!empty($res));
|
|
|
- $this->assertSame(substr($res[$this->Model->alias]['set_rate'], 0, 4), '3,11');
|
|
|
- $this->assertSame(substr($res[$this->Model->alias]['rel_rate'], 0, 5), '-4,22');
|
|
|
+ //debug($res);ob_flush();
|
|
|
+ $this->assertSame('3,11', substr($res[$this->Model->alias]['set_rate'], 0, 4));
|
|
|
+ $this->assertSame('-4,22', substr($res[$this->Model->alias]['rel_rate'], 0, 5));
|
|
|
|
|
|
$res = setlocale(LC_NUMERIC, 'en_US.utf8', 'english');
|
|
|
$this->assertTrue(!empty($res));
|
|
|
@@ -165,10 +186,15 @@ class NumberFormatBehaviorTest extends MyCakeTestCase {
|
|
|
$res = $this->Model->find('first', array('conditions' => array('name' => 'english')));
|
|
|
//debug($res);
|
|
|
$this->assertTrue(!empty($res));
|
|
|
- $this->assertSame(substr($res[$this->Model->alias]['set_rate'], 0, 4), '3.21');
|
|
|
- $this->assertSame(substr($res[$this->Model->alias]['rel_rate'], 0, 5), '-4.32');
|
|
|
+ $this->assertSame('3.21', substr($res[$this->Model->alias]['set_rate'], 0, 4));
|
|
|
+ $this->assertSame('-4.32', substr($res[$this->Model->alias]['rel_rate'], 0, 5));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * NumberFormatBehaviorTest::testMultiply()
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
public function testMultiply() {
|
|
|
$this->Model->Behaviors->unload('NumberFormat');
|
|
|
$this->Model->Behaviors->load('Tools.NumberFormat', array('fields' => array('rel_rate', 'set_rate'), 'transform' => array(), 'multiply' => 0.01, 'output' => false));
|
|
|
@@ -185,8 +211,8 @@ class NumberFormatBehaviorTest extends MyCakeTestCase {
|
|
|
$res = $this->Model->find('first', array('conditions' => array('name' => 'multiply')));
|
|
|
//debug($res);
|
|
|
$this->assertTrue(!empty($res));
|
|
|
- $this->assertSame(substr($res[$this->Model->alias]['set_rate'], 0, 4), '1.22');
|
|
|
- $this->assertSame(substr($res[$this->Model->alias]['rel_rate'], 0, 5), '-0.02');
|
|
|
+ $this->assertSame('1.22', substr($res[$this->Model->alias]['set_rate'], 0, 4));
|
|
|
+ $this->assertSame('-0.02', substr($res[$this->Model->alias]['rel_rate'], 0, 5));
|
|
|
|
|
|
$this->Model->Behaviors->unload('NumberFormat');
|
|
|
$this->Model->Behaviors->load('Tools.NumberFormat', array('fields' => array('rel_rate', 'set_rate'), 'transform' => array(), 'multiply' => 0.01, 'output' => true));
|
|
|
@@ -194,8 +220,8 @@ class NumberFormatBehaviorTest extends MyCakeTestCase {
|
|
|
$res = $this->Model->find('first', array('conditions' => array('name' => 'multiply')));
|
|
|
//debug($res);
|
|
|
$this->assertTrue(!empty($res));
|
|
|
- $this->assertSame($res[$this->Model->alias]['set_rate'], '122');
|
|
|
- $this->assertSame($res[$this->Model->alias]['rel_rate'], '-2');
|
|
|
+ $this->assertSame('122', $res[$this->Model->alias]['set_rate']);
|
|
|
+ $this->assertSame('-2', $res[$this->Model->alias]['rel_rate']);
|
|
|
}
|
|
|
|
|
|
}
|