Commit 07c1d3c8 authored by Karamel's avatar Karamel
Browse files

Fix some unit tests.

parent 1847037a
......@@ -293,7 +293,7 @@ class ImageAPITest extends TestCase
public function testDeleteImageInexistingModel() {
$img = $this->sampleImage(Image::MODEL_CATEGORY, -1);
$this->api->delete($img->getId());
// It should do nothing
$deletedCount = $this->api->delete($img->getId());
$this->assertEquals(0, $deletedCount);
}
}
......@@ -389,8 +389,6 @@ class TicketAPITest extends TestCase
}
/** @depends testSaveTicket
* @expectedException \BadMethodCallException
* @expectedExceptionMessage Tickets are read only.
* Test writing the same ticket twice (shared references). */
public function testSaveTicketOverwrite() {
$line1 = TicketLine::fromStruct(['dispOrder' => 1,
......@@ -418,10 +416,13 @@ class TicketAPITest extends TestCase
'amount' => 11.0,
'currencyAmount' => 11.0], $this->dao);
$tkt->addPayment($pm1);
$this->api->write($tkt);
$exceptionThrown = false;
try {
$this->api->write($tkt);
$this->api->write($tkt);
} catch (\BadMethodCallException $e) {
$exceptionThrown = true;
$this->assertEquals('Tickets are read only.', $e->getMessage());
$searchTkt = $this->dao->search(Ticket::class);
$this->assertEquals(1, count($searchTkt));
$readfTkt = $this->dao->read(FiscalTicket::class, [
......@@ -439,11 +440,12 @@ class TicketAPITest extends TestCase
$this->assertEquals($fdata['failure'], 'Tickets are read only.');
$this->assertTrue($readfTkt->checkSignature(null));
$this->assertTrue($readEOSTkt->checkSignature($readfTkt));
throw $e;
}
$this->assertTrue($exceptionThrown);
}
/** @depends testSaveTicketOverwrite
* @expectedException \BadMethodCallException
* Test failing the same ticket twice to check that 2 rejects are saved. */
public function testFailTwice() {
$line1 = TicketLine::fromStruct(['dispOrder' => 1,
......@@ -473,6 +475,7 @@ class TicketAPITest extends TestCase
$tkt->addPayment($pm1);
try {
$this->api->write($tkt);
$this->api->write($tkt);
} catch (\BadMethodCallException $e) {
// this is expected, refail
try {
......@@ -502,7 +505,7 @@ class TicketAPITest extends TestCase
$this->assertNotNull($fdata2);
$this->assertEquals($fdata2['failure'], 'Tickets are read only.');
$this->assertTrue($readfTkt->checkSignature(null));
$this->assertTrue($readfTkt->checkSignature($readfTkt));
$this->assertTrue($readfTkt2->checkSignature($readfTkt));
$this->assertTrue($readEOSTkt->checkSignature($readfTkt2));
throw $e;
}
......@@ -609,7 +612,7 @@ class TicketAPITest extends TestCase
}
public function testSaveTicketCashNotOpened() {
$this->markTestIncomplete('Todo');
}
/** @depends testSaveTicket */
......
......@@ -346,6 +346,8 @@ class CashSessionTest extends TestCase
$this->dao->commit();
$struct = $this->emptyStruct();
$session = CashSession::fromStruct($struct, $this->dao);
$this->assertEquals($this->cashRegister->getId(), $session->getCashRegister()->getId());
$this->assertEquals(1, $session->getSequence());
}
/** @depends testFromStructDefaults
......
......@@ -60,10 +60,12 @@ class CategoryTest extends TestCase
$cat->setReference('Ref');
$cat->setLabel('label');
$struct = $cat->toStruct();
$this->assertNull($cat->getId(), $struct['id']);
$this->assertNull($cat->getId());
$this->assertNull($struct['id']);
$this->assertEquals($cat->getReference(), $struct['reference']);
$this->assertEquals($cat->getLabel(), $struct['label']);
$this->assertNull($cat->getParent(), $struct['parent']);
$this->assertNull($cat->getParent());
$this->assertNull($struct['parent']);
$this->assertEquals($cat->hasImage(), $struct['hasImage']);
$this->assertEquals($cat->getDispOrder(), $struct['dispOrder']);
}
......
......@@ -68,7 +68,7 @@ class FiscalTicketTest extends TestCase
$falseTicket = new FiscalTicket();
$falseTicket->setSequence('00001');
$falseTicket->setNumber(0);
$fiscalTicket->setDate(new \DateTime());
$falseTicket->setDate(new \DateTime());
$falseTicket->setContent('I am a ticket');
$falseTicket->sign(null);
$this->assertTrue($fiscalTicket->checkSignature(null));
......
......@@ -81,8 +81,10 @@ class DoctrineDAOTest extends TestCase
'password' => $dbInfo['password']];
$altInfo['name'] = 'imnothere_hehe';
$dao = new DoctrineDAO($altInfo);
$this->markTestIncomplete('Todo');
}
/** @doesNotPerformAssertions */
public function testCreate() {
global $dbInfo;
$dao = new DoctrineDAO($dbInfo);
......@@ -165,6 +167,7 @@ class DoctrineDAOTest extends TestCase
}
/** @depends testCreate
* @doesNotPerformAssertions
* Test Delete, Commit (nothing) .*/
public function testDC() {
global $dbInfo;
......
......@@ -91,20 +91,34 @@ class HttpRoleTest extends TestCase
'Content-Type: application/json']);
$resp = curl_exec($this->curl);
$this->assertEquals(200, curl_getinfo($this->curl, CURLINFO_HTTP_CODE));
$dbUser = $this->dao->search(Role::class,
new DAOCondition('name', '=', 'New Role'));
$this->assertEquals(1, count($dbUser));
$dbRoles = $this->dao->search(Role::class);
$this->assertEquals(2, count($dbRoles));
$found = false;
foreach ($dbRoles as $dbRole) {
if ($dbRole->getId() != $this->role->getId()) {
$snapRole = $this->dao->readSnapshot(Role::class, $dbRole->getId());
$this->assertEquals('New Role', $snapRole->getName());
$found = true;
break;
}
}
$this->assertTrue($found);
}
public function testPostUpdate() {
$this->role->setName('Edited Role');
$struct = $this->role->toStruct();
$struct['name'] = 'Edited Role';
curl_setopt($this->curl, CURLOPT_URL, apiUrl('api/role'));
curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($this->curl, CURLOPT_POSTFIELDS, json_encode($this->role->toStruct()));
curl_setopt($this->curl, CURLOPT_POSTFIELDS, json_encode($struct));
curl_setopt($this->curl, CURLOPT_HTTPHEADER,
[Login::TOKEN_HEADER . ': ' . static::$token,
'Content-Type: application/json']);
$resp = curl_exec($this->curl);
$this->assertEquals(200, curl_getinfo($this->curl, CURLINFO_HTTP_CODE));
$dbUser = $this->dao->search(Role::class);
$this->assertEquals(1, count($dbUser));
$this->assertEquals('Edited Role', $dbUser[0]->getName());
$dbRoles = $this->dao->search(Role::class);
$this->assertEquals(1, count($dbRoles));
$snapRole = $this->dao->readSnapshot(Role::class, $dbRoles[0]->getId());
$this->assertEquals('Edited Role', $snapRole->getName());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment