Commit cdc75796 authored by Karamel's avatar Karamel
Browse files

Update ProductAPI to make getAll to get all, add getAllVisible (former getAll).

parent c8fa4bd9
......@@ -46,8 +46,8 @@ class ProductAPI extends APIRefHelper
return static::$ARCHIVE_CONDITION;
}
/** Get all Products currently in sold. */
public function getAll($order = null) {
/** Get all the visible (sellable) products, ignore the others. */
public function getAllVisible($order = null) {
$order = $this->getOrder($order);
return $this->dao->search(static::MODEL_NAME,
static::visibleCondition(), null, null, $order);
......
......@@ -77,7 +77,7 @@ class ProductAPITest extends TestCase
$this->dao->close();
}
/** Get all, don't get invisible ones. */
/** Get all, get invisible ones. */
public function testGetAll() {
$prd = new Product();
$prd->setReference('Ref');
......@@ -85,6 +85,7 @@ class ProductAPITest extends TestCase
$prd->setPriceSell(1);
$prd->setCategory($this->cat);
$prd->setTax($this->tax);
$prd->setDispOrder(0);
$archive = new Product();
$archive->setReference('Archive');
$archive->setLabel('Archive');
......@@ -92,15 +93,40 @@ class ProductAPITest extends TestCase
$archive->setCategory($this->cat);
$archive->setTax($this->tax);
$archive->setVisible(false);
$archive->setDispOrder(1);
$this->dao->write($prd);
$this->dao->write($archive);
$this->dao->commit();
$read = $this->api->getAll();
$this->assertEquals(2, count($read));
$this->assertEquals($prd->getId(), $read[0]->getId());
$this->assertEquals($archive->getId(), $read[1]->getId());
}
/** Get all visible, ignore archives. */
public function testGetAllVisible() {
$prd = new Product();
$prd->setReference('Ref');
$prd->setLabel('Label');
$prd->setPriceSell(1);
$prd->setCategory($this->cat);
$prd->setTax($this->tax);
$archive = new Product();
$archive->setReference('Archive');
$archive->setLabel('Archive');
$archive->setPriceSell(3);
$archive->setCategory($this->cat);
$archive->setTax($this->tax);
$archive->setVisible(false);
$this->dao->write($prd);
$this->dao->write($archive);
$this->dao->commit();
$read = $this->api->getAllVisible();
$this->assertEquals(1, count($read));
$this->assertEquals($prd->getId(), $read[0]->getId());
}
/** @depends testGetAll */
/** Get all invisible, ignore visible. */
public function testGetArchive() {
$prd = new Product();
$prd->setReference('Ref');
......
Supports Markdown
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