From 405e7d8d2198b26b7cfade4bce1e455527ea79b6 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Wed, 30 Jan 2013 09:12:35 -0500 Subject: [PATCH] Finished up cart tests. --- module/VuFind/src/VuFind/Cart.php | 2 + .../VuFind/tests/unit-tests/src/CartTest.php | 90 +++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/module/VuFind/src/VuFind/Cart.php b/module/VuFind/src/VuFind/Cart.php index b23ebcfadf2..4c9c9faf325 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 6716bb68a12..2ab4cb9091d 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 -- GitLab