Commit b65935f9 authored by Karamel's avatar Karamel
Browse files

Fix infinite loop when checking PaymentModeReturn equality (affecting Tickets)

parent 4e8f498a
......@@ -104,4 +104,14 @@ class PaymentModeReturn extends DoctrineEmbeddedModel
public function getReturnMode() { return $this->returnMode; }
public function setReturnMode($returnMode) { $this->returnMode = $returnMode; }
/** @Override from DoctrineModel */
protected function associationEquals($o, $field) {
if ($field['name'] != 'returnMode') {
return parent::associationEquals($o, $field);
}
// Special check to break infinite loop in return mode
$thisVal = $this->getReturnMode();
$oVal = $o->getReturnMode();
return ($thisVal->getReference() == $oVal->getReference());
}
}
......@@ -254,4 +254,18 @@ class PaymentModeTest extends TestCase
$pm2->addValue($value4);
$this->assertFalse($pm->equals($pm2));
}
public function testEqualsReturnLoop() {
$pm = new PaymentMode();
$pm->setReference('test');
$pm->setLabel('Test mode');
$ret = new PaymentModeReturn();
$pm->addReturn($ret);
$pm2 = new PaymentMode();
$pm2->setReference('test');
$pm2->setLabel('Test mode');
$ret2 = new PaymentModeReturn();
$pm2->addReturn($ret2);
$this->assertTrue($pm->equals($pm2));
}
}
......@@ -425,6 +425,37 @@ class HttpTicketTest extends TestCase
$this->assertEquals(0, count($data['errors']), $resp);
}
/** @depends testSingle */
public function testSingleTwice() {
$tkt = $this->getBaseTicket(1);
$tkt['lines'][] = $this->getBaseLine(0, 'test', 11.0);
$tkt['taxes'][] = $this->getBaseTax(10.0, 1.0);
$tkt['payments'][] = $this->getBasePayment(0, 11.0);
$daoTkt = new Ticket();
$daoTkt->merge($tkt, $this->dao);
$this->dao->write($daoTkt);
$this->dao->commit();
$this->dao->close();
sleep(10);
curl_setopt($this->curl, CURLOPT_POSTFIELDS,
'tickets=' . json_encode([$tkt]));
$resp = curl_exec($this->curl);
$this->assertEquals(200, curl_getinfo($this->curl, CURLINFO_HTTP_CODE));
$data = json_decode($resp, true);
$this->assertNotNull($data, $resp);
$this->assertEquals(1, count($data['successes']), $resp);
$s = $data['successes'][0];
$this->assertEquals($this->cash->getId(), $s['cashRegister'], $resp);
$this->assertEquals($this->session->getSequence(), $s['sequence'], $resp);
$this->assertEquals(1, $s['number'], $resp);
global $dbInfo;
$this->dao = DAOFactory::getDAO($dbInfo, ['debug' => true]);
$snap = readTicketSnapshot($this->cash, $s['sequence'], $s['number'], $this->dao);
$this->assertTicketModelEqStruct($snap, $tkt);
$this->assertEquals(0, count($data['failures']), $resp);
$this->assertEquals(0, count($data['errors']), $resp);
}
public function testSingleOldDesktop() {
$tkt = $this->getBaseTicket(1);
$tkt['lines'][] = $this->getBaseLine(0, 'test', 11.0);
......
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