public function testWrongTypes() { $cart = new StallCart($this->cartVar); $cart->add(4, 5); $this->assertEquals(1, $cart->cartCount()); $cart->add(0, 3); $cart->add(-1, 3); $cart->add("text", 3); $this->assertEquals(1, $cart->cartCount()); $cart->add(3, "text"); $this->assertEquals(1, $cart->cartCount()); $cart->remove("text"); $this->assertEquals(1, $cart->cartCount()); }
<?php require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"; /** * @link https://github.com/anmaslov/stall * @copyright Copyright © Alexey Maslov, 2016 * @license http://opensource.org/licenses/mit-license.php */ if (!CModule::IncludeModule('anmaslov.stall')) { return; } $cart = new StallCart('anmaslov.stall'); $sAction = $_REQUEST['action']; $id = (int) $_REQUEST['id']; $count = (int) $_REQUEST['count']; if ($sAction) { switch ($sAction) { case 'add': $cart->add($id, $count); break; case 'remove': $cart->remove($id, $count); break; } } echo \Bitrix\Main\Web\Json::encode($cart->viewCart());