diff --git a/module/VuFind/src/VuFind/Cart.php b/module/VuFind/src/VuFind/Cart.php index b23ebcfadf20c7897f0704af71d654e32aef0583..4c9c9faf3258ddd988c4680a70e1b51ebe35b896 100644 --- a/module/VuFind/src/VuFind/Cart.php +++ b/module/VuFind/src/VuFind/Cart.php @@ -295,7 +295,9 @@ class Cart */ protected function setCookie() { + // @codeCoverageIgnoreStart return call_user_func_array('setcookie', func_get_args()); + // @codeCoverageIgnoreEnd } /** diff --git a/module/VuFind/tests/unit-tests/src/CartTest.php b/module/VuFind/tests/unit-tests/src/CartTest.php index 6716bb68a129b38490002502bedb9acea8f16761..2ab4cb9091d21a00322b745fd5a776cbc1f89884 100644 --- a/module/VuFind/tests/unit-tests/src/CartTest.php +++ b/module/VuFind/tests/unit-tests/src/CartTest.php @@ -149,4 +149,94 @@ class CartTest extends \PHPUnit_Framework_TestCase ->with($this->equalTo('vufind_cart_src'), $this->equalTo('VuFind')); $cart->addItem('VuFind|a'); } + + /** + * Test the contains method. + * + * @return void + */ + public function testContains() + { + $cart = $this->getCart(); + $this->assertFalse($cart->contains('VuFind|a')); + $cart->addItem('VuFind|a'); + $this->assertTrue($cart->contains('VuFind|a')); + } + + /** + * Test the "empty cart" method. + * + * @return void + */ + public function testCartCanBeEmptied() + { + $cart = $this->getCart(); + $cart->addItem('VuFind|a'); + $this->assertFalse($cart->isEmpty()); + $cart->emptyCart(); + $this->assertTrue($cart->isEmpty()); + } + + /** + * Test the "remove items" method. + * + * @return void + */ + public function testRemoveItems() + { + $cart = $this->getCart(); + $cart->addItems(array('VuFind|a', 'VuFind|b', 'VuFind|c')); + $cart->removeItems(array('VuFind|a', 'VuFind|b')); + $this->assertTrue($cart->contains('VuFind|c')); + $this->assertFalse($cart->contains('VuFind|a')); + $this->assertFalse($cart->contains('VuFind|b')); + } + + /** + * Test the "get record details" method. + * + * @return void + */ + public function testGetRecordDetails() + { + $this->loader->expects($this->once()) + ->method('loadBatch') + ->with($this->equalTo(array('VuFind|a'))) + ->will($this->returnValue('success')); + $cart = $this->getCart(); + $cart->addItem('VuFind|a'); + $this->assertEquals('success', $cart->getRecordDetails()); + } + + /** + * Test loading values from a VuFind 1.x-style cookie. + * + * @return void + */ + public function testVF1Cookie() + { + $cart = $this->getCart(100, true, array('vufind_cart' => "a\tb\tc")); + $this->assertEquals(3, count($cart->getItems())); + $this->assertTrue($cart->contains('VuFind|a')); + $this->assertTrue($cart->contains('VuFind|b')); + $this->assertTrue($cart->contains('VuFind|c')); + } + + /** + * Test loading values from a VuFind 2.x-style cookie. + * + * @return void + */ + public function testVF2Cookie() + { + $cookies = array( + 'vufind_cart' => "Aa\tBb\tCc", + 'vufind_cart_src' => "VuFind\tSummon\tWorldCat" + ); + $cart = $this->getCart(100, true, $cookies); + $this->assertEquals(3, count($cart->getItems())); + $this->assertTrue($cart->contains('VuFind|a')); + $this->assertTrue($cart->contains('Summon|b')); + $this->assertTrue($cart->contains('WorldCat|c')); + } } \ No newline at end of file