From 678c6614d2e62b7a0685a09e3281d6fca0704712 Mon Sep 17 00:00:00 2001 From: Matthew Ross Date: Mon, 2 May 2016 20:13:43 -0400 Subject: [PATCH] API models fully tested --- src/api/models/UserOptions.php | 4 +-- src/index.html | 3 ++- test/api/ApiJsonTest.php | 48 +++++++++++++++++++++++++++++++++ test/api/UserOptionsTest.php | 38 +++++++++++++------------- tests.db | Bin 13312 -> 13312 bytes 5 files changed, 72 insertions(+), 21 deletions(-) create mode 100644 test/api/ApiJsonTest.php diff --git a/src/api/models/UserOptions.php b/src/api/models/UserOptions.php index e159128..3e4c459 100644 --- a/src/api/models/UserOptions.php +++ b/src/api/models/UserOptions.php @@ -1,6 +1,6 @@ loadPropertiesFrom($bean); } - public function loadFromJson($obj) { + public function loadFromJson($json) { $obj = json_decode($json); if (!isset($obj->id) || $obj->id === 0) { diff --git a/src/index.html b/src/index.html index c3932a8..2fdc8f2 100644 --- a/src/index.html +++ b/src/index.html @@ -2,7 +2,7 @@ TaskBoard - + @@ -32,3 +32,4 @@ + diff --git a/test/api/ApiJsonTest.php b/test/api/ApiJsonTest.php new file mode 100644 index 0000000..5a51a80 --- /dev/null +++ b/test/api/ApiJsonTest.php @@ -0,0 +1,48 @@ +assertTrue($apiJson->status === 'failure'); + $this->assertArraySubset($apiJson->data, []); + $this->assertArraySubset($apiJson->alerts, []); + } + + public function testSetSuccess() { + $apiJson = new ApiJson(); + $this->assertTrue($apiJson->status === 'failure'); + + $apiJson->setSuccess(); + $this->assertTrue($apiJson->status === 'success'); + } + + public function testSetFailure() { + $apiJson = new ApiJson(); + $apiJson->setSuccess(); + $this->assertTrue($apiJson->status === 'success'); + + $apiJson->setFailure(); + $this->assertTrue($apiJson->status === 'failure'); + } + + public function testAddData() { + $apiJson = new ApiJson(); + + $obj = new stdClass(); + $obj->id = 1; + + $apiJson->addData($obj); + $this->assertArraySubset($apiJson->data, [$obj]); + } + + public function testAddAlert() { + $apiJson = new ApiJson(); + + $alert = new stdClass(); + $alert->type = 'success'; + $alert->text = 'Test message.'; + + $this->assertArraySubset($apiJson->alerts, [$alert]); + } +} + diff --git a/test/api/UserOptionsTest.php b/test/api/UserOptionsTest.php index 108bb30..16ec11b 100644 --- a/test/api/UserOptionsTest.php +++ b/test/api/UserOptionsTest.php @@ -20,7 +20,7 @@ class UserOptionsTest extends PHPUnit_Framework_TestCase { $options = DataMock::getUserOptions(); $this->json = json_encode($options); - $this->bean = $user; + $this->bean = $options; } public function testCreateUserOptions() { @@ -52,27 +52,29 @@ class UserOptionsTest extends PHPUnit_Framework_TestCase { $options->updateBean(); $bean = $options->getBean(); - $this->assertTrue($bean->id === $user->id); - $this->assertTrue($bean->new_tasks_at_bottom === $user->new_tasks_at_bottom); - $this->assertTrue($bean->show_animations === $user->show_animations); - $this->assertTrue($bean->show_assignee === $user->show_assignee); - $this->assertTrue($bean->multiple_tasks_per_row === $user->multiple_tasks_per_row); + $this->assertTrue($bean->id === $options->id); + $this->assertTrue((bool) $bean->new_tasks_at_bottom === + $options->new_tasks_at_bottom); + $this->assertTrue((bool) $bean->show_animations === $options->show_animations); + $this->assertTrue((bool) $bean->show_assignee === $options->show_assignee); + $this->assertTrue((bool) $bean->multiple_tasks_per_row === + $options->multiple_tasks_per_row); } - private function assertDefaultProperties($user) { - $this->assertTrue($user->id === 0); - $this->assertTrue($user->security_level == SecurityLevel::User); - $this->assertTrue($user->username === ''); - $this->assertTrue($user->salt === ''); - $this->assertTrue($user->password_hash === ''); + private function assertDefaultProperties($options) { + $this->assertTrue($options->id === 0); + $this->assertTrue($options->new_tasks_at_bottom === true); + $this->assertTrue($options->show_animations === true); + $this->assertTrue($options->show_assignee === true); + $this->assertTrue($options->multiple_tasks_per_row === false); } - private function assertMockProperties($user) { - $this->assertTrue($user->id === 1); - $this->assertTrue($user->salt === 'salty1234'); - $this->assertTrue($user->password_hash === 'hashpass1234'); - $this->assertTrue($user->email === 'user@example.com'); - $this->assertTrue($user->default_board_id === 1); + private function assertMockProperties($options) { + $this->assertTrue($options->id === 1); + $this->assertTrue($options->new_tasks_at_bottom === false); + $this->assertTrue($options->show_animations === false); + $this->assertTrue($options->show_assignee === false); + $this->assertTrue($options->multiple_tasks_per_row === true); } } diff --git a/tests.db b/tests.db index 0f6e3e8170becb48f21342c8ba616c2c3033bd0f..b89274154a48fcce6a5384113ee7c3dca6d32a5e 100644 GIT binary patch delta 160 zcmZq3Xvml#C8Yj=fq{XSfq{XEfq{XWfkE!qL>(g$^$!fXUl)Od8JX8HFt20U%d~g1 zAklzGj(SwZFw@q`0QJR<VExJHENBqZf07NsC-QBcrPaPtpx^>p_GS*(Fjp~=Mw1`0v0ZmvPD ze$KAJ3J}=@4UoIx^8S7bF0MYVA+8F+t|1D3p*}te{(cIf0WKha!-X`9SlPwhB^et9 zGxJhXE5Jm2T7FS#W_n(BYGr(Keokp_UOd==5H=e$=sf*gTq6|lY5-Z70MV78paC`` zJ~KsAp|O~SU0hOk#GfOh_^N<3+k%^mK zJXn;mQ4{QTFoEpj(&E&j_>|PN#L}D+h`&K1yij-H@HI#YswS}CLBa_N8YrfLLx6#S zA;(#iv5^yOJ($37130`uCh!npH&`*UonQg5T>(sN;@aAbk>Ic{F3ia+NsTW~Ei6sV zOHM`OGDB^Ggg%<21}I>4icz=M|m zp;||&(GVC7fuR)w9E>asqMRkE#U-G+8C0t?UxdJ+<&ROfo?|0m{8!_>Q@-Wm;o(GY-#04ozK124E!&(6!i3F_#B^Z$3|?{FofjL{Gn z4T0et0xZm&jG$fs3#k5QWd6=Dn)`=ybdUONGz3sWfSr+@fs=!i7d+6<$oz+a`45Wx zC}%VTMnhnjhX6A(11B%jGzJ!i1P11HjDZYK84^ISk&T^QJW!djQ58I!2_}%IG?4}s zA+xGT0vyn3N7&@*pqQe~;$j!4*A#7&6DPa4s3>DgI(U*6G!hHKEYNU)OvfgGgh-nT zFHTJ^Ey^sZjL%6eOU*%=1P2)fn$CsIlNTrEl)%^piN(d``9&%58HvRiFu~N^#LOHR z2Yo&p$zbsK@W8BOU|?XB5D!&mY}5rOJ}`kR1wz+tAf-VrXjsG2U`lEQ0nOmqb|e!L z6f~g5f~VaX7#KRKl_Bsr1{~m6oB|dHJB0f4|DgW=X#GFT3;I#-jfMc05MX8o^#DMN zel{^MmovR!T+C?BunCL8K_xWWqDU3ee(7P<2Vn+Q>#84)#IRqM&9Io1zxQ oX#GE^3b#?mjD`T+LIBkNN6P=B>wD=I@}m}whQPpw0I2;B0I`_Vp8x;=