/** * @covers sBasket::sAddArticle */ public function testsAddArticle() { // No id, expect false $this->assertFalse($this->module->sAddArticle(null)); $this->module->sSYSTEM->sSESSION_ID = uniqid(); $this->session->offsetSet('sessionId', $this->module->sSYSTEM->sSESSION_ID); // Get random article with stock controll and add it to the basket $randomArticleOne = $this->db->fetchRow('SELECT detail.* FROM s_articles_details detail INNER JOIN s_articles article ON article.id = detail.articleID LEFT JOIN s_articles_avoid_customergroups avoid ON avoid.articleID = article.id WHERE detail.active = 1 AND laststock = 1 AND instock > 3 AND avoid.articleID IS NULL AND article.id NOT IN ( SELECT articleID FROM s_articles_avoid_customergroups WHERE customergroupID = 1 ) ORDER BY RAND() LIMIT 1'); // Adding article without quantity adds one $this->module->sAddArticle($randomArticleOne['ordernumber']); $basket = $this->module->sGetBasket(); $this->assertEquals(1, $basket['Quantity']); $this->assertEquals(1, $basket['content'][0]['quantity']); // Adding article with quantity adds correctly, finds stacks $this->module->sAddArticle($randomArticleOne['ordernumber'], 2); $basket = $this->module->sGetBasket(); $this->assertEquals(1, $basket['Quantity']); $this->assertEquals(3, $basket['content'][0]['quantity']); // Start over $this->module->sDeleteBasket(); // Adding article with quantity over stock, check that we have the available stock $this->module->sAddArticle($randomArticleOne['ordernumber'], $randomArticleOne['instock'] + 200); $basket = $this->module->sGetBasket(); $this->assertEquals(1, $basket['Quantity']); $this->assertEquals(min($randomArticleOne['instock'], 100), $basket['content'][0]['quantity']); // Start over $this->module->sDeleteBasket(); // Get random article and add it to the basket $randomArticleTwo = $this->db->fetchRow('SELECT detail.* FROM s_articles_details detail INNER JOIN s_articles article ON article.id = detail.articleID WHERE detail.active = 1 AND laststock = 0 AND instock > 20 AND instock < 70 AND article.id NOT IN ( SELECT articleID FROM s_articles_avoid_customergroups WHERE customergroupID = 1 ) ORDER BY RAND() LIMIT 1'); // Adding article with quantity over stock, check that we have the desired quantity $this->module->sAddArticle($randomArticleTwo['ordernumber'], $randomArticleTwo['instock'] + 20); $basket = $this->module->sGetBasket(); $this->assertEquals(1, $basket['Quantity']); $this->assertEquals(min($randomArticleTwo['instock'] + 20, 100), $basket['content'][0]['quantity']); // Housekeeping $this->db->delete('s_order_basket', array('sessionID = ?' => $this->session->get('sessionId'))); }