Skip to content
Snippets Groups Projects
ServerTest.php 3.25 KiB
Newer Older
Demian Katz's avatar
Demian Katz committed
<?php

/**
 * OAI-PMH server unit test.
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Demian Katz's avatar
Demian Katz committed
 *
 * @category Search
 * @package  Service
 * @author   David Maus <maus@hab.de>
 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
Demian Katz's avatar
Demian Katz committed
 * @link     https://vufind.org/wiki/development
Demian Katz's avatar
Demian Katz committed
 */
namespace VuFindTest\OAI;

use VuFind\OAI\Server;

/**
 * OAI-PMH server unit test.
 *
 * @category Search
 * @package  Service
 * @author   David Maus <maus@hab.de>
 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
Demian Katz's avatar
Demian Katz committed
 * @link     https://vufind.org/wiki/development
Demian Katz's avatar
Demian Katz committed
 */
class ServerTest extends \VuFindTest\Unit\TestCase
{
    /**
     * Test an empty input.
     *
     * @return void
     */
    public function testEmptyInput()
    {
        $server = $this->getServer();
Cloud8's avatar
Cloud8 committed
        $this->assertTrue(false !== strpos($server->getResponse(), '<error code="badVerb">Missing Verb Argument</error>'));
Demian Katz's avatar
Demian Katz committed
    }

    /**
     * Get a server object.
     *
     * @param array  $config  Server configuration
     * @param string $baseURL Server base URL
     * @param array  $params  Incoming query parameters
     *
     * @return Server
     */
    protected function getServer($config = [], $baseURL = 'http://foo',
        $params = []
Demian Katz's avatar
Demian Katz committed
    ) {
        // Force an email into the configuration if missing; this is required by the
        // server.
        if (!isset($config['Site']['email'])) {
            $config['Site']['email'] = 'fake@example.com';
        }

        return new Server(
            $this->getMockResultsManager(),
            $this->getMockRecordLoader(),
            $this->getMockTableManager(),
            new \Zend\Config\Config($config),
            $baseURL,
            $params
        );
    }

    /**
     * Get a mock results manager
     *
     * @return \VuFind\Search\Results\PluginManager
     */
    protected function getMockResultsManager()
    {
        return $this->getMockBuilder('VuFind\Search\Results\PluginManager')
            ->disableOriginalConstructor()
            ->getMock();
    }

    /**
     * Get a mock record loader
     *
     * @return \VuFind\Record\Loader
     */
    protected function getMockRecordLoader()
    {
        return $this->getMockBuilder('VuFind\Record\Loader')
            ->disableOriginalConstructor()
            ->getMock();
    }

    /**
     * Get a mock table manager
     *
     * @return \VuFind\Db\Table\PluginManager
     */
    protected function getMockTableManager()
    {
        return $this->getMockBuilder('VuFind\Db\Table\PluginManager')
            ->disableOriginalConstructor()
            ->getMock();
    }