first import

This commit is contained in:
bachy
2013-03-12 15:26:34 +01:00
commit 6a402551d7
109 changed files with 32515 additions and 0 deletions

View File

@@ -0,0 +1,439 @@
<?php
/**
* Copyright (c) 2007-2011, Servigistics, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Servigistics, Inc. nor the names of
* its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
* @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
*
* @package Apache
* @subpackage Solr
* @author Donovan Jimenez <djimenez@conduit-it.com>
*/
/**
* Apache_Solr_Document Unit Test
*/
class Apache_Solr_DocumentTest extends PHPUnit_Framework_TestCase
{
/**
* Fixture used for testing
*
* @var Apache_Solr_Document
*/
private $_fixture;
/**
* Setup for the fixture before each unit test - part of test case API
*/
protected function setup()
{
$this->_fixture = new Apache_Solr_Document();
}
/**
* Teardown after each unit test - part of test case API
*/
protected function tearDown()
{
unset($this->_fixture);
}
public function testDefaultStateAfterConstructor()
{
// document boost should be false
$this->assertFalse($this->_fixture->getBoost());
// document fields should be empty
$this->assertEquals(0, count($this->_fixture->getFieldNames()));
$this->assertEquals(0, count($this->_fixture->getFieldValues()));
$this->assertEquals(0, count($this->_fixture->getFieldBoosts()));
// document iterator should be empty
$this->assertEquals(0, iterator_count($this->_fixture));
}
public function testSetAndGetField()
{
$field = 'field';
$value = 'value';
$boost = 0.5;
// set the field
$this->_fixture->setField($field, $value, $boost);
$result = $this->_fixture->getField($field);
// check the array values
$this->assertTrue(is_array($result));
$this->assertEquals($field, $result['name']);
$this->assertEquals($value, $result['value']);
$this->assertEquals($boost, $result['boost']);
}
public function testGetFieldReturnsFalseForNonExistentField()
{
$this->assertFalse($this->_fixture->getField('field'));
}
public function testMagicGetForFieldValues()
{
$field = 'field';
$value = 'value';
$this->_fixture->setField($field, $value);
// test the __get value
$this->assertEquals($value, $this->_fixture->{$field});
}
/**
* Added for issue #48 (http://code.google.com/p/solr-php-client/issues/detail?id=48)
*/
public function testMagicGetReturnsNullForNonExistentField()
{
$this->assertNull($this->_fixture->nonExistent);
}
public function testMagicSetForFieldValues()
{
$field = 'field';
$value = 'value';
// set field value with magic __set
$this->_fixture->{$field} = $value;
$fieldArray = $this->_fixture->getField($field);
// set values
$this->assertEquals($field, $fieldArray['name']);
$this->assertEquals($value, $fieldArray['value']);
$this->assertTrue($fieldArray['boost'] === false);
}
public function testMagicIssetForNonExistentField()
{
$this->assertFalse(isset($this->_fixture->field));
}
public function testMagicIssetForExistingField()
{
$field = 'field';
$this->_fixture->{$field} = 'value';
$this->assertTrue(isset($this->_fixture->{$field}));
}
public function testMagicUnsetForExistingField()
{
$field = 'field';
$this->_fixture->{$field} = 'value';
// now unset the field
unset($this->_fixture->{$field});
// now test that its unset
$this->assertFalse(isset($this->_fixture->{$field}));
}
public function testMagicUnsetForNonExistingField()
{
$field = 'field';
unset($this->_fixture->{$field});
// now test that it still does not exist
$this->assertFalse(isset($this->_fixture->{$field}));
}
public function testSetAndGetFieldBoostWithPositiveNumberSetsBoost()
{
$field = 'field';
$boost = 0.5;
$this->_fixture->setFieldBoost($field, $boost);
// test the field boost
$this->assertEquals($boost, $this->_fixture->getFieldBoost($field));
}
public function testSetAndGetFieldBoostWithZeroRemovesBoost()
{
$field = 'field';
$boost = 0;
$this->_fixture->setFieldBoost($field, $boost);
// test the field boost
$this->assertTrue($this->_fixture->getFieldBoost($field) === false);
}
public function testSetAndGetFieldBoostWithNegativeNumberRemovesBoost()
{
$field = 'field';
$boost = -1;
$this->_fixture->setFieldBoost($field, $boost);
// test the field boost
$this->assertTrue($this->_fixture->getFieldBoost($field) === false);
}
public function testSetAndGetFieldBoostWithNonNumberRemovesBoost()
{
$field = 'field';
$boost = "i am not a number";
$this->_fixture->setFieldBoost($field, $boost);
// test the field boost
$this->assertTrue($this->_fixture->getFieldBoost($field) === false);
}
public function testSetAndGetBoostWithPositiveNumberSetsBoost()
{
$boost = 0.5;
$this->_fixture->setBoost($boost);
// the boost should now be set
$this->assertEquals($boost, $this->_fixture->getBoost());
}
public function testSetAndGetBoostWithZeroRemovesBoost()
{
$this->_fixture->setBoost(0);
// should be boolean false
$this->assertTrue($this->_fixture->getBoost() === false);
}
public function testSetAndGetBoostWithNegativeNumberRemovesBoost()
{
$this->_fixture->setBoost(-1);
// should be boolean false
$this->assertTrue($this->_fixture->getBoost() === false);
}
public function testSetAndGetBoostWithNonNumberRemovesBoost()
{
$this->_fixture->setBoost("i am not a number");
// should be boolean false
$this->assertTrue($this->_fixture->getBoost() === false);
}
public function testAddFieldCreatesMultiValueWhenFieldDoesNotExist()
{
$field = 'field';
$value = 'value';
$this->_fixture->addField($field, $value);
// check that value is an array with correct values
$fieldValue = $this->_fixture->{$field};
$this->assertTrue(is_array($fieldValue));
$this->assertEquals(1, count($fieldValue));
$this->assertEquals($value, $fieldValue[0]);
}
/**
* setMultiValue has been deprecated and defers to addField
*
* @deprecated
*/
public function testSetMultiValueCreateMultiValueWhenFieldDoesNotExist()
{
$field = 'field';
$value = 'value';
$this->_fixture->setMultiValue($field, $value);
// check that value is an array with correct values
$fieldValue = $this->_fixture->{$field};
$this->assertTrue(is_array($fieldValue));
$this->assertEquals(1, count($fieldValue));
$this->assertEquals($value, $fieldValue[0]);
}
public function testAddFieldCreatesMultiValueWhenFieldDoesExistAsSingleValue()
{
$field = 'field';
$value1 = 'value1';
$value2 = 'value2';
// set first value as singular value
$this->_fixture->{$field} = $value1;
// add a second value with addField
$this->_fixture->addField($field, $value2);
// check that value is an array with correct values
$fieldValue = $this->_fixture->{$field};
$this->assertTrue(is_array($fieldValue));
$this->assertEquals(2, count($fieldValue));
$this->assertEquals($value1, $fieldValue[0]);
$this->assertEquals($value2, $fieldValue[1]);
}
/**
* setMultiValue has been deprecated and defers to addField
*
* @deprecated
*/
public function testSetMultiValueCreatesMultiValueWhenFieldDoesExistAsSingleValue()
{
$field = 'field';
$value1 = 'value1';
$value2 = 'value2';
// set first value as singular value
$this->_fixture->{$field} = $value1;
// add a second value with addField
$this->_fixture->setMultiValue($field, $value2);
// check that value is an array with correct values
$fieldValue = $this->_fixture->{$field};
$this->assertTrue(is_array($fieldValue));
$this->assertEquals(2, count($fieldValue));
$this->assertEquals($value1, $fieldValue[0]);
$this->assertEquals($value2, $fieldValue[1]);
}
public function testAddFieldWithBoostSetsFieldBoost()
{
$field = 'field';
$boost = 0.5;
$this->_fixture->addField($field, 'value', $boost);
// check the field boost
$this->assertEquals($boost, $this->_fixture->getFieldBoost($field));
}
public function testAddFieldWithBoostMultipliesWithAPreexistingBoost()
{
$field = 'field';
$boost = 0.5;
// set a field with a boost
$this->_fixture->setField($field, 'value1', $boost);
// now add another value with the same boost
$this->_fixture->addField($field, 'value2', $boost);
// new boost should be $boost * $boost
$this->assertEquals($boost * $boost, $this->_fixture->getFieldBoost($field));
}
public function testGetFieldNamesIsInitiallyEmpty()
{
$fieldNames = $this->_fixture->getFieldNames();
$this->assertTrue(empty($fieldNames));
}
public function testGetFieldNamesAfterFieldIsSetIsNotEmpty()
{
$field = 'field';
$this->_fixture->{$field} = 'value';
$fieldNames = $this->_fixture->getFieldNames();
$this->assertTrue(!empty($fieldNames));
$this->assertEquals(1, count($fieldNames));
$this->assertEquals($field, $fieldNames[0]);
}
public function testGetFieldValuesIsInitiallyEmpty()
{
$fieldValues = $this->_fixture->getFieldValues();
$this->assertTrue(empty($fieldValues));
}
public function testGetFieldValuessAfterFieldIsSetIsNotEmpty()
{
$value = 'value';
$this->_fixture->field = $value;
$fieldValues = $this->_fixture->getFieldValues();
$this->assertTrue(!empty($fieldValues));
$this->assertEquals(1, count($fieldValues));
$this->assertEquals($value, $fieldValues[0]);
}
public function testGetIteratorAfterFieldValueIsSet()
{
$field = 'field';
$value = 'value';
$this->_fixture->{$field} = $value;
$itemCount = 0;
foreach ($this->_fixture as $iteratedField => $iteratedValue)
{
++$itemCount;
// test field and value
$this->assertEquals($field, $iteratedField);
$this->assertEquals($value, $iteratedValue);
}
// test number of iterations is 1
$this->assertEquals(1, $itemCount);
}
public function testClearReturnsDocumentToDefaultState()
{
// set the document boost
$this->_fixture->setBoost(0.5);
// set a field
$this->_fixture->someField = "some value";
// clear the document to remove boost and fields
$this->_fixture->clear();
// document boost should now be false
$this->assertFalse($this->_fixture->getBoost());
// document fields should now be empty
$this->assertEquals(0, count($this->_fixture->getFieldNames()));
$this->assertEquals(0, count($this->_fixture->getFieldValues()));
$this->assertEquals(0, count($this->_fixture->getFieldBoosts()));
// document iterator should now be empty
$this->assertEquals(0, iterator_count($this->_fixture));
}
}

View File

@@ -0,0 +1,208 @@
<?php
/**
* Copyright (c) 2007-2011, Servigistics, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Servigistics, Inc. nor the names of
* its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
* @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
*
* @package Apache
* @subpackage Solr
* @author Donovan Jimenez <djimenez@conduit-it.com>
*/
/**
* Apache_Solr_HttpTransport_Abstract Unit Tests
*/
abstract class Apache_Solr_HttpTransport_AbstractTest extends PHPUnit_Framework_TestCase
{
const TIMEOUT = 2;
// request our copyright file from googlecode for GET and HEAD
const GET_URL = "http://solr-php-client.googlecode.com/svn/trunk/COPYING";
const GET_RESPONSE_MIME_TYPE = 'text/plain';
const GET_RESPONSE_ENCODING = 'UTF-8';
const GET_RESPONSE_MATCH = 'Copyright (c) ';
// post to the issue list page with a search for 'meh'
const POST_URL = "http://code.google.com/p/solr-php-client/issues/list";
const POST_DATA = "can=2&q=meh&colspec=ID+Type+Status+Priority+Milestone+Owner+Summary&cells=tiles";
const POST_REQUEST_CONTENT_TYPE = 'application/x-www-form-urlencoded; charset=UTF-8';
const POST_RESPONSE_MIME_TYPE = 'text/html';
const POST_RESPONSE_ENCODING = 'UTF-8';
//const POST_RESPONSE_MATCH = 'not sure';
abstract public function getFixture();
public function testGetDefaultTimeoutWithDefaultConstructor()
{
$fixture = $this->getFixture();
$timeout = $fixture->getDefaultTimeout();
$this->assertGreaterThan(0, $timeout);
}
public function testGetDefaultTimeoutSetToSixtyForBadValues()
{
// first set our default_socket_timeout ini setting
$previousValue = ini_get('default_socket_timeout');
ini_set('default_socket_timeout', 0);
$fixture = $this->getFixture();
$timeout = $fixture->getDefaultTimeout();
// reset timeout
ini_set('default_socket_timeout', $previousValue);
$this->assertEquals(60, $timeout);
}
public function testSetDefaultTimeout()
{
$newTimeout = 1234;
$fixture = $this->getFixture();
$fixture->setDefaultTimeout($newTimeout);
$timeout = $fixture->getDefaultTimeout();
$this->assertEquals($newTimeout, $timeout);
}
public function testPerformGetRequest()
{
$fixture = $this->getFixture();
$fixture->setDefaultTimeout(self::TIMEOUT);
$response = $fixture->performGetRequest(self::GET_URL);
$this->assertType('Apache_Solr_HttpTransport_Response', $response);
$this->assertEquals(200, $response->getStatusCode(), 'Status code was not 200');
$this->assertEquals(self::GET_RESPONSE_MIME_TYPE, $response->getMimeType(), 'mimetype was not correct');
$this->assertEquals(self::GET_RESPONSE_ENCODING, $response->getEncoding(), 'character encoding was not correct');
$this->assertStringStartsWith(self::GET_RESPONSE_MATCH, $response->getBody(), 'body did not start with match text');
}
public function testPerformGetRequestWithTimeout()
{
$fixture = $this->getFixture();
$response = $fixture->performGetRequest(self::GET_URL, self::TIMEOUT);
$this->assertType('Apache_Solr_HttpTransport_Response', $response);
$this->assertEquals(200, $response->getStatusCode(), 'Status code was not 200');
$this->assertEquals(self::GET_RESPONSE_MIME_TYPE, $response->getMimeType(), 'mimetype was not correct');
$this->assertEquals(self::GET_RESPONSE_ENCODING, $response->getEncoding(), 'character encoding was not correct');
$this->assertStringStartsWith(self::GET_RESPONSE_MATCH, $response->getBody(), 'body did not start with match text');
}
public function testPerformHeadRequest()
{
$fixture = $this->getFixture();
$fixture->setDefaultTimeout(self::TIMEOUT);
$response = $fixture->performHeadRequest(self::GET_URL);
// we should get everything the same as a get, except the body
$this->assertType('Apache_Solr_HttpTransport_Response', $response);
$this->assertEquals(200, $response->getStatusCode(), 'Status code was not 200');
$this->assertEquals(self::GET_RESPONSE_MIME_TYPE, $response->getMimeType(), 'mimetype was not correct');
$this->assertEquals(self::GET_RESPONSE_ENCODING, $response->getEncoding(), 'character encoding was not correct');
$this->assertEquals("", $response->getBody(), 'body was not empty');
}
public function testPerformHeadRequestWithTimeout()
{
$fixture = $this->getFixture();
$response = $fixture->performHeadRequest(self::GET_URL, self::TIMEOUT);
// we should get everything the same as a get, except the body
$this->assertType('Apache_Solr_HttpTransport_Response', $response);
$this->assertEquals(200, $response->getStatusCode(), 'Status code was not 200');
$this->assertEquals(self::GET_RESPONSE_MIME_TYPE, $response->getMimeType(), 'mimetype was not correct');
$this->assertEquals(self::GET_RESPONSE_ENCODING, $response->getEncoding(), 'character encoding was not correct');
$this->assertEquals("", $response->getBody(), 'body was not empty');
}
public function testPerformPostRequest()
{
$fixture = $this->getFixture();
$fixture->setDefaultTimeout(self::TIMEOUT);
$response = $fixture->performPostRequest(self::POST_URL, self::POST_DATA, self::POST_REQUEST_CONTENT_TYPE);
$this->assertType('Apache_Solr_HttpTransport_Response', $response);
$this->assertEquals(200, $response->getStatusCode(), 'Status code was not 200');
$this->assertEquals(self::POST_RESPONSE_MIME_TYPE, $response->getMimeType(), 'mimetype was not correct');
$this->assertEquals(self::POST_RESPONSE_ENCODING, $response->getEncoding(), 'character encoding was not correct');
//$this->assertStringStartsWith(self::POST_RESPONSE_MATCH, $response->getBody(), 'body did not start with match text');
}
public function testPerformPostRequestWithTimeout()
{
$fixture = $this->getFixture();
$response = $fixture->performPostRequest(self::POST_URL, self::POST_DATA, self::POST_REQUEST_CONTENT_TYPE, self::TIMEOUT);
$this->assertType('Apache_Solr_HttpTransport_Response', $response);
$this->assertEquals(200, $response->getStatusCode(), 'Status code was not 200');
$this->assertEquals(self::POST_RESPONSE_MIME_TYPE, $response->getMimeType(), 'mimetype was not correct');
$this->assertEquals(self::POST_RESPONSE_ENCODING, $response->getEncoding(), 'character encoding was not correct');
//$this->assertStringStartsWith(self::POST_RESPONSE_MATCH, $response->getBody(), 'body did not start with match text');
}
/**
* Test one session doing multiple requests in multiple orders
*/
public function testMultipleRequests()
{
// initial get request
$this->testPerformGetRequest();
// head following get
$this->testPerformHeadRequest();
// post following head
$this->testPerformPostRequest();
// get following post
$this->testPerformGetRequest();
// post following get
$this->testPerformPostRequest();
// head following post
$this->testPerformHeadRequest();
// get following post
$this->testPerformGetRequest();
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* Copyright (c) 2007-2011, Servigistics, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Servigistics, Inc. nor the names of
* its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
* @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
*
* @package Apache
* @subpackage Solr
* @author Donovan Jimenez <djimenez@conduit-it.com>
*/
/**
* Apache_Solr_HttpTransport_CurlNoReuse Unit Tests
*/
class Apache_Solr_HttpTransport_CurlNoReuseTest extends Apache_Solr_HttpTransport_AbstractTest
{
public function getFixture()
{
// ensure curl is enabled
if (!extension_loaded('curl'))
{
$this->markTestSkipped("curl module is not enabled");
}
return new Apache_Solr_HttpTransport_CurlNoReuse();
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* Copyright (c) 2007-2011, Servigistics, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Servigistics, Inc. nor the names of
* its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
* @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
*
* @package Apache
* @subpackage Solr
* @author Donovan Jimenez <djimenez@conduit-it.com>
*/
/**
* Apache_Solr_HttpTransport_Curl Unit Tests
*/
class Apache_Solr_HttpTransport_CurlTest extends Apache_Solr_HttpTransport_AbstractTest
{
public function getFixture()
{
// ensure curl is enabled
if (!extension_loaded('curl'))
{
$this->markTestSkipped("curl module is not enabled");
}
return new Apache_Solr_HttpTransport_Curl();
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* Copyright (c) 2007-2011, Servigistics, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Servigistics, Inc. nor the names of
* its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
* @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
*
* @package Apache
* @subpackage Solr
* @author Donovan Jimenez <djimenez@conduit-it.com>
*/
/**
* Apache_Solr_HttpTransport_FileGetContents Unit Tests
*/
class Apache_Solr_HttpTransport_FileGetContentsTest extends Apache_Solr_HttpTransport_AbstractTest
{
public function getFixture()
{
// make sure allow_url_fopen is on
if (!ini_get("allow_url_fopen"))
{
$this->markTestSkipped("allow_url_fopen is not enabled");
}
return new Apache_Solr_HttpTransport_FileGetContents();
}
}

View File

@@ -0,0 +1,164 @@
<?php
/**
* Copyright (c) 2007-2011, Servigistics, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Servigistics, Inc. nor the names of
* its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
* @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
*
* @package Apache
* @subpackage Solr
* @author Donovan Jimenez <djimenez@conduit-it.com>
*/
/**
* Apache_Solr_HttpTransport_Response Unit Tests
*/
class Apache_Solr_HttpTransport_ResponseTest extends PHPUnit_Framework_TestCase
{
// generated with the following query string: select?q=solr&wt=json
const STATUS_CODE_200 = 200;
const STATUS_MESSAGE_200 = "OK";
const BODY_200 = '{"responseHeader":{"status":0,"QTime":0,"params":{"q":"solr","wt":"json"}},"response":{"numFound":0,"start":0,"docs":[]}}';
const BODY_200_WITH_DOCUMENTS = '{"responseHeader":{"status":0,"QTime":0,"params":{"q":"*:*","wt":"json"}},"response":{"numFound":1,"start":0,"docs":[{"guid":"dev/2/products/45410/1236981","cit_domain":"products","cit_client":"2","cit_instance":"dev","cit_timestamp":"2010-10-06T18:16:51.573Z","product_code_t":["235784"],"product_id":[1236981],"dealer_id":[45410],"category_id":[1030],"manufacturer_id":[0],"vendor_id":[472],"catalog_id":[202]}]}}';
const CONTENT_TYPE_200 = "text/plain; charset=utf-8";
const MIME_TYPE_200 = "text/plain";
const ENCODING_200 = "utf-8";
// generated with the following query string: select?qt=standad&q=solr&wt=json
// NOTE: the intentional mispelling of the standard in the qt parameter
const STATUS_CODE_400 = 400;
const STATUS_MESSAGE_400 = "Bad Request";
const BODY_400 = '<html><head><title>Apache Tomcat/6.0.24 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 400 - unknown handler: standad</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>unknown handler: standad</u></p><p><b>description</b> <u>The request sent by the client was syntactically incorrect (unknown handler: standad).</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0.24</h3></body></html>';
const CONTENT_TYPE_400 = "text/html; charset=utf-8";
const MIME_TYPE_400 = "text/html";
const ENCODING_400 = "utf-8";
// generated with the following query string: select?q=solr&wt=json on a core that does not exist
const STATUS_CODE_404 = 404;
const STATUS_MESSAGE_404 = "Not Found";
const BODY_404 = '<html><head><title>Apache Tomcat/6.0.24 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - /solr/doesnotexist/select</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>/solr/doesnotexist/select</u></p><p><b>description</b> <u>The requested resource (/solr/doesnotexist/select) is not available.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0.24</h3></body></html>';
const CONTENT_TYPE_404 = "text/html; charset=utf-8";
const MIME_TYPE_404 = "text/html";
const ENCODING_404 = "utf-8";
public static function get0Response()
{
return new Apache_Solr_HttpTransport_Response(null, null, null);
}
public static function get200Response()
{
return new Apache_Solr_HttpTransport_Response(self::STATUS_CODE_200, self::CONTENT_TYPE_200, self::BODY_200);
}
public static function get200ResponseWithDocuments()
{
return new Apache_Solr_HttpTransport_Response(self::STATUS_CODE_200, self::CONTENT_TYPE_200, self::BODY_200_WITH_DOCUMENTS);
}
public static function get400Response()
{
return new Apache_Solr_HttpTransport_Response(self::STATUS_CODE_400, self::CONTENT_TYPE_400, self::BODY_400);
}
public static function get404Response()
{
return new Apache_Solr_HttpTransport_Response(self::STATUS_CODE_404, self::CONTENT_TYPE_404, self::BODY_404);
}
public function testGetStatusCode()
{
$fixture = self::get200Response();
$statusCode = $fixture->getStatusCode();
$this->assertEquals(self::STATUS_CODE_200, $statusCode);
}
public function testGetStatusMessage()
{
$fixture = self::get200Response();
$statusMessage = $fixture->getStatusMessage();
$this->assertEquals(self::STATUS_MESSAGE_200, $statusMessage);
}
public function testGetStatusMessageWithUnknownCode()
{
$fixture = new Apache_Solr_HttpTransport_Response(499, null, null);
$statusMessage = $fixture->getStatusMessage();
$this->assertEquals("Unknown Status", $statusMessage);
}
public function testGetBody()
{
$fixture = self::get200Response();
$body = $fixture->getBody();
$this->assertEquals(self::BODY_200, $body);
}
public function testGetMimeType()
{
$fixture = self::get200Response();
$mimeType = $fixture->getMimeType();
$this->assertEquals(self::MIME_TYPE_200, $mimeType);
}
public function testGetEncoding()
{
$fixture = self::get200Response();
$encoding = $fixture->getEncoding();
$this->assertEquals(self::ENCODING_200, $encoding);
}
public function testGetStatusMessageWhenNotProvided()
{
// test 4 of the most common status code responses, probably don't need
// to test all the codes we have
$fixture = new Apache_Solr_HttpTransport_Response(null, null, null, null, null);
$this->assertEquals("Communication Error", $fixture->getStatusMessage(), 'Did not get correct default status message for status code 0');
$fixture = new Apache_Solr_HttpTransport_Response(200, null, null, null, null);
$this->assertEquals("OK", $fixture->getStatusMessage(), 'Did not get correct default status message for status code 200');
$fixture = new Apache_Solr_HttpTransport_Response(400, null, null, null, null);
$this->assertEquals("Bad Request", $fixture->getStatusMessage(), 'Did not get correct default status message for status code 400');
$fixture = new Apache_Solr_HttpTransport_Response(404, null, null, null, null);
$this->assertEquals("Not Found", $fixture->getStatusMessage(), 'Did not get correct default status message for status code 404');
}
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* Copyright (c) 2007-2011, Servigistics, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Servigistics, Inc. nor the names of
* its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
* @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
*
* @package Apache
* @subpackage Solr
* @author Donovan Jimenez <djimenez@conduit-it.com>
*/
/**
* Apache_Solr_HttpTransportException Unit Tests
*/
class Apache_Solr_HttpTransportExceptionTest extends PHPUnit_Framework_TestCase
{
/**
* @expectedException PHPUnit_Framework_Error
*/
public function testConstructorRequiresResponse()
{
$fixture = new Apache_Solr_HttpTransportException();
}
public function testGetResponse()
{
$response = Apache_Solr_ResponseTest::get0Response();
$fixture = new Apache_Solr_HttpTransportException($response);
$this->assertEquals($response, $fixture->getResponse());
}
}

View File

@@ -0,0 +1,194 @@
<?php
/**
* Copyright (c) 2007-2011, Servigistics, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Servigistics, Inc. nor the names of
* its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
* @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
*
* @package Apache
* @subpackage Solr
* @author Donovan Jimenez <djimenez@conduit-it.com>
*/
/**
* Apache_Solr_Response Unit Test
*/
class Apache_Solr_ResponseTest extends PHPUnit_Framework_TestCase
{
static public function get0Response($createDocuments = true, $collapseSingleValueArrays = true)
{
return new Apache_Solr_Response(Apache_Solr_HttpTransport_ResponseTest::get0Response(), $createDocuments, $collapseSingleValueArrays);
}
static public function get200Response($createDocuments = true, $collapseSingleValueArrays = true)
{
return new Apache_Solr_Response(Apache_Solr_HttpTransport_ResponseTest::get200Response(), $createDocuments, $collapseSingleValueArrays);
}
static public function get200ResponseWithDocuments($createDocuments = true, $collapseSingleValueArrays = true)
{
return new Apache_Solr_Response(Apache_Solr_HttpTransport_ResponseTest::get200ResponseWithDocuments(), $createDocuments, $collapseSingleValueArrays);
}
static public function get400Response($createDocuments = true, $collapseSingleValueArrays = true)
{
return new Apache_Solr_Response(Apache_Solr_HttpTransport_ResponseTest::get400Response(), $createDocuments, $collapseSingleValueArrays);
}
static public function get404Response($createDocuments = true, $collapseSingleValueArrays = true)
{
return new Apache_Solr_Response(Apache_Solr_HttpTransport_ResponseTest::get404Response(), $createDocuments, $collapseSingleValueArrays);
}
public function testConstuctorWithValidBodyAndHeaders()
{
$fixture = self::get200Response();
// check that we parsed the HTTP status correctly
$this->assertEquals(Apache_Solr_HttpTransport_ResponseTest::STATUS_CODE_200, $fixture->getHttpStatus());
// check that we received the body correctly
$this->assertEquals(Apache_Solr_HttpTransport_ResponseTest::BODY_200, $fixture->getRawResponse());
// check that our defaults are correct
$this->assertEquals(Apache_Solr_HttpTransport_ResponseTest::ENCODING_200, $fixture->getEncoding());
$this->assertEquals(Apache_Solr_HttpTransport_ResponseTest::MIME_TYPE_200, $fixture->getType());
}
public function testConstructorWithBadBodyAndHeaders()
{
$fixture = self::get0Response();
// check that our defaults are correct
$this->assertEquals(0, $fixture->getHttpStatus());
$this->assertEquals("UTF-8", $fixture->getEncoding());
$this->assertEquals("text/plain", $fixture->getType());
}
public function testMagicGetWithValidBodyAndHeaders()
{
$fixture = self::get200Response();
// test top level gets
$this->assertType('stdClass', $fixture->responseHeader);
$this->assertEquals(0, $fixture->responseHeader->status);
$this->assertEquals(0, $fixture->responseHeader->QTime);
$this->assertType('stdClass', $fixture->response);
$this->assertEquals(0, $fixture->response->numFound);
$this->assertTrue(is_array($fixture->response->docs));
$this->assertEquals(0, count($fixture->response->docs));
}
/**
* @expectedException Apache_Solr_ParserException
*/
public function testMagicGetWith0Response()
{
$fixture = self::get0Response();
// attempting to magic get a part of the response
// should throw a ParserException
$fixture->responseHeader;
$this->fail("Expected Apache_Solr_ParserException was not raised");
}
/**
* @expectedException Apache_Solr_ParserException
*/
public function testMagicGetWith400Response()
{
$fixture = self::get400Response();
// attempting to magic get a part of the response
// should throw a ParserException
$fixture->responseHeader;
$this->fail("Expected Apache_Solr_ParserException was not raised");
}
/**
* @expectedException Apache_Solr_ParserException
*/
public function testMagicGetWith404Response()
{
$fixture = self::get404Response();
// attempting to magic get a part of the response
// should throw a ParserException
$fixture->responseHeader;
$this->fail("Expected Apache_Solr_ParserException was not raised");
}
public function testCreateDocuments()
{
$fixture = self::get200ResponseWithDocuments();
$this->assertTrue(count($fixture->response->docs) > 0, 'There are not 1 or more documents, cannot test');
$this->assertType('Apache_Solr_Document', $fixture->response->docs[0], 'The first document is not of type Apache_Solr_Document');
}
public function testDontCreateDocuments()
{
$fixture = self::get200ResponseWithDocuments(false);
$this->assertTrue(count($fixture->response->docs) > 0, 'There are not 1 or more documents, cannot test');
$this->assertType('stdClass', $fixture->response->docs[0], 'The first document is not of type stdClass');
}
public function testGetHttpStatusMessage()
{
$fixture = self::get200Response();
$this->assertEquals("OK", $fixture->getHttpStatusMessage());
}
public function testMagicGetReturnsNullForUndefinedData()
{
$fixture = self::get200Response();
$this->assertNull($fixture->doesnotexist);
}
public function testMagicIssetForDefinedProperty()
{
$fixture = self::get200Response();
$this->assertTrue(isset($fixture->responseHeader));
}
public function testMagicIssetForUndefinedProperty()
{
$fixture = self::get200Response();
$this->assertFalse(isset($fixture->doesnotexist));
}
}

View File

@@ -0,0 +1,47 @@
<?php
/**
* Copyright (c) 2007-2011, Servigistics, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Servigistics, Inc. nor the names of
* its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
* @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
*
* @package Apache
* @subpackage Solr
* @author Donovan Jimenez <djimenez@conduit-it.com>
*/
/**
* Apache_Solr_Service_Balancer Unit Tests
*/
class Apache_Solr_Service_BalancerTest extends Apache_Solr_ServiceAbstractTest
{
public function getFixture()
{
return new Apache_Solr_Service_Balancer();
}
}

View File

@@ -0,0 +1,139 @@
<?php
/**
* Copyright (c) 2007-2011, Servigistics, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Servigistics, Inc. nor the names of
* its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
* @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
*
* @package Apache
* @subpackage Solr
* @author Donovan Jimenez <djimenez@conduit-it.com>
*/
/**
* Provides base funcationality test for both Apache_Solr_Service and the
* Apache_Solr_Service_Balancer classes.
*/
abstract class Apache_Solr_ServiceAbstractTest extends PHPUnit_Framework_TestCase
{
/**
* Method that gets the appropriate instance for testing
*/
abstract public function getFixture();
/**
* @dataProvider testEscapeDataProvider
*/
public function testEscape($input, $expectedOutput)
{
$fixture = $this->getFixture();
$this->assertEquals($expectedOutput, $fixture->escape($input));
}
public function testEscapeDataProvider()
{
return array(
array(
"I should look the same",
"I should look the same"
),
array(
"(There) are: ^lots \\ && of spec!al charaters",
"\\(There\\) are\\: \\^lots \\\\ \\&& of spec\\!al charaters"
)
);
}
/**
* @dataProvider testEscapePhraseDataProvider
*/
public function testEscapePhrase($input, $expectedOutput)
{
$fixture = $this->getFixture();
$this->assertEquals($expectedOutput, $fixture->escapePhrase($input));
}
public function testEscapePhraseDataProvider()
{
return array(
array(
"I'm a simple phrase",
"I'm a simple phrase"
),
array(
"I have \"phrase\" characters",
'I have \\"phrase\\" characters'
)
);
}
/**
* @dataProvider testPhraseDataProvider
*/
public function testPhrase($input, $expectedOutput)
{
$fixture = $this->getFixture();
$this->assertEquals($expectedOutput, $fixture->phrase($input));
}
public function testPhraseDataProvider()
{
return array(
array(
"I'm a simple phrase",
'"I\'m a simple phrase"'
),
array(
"I have \"phrase\" characters",
'"I have \\"phrase\\" characters"'
)
);
}
public function testGetCreateDocumentWithDefaultConstructor()
{
$fixture = $this->getFixture();
$this->assertTrue($fixture->getCreateDocuments());
}
public function testSetCreateDocuments()
{
$fixture = $this->getFixture();
$fixture->setCreateDocuments(false);
$this->assertFalse($fixture->getCreateDocuments());
}
}

File diff suppressed because it is too large Load Diff