ServiceAbstractTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * Copyright (c) 2007-2011, Servigistics, Inc.
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * - Redistributions of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * - Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * - Neither the name of Servigistics, Inc. nor the names of
  15. * its contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  22. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. * @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  31. * @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
  32. *
  33. * @package Apache
  34. * @subpackage Solr
  35. * @author Donovan Jimenez <djimenez@conduit-it.com>
  36. */
  37. /**
  38. * Provides base funcationality test for both Apache_Solr_Service and the
  39. * Apache_Solr_Service_Balancer classes.
  40. */
  41. abstract class Apache_Solr_ServiceAbstractTest extends PHPUnit_Framework_TestCase
  42. {
  43. /**
  44. * Method that gets the appropriate instance for testing
  45. */
  46. abstract public function getFixture();
  47. /**
  48. * @dataProvider testEscapeDataProvider
  49. */
  50. public function testEscape($input, $expectedOutput)
  51. {
  52. $fixture = $this->getFixture();
  53. $this->assertEquals($expectedOutput, $fixture->escape($input));
  54. }
  55. public function testEscapeDataProvider()
  56. {
  57. return array(
  58. array(
  59. "I should look the same",
  60. "I should look the same"
  61. ),
  62. array(
  63. "(There) are: ^lots \\ && of spec!al charaters",
  64. "\\(There\\) are\\: \\^lots \\\\ \\&& of spec\\!al charaters"
  65. )
  66. );
  67. }
  68. /**
  69. * @dataProvider testEscapePhraseDataProvider
  70. */
  71. public function testEscapePhrase($input, $expectedOutput)
  72. {
  73. $fixture = $this->getFixture();
  74. $this->assertEquals($expectedOutput, $fixture->escapePhrase($input));
  75. }
  76. public function testEscapePhraseDataProvider()
  77. {
  78. return array(
  79. array(
  80. "I'm a simple phrase",
  81. "I'm a simple phrase"
  82. ),
  83. array(
  84. "I have \"phrase\" characters",
  85. 'I have \\"phrase\\" characters'
  86. )
  87. );
  88. }
  89. /**
  90. * @dataProvider testPhraseDataProvider
  91. */
  92. public function testPhrase($input, $expectedOutput)
  93. {
  94. $fixture = $this->getFixture();
  95. $this->assertEquals($expectedOutput, $fixture->phrase($input));
  96. }
  97. public function testPhraseDataProvider()
  98. {
  99. return array(
  100. array(
  101. "I'm a simple phrase",
  102. '"I\'m a simple phrase"'
  103. ),
  104. array(
  105. "I have \"phrase\" characters",
  106. '"I have \\"phrase\\" characters"'
  107. )
  108. );
  109. }
  110. public function testGetCreateDocumentWithDefaultConstructor()
  111. {
  112. $fixture = $this->getFixture();
  113. $this->assertTrue($fixture->getCreateDocuments());
  114. }
  115. public function testSetCreateDocuments()
  116. {
  117. $fixture = $this->getFixture();
  118. $fixture->setCreateDocuments(false);
  119. $this->assertFalse($fixture->getCreateDocuments());
  120. }
  121. }