From dd5c3b0f54b00c53e5a7e17d63655037f74d3e24 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 10 Jan 2014 12:51:58 -0500
Subject: [PATCH] Added loader test.

---
 .../src/VuFindTest/Record/LoaderTest.php      | 98 +++++++++++++++++++
 1 file changed, 98 insertions(+)
 create mode 100644 module/VuFind/tests/unit-tests/src/VuFindTest/Record/LoaderTest.php

diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Record/LoaderTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Record/LoaderTest.php
new file mode 100644
index 00000000000..39ade403878
--- /dev/null
+++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Record/LoaderTest.php
@@ -0,0 +1,98 @@
+<?php
+
+/**
+ * Record loader tests.
+ *
+ * PHP version 5
+ *
+ * Copyright (C) Villanova University 2010.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * @category VuFind2
+ * @package  Tests
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     http://vufind.org/wiki/vufind2:unit_tests Wiki
+ */
+
+namespace VuFindTest\Record;
+
+use VuFind\Record\Loader;
+use VuFind\RecordDriver\AbstractBase as RecordDriver;
+use VuFind\RecordDriver\PluginManager as RecordFactory;
+use VuFindSearch\Response\RecordCollectionInterface;
+use VuFindSearch\Service as SearchService;
+use VuFindTest\Unit\TestCase as TestCase;
+
+/**
+ * Record loader tests.
+ *
+ * @category VuFind2
+ * @package  Tests
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     http://vufind.org/wiki/vufind2:unit_tests Wiki
+ */
+class LoaderTest extends TestCase
+{
+    /**
+     * Test exception for missing record.
+     *
+     * @return void
+     * @expectedException VuFind\Exception\RecordMissing
+     * @expectedExceptionMessage Record VuFind:test does not exist.
+     */
+    public function testMissingRecord()
+    {
+        $collection = $this->getCollection(array());
+        $service = $this->getMock('VuFindSearch\Service');
+        $service->expects($this->once())->method('retrieve')
+            ->with($this->equalTo('VuFind'), $this->equalTo('test'))
+            ->will($this->returnValue($collection));
+        $loader = $this->getLoader($service);
+        $loader->load('test');
+    }
+
+    /**
+     * Build a loader to test.
+     *
+     * @param SearchService $service Search service
+     * @param RecordFactory $factory Record factory (optional)
+     *
+     * @return Loader
+     */
+    protected function getLoader(SearchService $service, RecordFactory $factory = null)
+    {
+        if (null === $factory) {
+            $factory = $this->getMock('VuFind\RecordDriver\PluginManager');
+        }
+        return new Loader($service, $factory);
+    }
+
+    /**
+     * Get a fake record collection.
+     *
+     * @param array $records Record(s) to retrieve
+     *
+     * @return RecordCollectionInterface
+     */
+    protected function getCollection($records)
+    {
+        $collection = $this->getMock('VuFindSearch\Response\RecordCollectionInterface');
+        $collection->expects($this->any())->method('getRecords')->will($this->returnValue($records));
+        $collection->expects($this->any())->method('count')->will($this->returnValue(count($records)));
+        return $collection;
+    }
+}
\ No newline at end of file
-- 
GitLab