summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-01-14 20:40:31 -0500
committerFrederic Guillot <fred@kanboard.net>2016-01-14 20:40:31 -0500
commita8f404421f3e404ccd285da861a8cb25f3642f31 (patch)
tree0af51bfb56546d393ecb1b63be20ab348fd519d6 /tests
parent805be7d33155478ef32c4bd3643dcf4025d85a05 (diff)
Fix bug: unable to set currency rate with Postgres
Diffstat (limited to 'tests')
-rw-r--r--tests/units/Model/CurrencyTest.php46
-rw-r--r--tests/units/Validator/CurrencyValidatorTest.php27
2 files changed, 73 insertions, 0 deletions
diff --git a/tests/units/Model/CurrencyTest.php b/tests/units/Model/CurrencyTest.php
new file mode 100644
index 00000000..ee11c0fb
--- /dev/null
+++ b/tests/units/Model/CurrencyTest.php
@@ -0,0 +1,46 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\Currency;
+
+class CurrencyTest extends Base
+{
+ public function testGetAll()
+ {
+ $currencyModel = new Currency($this->container);
+ $currencies = $currencyModel->getAll();
+ $this->assertCount(0, $currencies);
+
+ $this->assertNotFalse($currencyModel->create('USD', 9.9));
+ $currencies = $currencyModel->getAll();
+ $this->assertCount(1, $currencies);
+ $this->assertEquals('USD', $currencies[0]['currency']);
+ $this->assertEquals(9.9, $currencies[0]['rate']);
+ }
+
+ public function testCreate()
+ {
+ $currencyModel = new Currency($this->container);
+ $this->assertNotFalse($currencyModel->create('EUR', 1.2));
+ $this->assertNotFalse($currencyModel->create('EUR', 1.5));
+ }
+
+ public function testUpdate()
+ {
+ $currencyModel = new Currency($this->container);
+ $this->assertNotFalse($currencyModel->create('EUR', 1.1));
+ $this->assertNotFalse($currencyModel->update('EUR', 2.2));
+ }
+
+ public function testGetPrice()
+ {
+ $currencyModel = new Currency($this->container);
+
+ $this->assertEquals(123, $currencyModel->getPrice('USD', 123));
+
+ $this->assertNotFalse($currencyModel->create('EUR', 0.5));
+ $this->assertEquals(50.0, $currencyModel->getPrice('EUR', 100));
+ $this->assertEquals(50.0, $currencyModel->getPrice('EUR', 100)); // test with cached result
+ }
+}
diff --git a/tests/units/Validator/CurrencyValidatorTest.php b/tests/units/Validator/CurrencyValidatorTest.php
new file mode 100644
index 00000000..39c06d44
--- /dev/null
+++ b/tests/units/Validator/CurrencyValidatorTest.php
@@ -0,0 +1,27 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Validator\CurrencyValidator;
+
+class CurrencyValidatorTest extends Base
+{
+ public function testValidation()
+ {
+ $validator = new CurrencyValidator($this->container);
+ $result = $validator->validateCreation(array());
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateCreation(array('currency' => 'EUR'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateCreation(array('rate' => 1.9));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateCreation(array('currency' => 'EUR', 'rate' => 'foobar'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateCreation(array('currency' => 'EUR', 'rate' => 1.25));
+ $this->assertTrue($result[0]);
+ }
+}