Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
solarium
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
solarium
Commits
2463928e
Commit
2463928e
authored
Aug 10, 2012
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved unittest coverage
parent
029c8027
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
659 additions
and
1 deletion
+659
-1
library/Solarium/Plugin/ParallelExecution/Event/Events.php
library/Solarium/Plugin/ParallelExecution/Event/Events.php
+2
-0
library/Solarium/Plugin/ParallelExecution/Event/ExecuteEnd.php
...ry/Solarium/Plugin/ParallelExecution/Event/ExecuteEnd.php
+2
-0
library/Solarium/Plugin/ParallelExecution/Event/ExecuteStart.php
.../Solarium/Plugin/ParallelExecution/Event/ExecuteStart.php
+2
-0
tests/Solarium/Tests/Plugin/BufferedAdd/Event/PostCommitTest.php
...olarium/Tests/Plugin/BufferedAdd/Event/PostCommitTest.php
+55
-0
tests/Solarium/Tests/Plugin/BufferedAdd/Event/PostFlushTest.php
...Solarium/Tests/Plugin/BufferedAdd/Event/PostFlushTest.php
+55
-0
tests/Solarium/Tests/Plugin/BufferedAdd/Event/PreCommitTest.php
...Solarium/Tests/Plugin/BufferedAdd/Event/PreCommitTest.php
+117
-0
tests/Solarium/Tests/Plugin/BufferedAdd/Event/PreFlushTest.php
.../Solarium/Tests/Plugin/BufferedAdd/Event/PreFlushTest.php
+88
-0
tests/Solarium/Tests/Plugin/CustomizeRequest/CustomizeRequestTest.php
...um/Tests/Plugin/CustomizeRequest/CustomizeRequestTest.php
+29
-0
tests/Solarium/Tests/Plugin/Loadbalancer/Event/EndpointFailureTest.php
...m/Tests/Plugin/Loadbalancer/Event/EndpointFailureTest.php
+52
-0
tests/Solarium/Tests/Plugin/ParallelExecution/ParallelExecutionTest.php
.../Tests/Plugin/ParallelExecution/ParallelExecutionTest.php
+0
-1
tests/Solarium/Tests/Plugin/PostBigRequestTest.php
tests/Solarium/Tests/Plugin/PostBigRequestTest.php
+12
-0
tests/Solarium/Tests/QueryType/Extract/QueryTest.php
tests/Solarium/Tests/QueryType/Extract/QueryTest.php
+211
-0
tests/Solarium/Tests/QueryType/Extract/RequestBuilderTest.php
...s/Solarium/Tests/QueryType/Extract/RequestBuilderTest.php
+34
-0
No files found.
library/Solarium/Plugin/ParallelExecution/Event/Events.php
View file @
2463928e
...
...
@@ -40,6 +40,8 @@ namespace Solarium\Plugin\ParallelExecution\Event;
/**
* Event definitions
*
* @codeCoverageIgnore
*/
class
Events
{
...
...
library/Solarium/Plugin/ParallelExecution/Event/ExecuteEnd.php
View file @
2463928e
...
...
@@ -41,6 +41,8 @@ use Symfony\Component\EventDispatcher\Event;
/**
* ExecuteEnd event, see Events for details
*
* @codeCoverageIgnore
*/
class
ExecuteEnd
extends
Event
{
...
...
library/Solarium/Plugin/ParallelExecution/Event/ExecuteStart.php
View file @
2463928e
...
...
@@ -42,6 +42,8 @@ use Solarium\QueryType\Update\Result;
/**
* ExecuteStart event, see Events for details
*
* @codeCoverageIgnore
*/
class
ExecuteStart
extends
Event
{
...
...
tests/Solarium/Tests/Plugin/BufferedAdd/Event/PostCommitTest.php
0 → 100644
View file @
2463928e
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER 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 HOLDER 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.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
namespace
Solarium\Tests\Plugin\BufferedAdd\Event
;
use
Solarium\Plugin\BufferedAdd\Event\PostCommit
;
use
Solarium\QueryType\Select\Query\Query
;
use
Solarium\Core\Client\Client
;
use
Solarium\Core\Client\Response
;
use
Solarium\Core\Query\Result\Result
;
class
PostCommitTest
extends
\PHPUnit_Framework_TestCase
{
public
function
testConstructorAndGetter
()
{
$client
=
new
Client
;
$query
=
$client
->
createSelect
();
$query
->
setQuery
(
'test123'
);
$response
=
new
Response
(
''
,
array
(
'HTTP 1.0 200 OK'
));
$result
=
new
Result
(
$client
,
$query
,
$response
);
$event
=
new
PostCommit
(
$result
);
$this
->
assertEquals
(
$result
,
$event
->
getResult
());
}
}
tests/Solarium/Tests/Plugin/BufferedAdd/Event/PostFlushTest.php
0 → 100644
View file @
2463928e
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER 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 HOLDER 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.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
namespace
Solarium\Tests\Plugin\BufferedAdd\Event
;
use
Solarium\Plugin\BufferedAdd\Event\PostFlush
;
use
Solarium\QueryType\Select\Query\Query
;
use
Solarium\Core\Client\Client
;
use
Solarium\Core\Client\Response
;
use
Solarium\Core\Query\Result\Result
;
class
PostFlushTest
extends
\PHPUnit_Framework_TestCase
{
public
function
testConstructorAndGetter
()
{
$client
=
new
Client
;
$query
=
$client
->
createSelect
();
$query
->
setQuery
(
'test123'
);
$response
=
new
Response
(
''
,
array
(
'HTTP 1.0 200 OK'
));
$result
=
new
Result
(
$client
,
$query
,
$response
);
$event
=
new
PostFlush
(
$result
);
$this
->
assertEquals
(
$result
,
$event
->
getResult
());
}
}
tests/Solarium/Tests/Plugin/BufferedAdd/Event/PreCommitTest.php
0 → 100644
View file @
2463928e
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER 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 HOLDER 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.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
namespace
Solarium\Tests\Plugin\BufferedAdd\Event
;
use
Solarium\Plugin\BufferedAdd\Event\PreCommit
;
class
PreCommitTest
extends
\PHPUnit_Framework_TestCase
{
public
function
testConstructorAndGetters
()
{
$buffer
=
array
(
1
,
2
,
3
);
$overwrite
=
true
;
$waitFlush
=
false
;
$waitSearcher
=
true
;
$expungeDeletes
=
false
;
$event
=
new
PreCommit
(
$buffer
,
$overwrite
,
$waitFlush
,
$waitSearcher
,
$expungeDeletes
);
$this
->
assertEquals
(
$buffer
,
$event
->
getBuffer
());
$this
->
assertEquals
(
$overwrite
,
$event
->
getOverwrite
());
$this
->
assertEquals
(
$waitFlush
,
$event
->
getWaitFlush
());
$this
->
assertEquals
(
$waitSearcher
,
$event
->
getWaitSearcher
());
$this
->
assertEquals
(
$expungeDeletes
,
$event
->
getExpungeDeletes
());
return
$event
;
}
/**
* @depends testConstructorAndGetters
*
* @param PreCommit $event
*/
public
function
testSetAndGetBuffer
(
$event
)
{
$buffer
=
array
(
4
,
5
,
6
);
$event
->
setBuffer
(
$buffer
);
$this
->
assertEquals
(
$buffer
,
$event
->
getBuffer
());
}
/**
* @depends testConstructorAndGetters
*
* @param PreCommit $event
*/
public
function
testSetAndGetExpungeDeletes
(
$event
)
{
$expungeDeletes
=
true
;
$event
->
setExpungeDeletes
(
$expungeDeletes
);
$this
->
assertEquals
(
$expungeDeletes
,
$event
->
getExpungeDeletes
());
}
/**
* @depends testConstructorAndGetters
*
* @param PreCommit $event
*/
public
function
testSetAndGetOverwrite
(
$event
)
{
$overwrite
=
false
;
$event
->
setOverwrite
(
$overwrite
);
$this
->
assertEquals
(
$overwrite
,
$event
->
getOverwrite
());
}
/**
* @depends testConstructorAndGetters
*
* @param PreCommit $event
*/
public
function
testSetAndGetWaitFlush
(
$event
)
{
$waitFlush
=
true
;
$event
->
setWaitFlush
(
$waitFlush
);
$this
->
assertEquals
(
$waitFlush
,
$event
->
getWaitFlush
());
}
/**
* @depends testConstructorAndGetters
*
* @param PreCommit $event
*/
public
function
testSetAndGetWaitSearcher
(
$event
)
{
$waitSearcher
=
false
;
$event
->
setWaitSearcher
(
$waitSearcher
);
$this
->
assertEquals
(
$waitSearcher
,
$event
->
getWaitSearcher
());
}
}
tests/Solarium/Tests/Plugin/BufferedAdd/Event/PreFlushTest.php
0 → 100644
View file @
2463928e
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER 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 HOLDER 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.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
namespace
Solarium\Tests\Plugin\BufferedAdd\Event
;
use
Solarium\Plugin\BufferedAdd\Event\PreFlush
;
class
PreFlushTest
extends
\PHPUnit_Framework_TestCase
{
public
function
testConstructorAndGetters
()
{
$buffer
=
array
(
1
,
2
,
3
);
$overwrite
=
true
;
$commitWithin
=
567
;
$event
=
new
PreFlush
(
$buffer
,
$overwrite
,
$commitWithin
);
$this
->
assertEquals
(
$buffer
,
$event
->
getBuffer
());
$this
->
assertEquals
(
$overwrite
,
$event
->
getOverwrite
());
$this
->
assertEquals
(
$commitWithin
,
$event
->
getCommitWithin
());
return
$event
;
}
/**
* @depends testConstructorAndGetters
*
* @param PreFlush $event
*/
public
function
testSetAndGetBuffer
(
$event
)
{
$buffer
=
array
(
4
,
5
,
6
);
$event
->
setBuffer
(
$buffer
);
$this
->
assertEquals
(
$buffer
,
$event
->
getBuffer
());
}
/**
* @depends testConstructorAndGetters
*
* @param PreFlush $event
*/
public
function
testSetAndGetCommitWithin
(
$event
)
{
$commitWithin
=
321
;
$event
->
setCommitWithin
(
$commitWithin
);
$this
->
assertEquals
(
$commitWithin
,
$event
->
getCommitWithin
());
}
/**
* @depends testConstructorAndGetters
*
* @param PreFlush $event
*/
public
function
testSetAndGetOverwrite
(
$event
)
{
$overwrite
=
false
;
$event
->
setOverwrite
(
$overwrite
);
$this
->
assertEquals
(
$overwrite
,
$event
->
getOverwrite
());
}
}
tests/Solarium/Tests/Plugin/CustomizeRequest/CustomizeRequestTest.php
View file @
2463928e
...
...
@@ -32,7 +32,9 @@
namespace
Solarium\Tests\Plugin\CustomizeRequest
;
use
Solarium\Plugin\CustomizeRequest\CustomizeRequest
;
use
Solarium\Plugin\CustomizeRequest\Customization
;
use
Solarium\Core\Client\Client
;
use
Solarium\Core\Client\Request
;
use
Solarium\Core\Client\Response
;
use
Solarium\Core\Client\Endpoint
;
use
Solarium\Core\Event\PreExecuteRequest
as
PreExecuteRequestEvent
;
...
...
@@ -90,6 +92,33 @@ class CustomizeRequestTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
false
,
$id
->
getOverwrite
());
}
public
function
testPluginIntegration
()
{
$client
=
new
Client
;
$client
->
registerPlugin
(
'testplugin'
,
$this
->
plugin
);
$input
=
array
(
'key'
=>
'xid'
,
'type'
=>
'param'
,
'name'
=>
'xid'
,
'value'
=>
123
,
);
$this
->
plugin
->
addCustomization
(
$input
);
$originalRequest
=
new
Request
();
$expectedRequest
=
new
Request
();
$expectedRequest
->
addParam
(
'xid'
,
123
);
// this should be the effect of the customization
$observer
=
$this
->
getMock
(
'Solarium\Core\Client\Adapter\Http'
,
array
(
'execute'
));
$observer
->
expects
(
$this
->
once
())
->
method
(
'execute'
)
->
with
(
$this
->
equalTo
(
$expectedRequest
))
->
will
(
$this
->
returnValue
(
new
Response
(
''
,
array
(
'HTTP 1.0 200 OK'
))));
$client
->
setAdapter
(
$observer
);
$client
->
executeRequest
(
$originalRequest
);
}
public
function
testCreateCustomization
()
{
$customization
=
$this
->
plugin
->
createCustomization
(
'id1'
);
...
...
tests/Solarium/Tests/Plugin/Loadbalancer/Event/EndpointFailureTest.php
0 → 100644
View file @
2463928e
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER 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 HOLDER 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.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
namespace
Solarium\Tests\Plugin\Loadbalancer\Event
;
use
Solarium\Plugin\Loadbalancer\Event\EndpointFailure
;
use
Solarium\Core\Client\Client
;
use
Solarium\Exception\HttpException
;
class
EndpointFailureTest
extends
\PHPUnit_Framework_TestCase
{
public
function
testConstructorAndGetters
()
{
$client
=
new
Client
;
$endpoint
=
$client
->
getEndpoint
();
$httpException
=
new
HttpException
(
'test exception'
);
$event
=
new
EndpointFailure
(
$endpoint
,
$httpException
);
$this
->
assertEquals
(
$endpoint
,
$event
->
getEndpoint
());
$this
->
assertEquals
(
$httpException
,
$event
->
getException
());
}
}
tests/Solarium/Tests/Plugin/ParallelExecution/ParallelExecutionTest.php
View file @
2463928e
...
...
@@ -43,7 +43,6 @@ class ParallelExecutionTest extends \PHPUnit_Framework_TestCase
public
function
setUp
()
{
$this
->
plugin
=
new
ParallelExecution
();
}
public
function
testAddAndGetQueries
()
...
...
tests/Solarium/Tests/Plugin/PostBigRequestTest.php
View file @
2463928e
...
...
@@ -112,4 +112,16 @@ class PostBigRequestTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
$requestInput
,
$requestOutput
);
}
public
function
testPluginIntegration
()
{
$client
=
new
Client
;
$client
->
registerPlugin
(
'testplugin'
,
$this
->
plugin
);
$this
->
plugin
->
setMaxQueryStringLength
(
1
);
// this forces POST for even the smallest queries
$query
=
$client
->
createSelect
();
$request
=
$client
->
createRequest
(
$query
);
// default method is GET, the plugin should have changed this to POST
$this
->
assertEquals
(
Request
::
METHOD_POST
,
$request
->
getMethod
());
}
}
tests/Solarium/Tests/QueryType/Extract/QueryTest.php
0 → 100644
View file @
2463928e
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER 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 HOLDER 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.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
namespace
Solarium\Tests\QueryType\Extract
;
use
Solarium\Core\Client\Client
;
use
Solarium\QueryType\Update\Query\Document
;
use
Solarium\QueryType\Extract\Query
;
class
QueryTest
extends
\PHPUnit_Framework_TestCase
{
/**
* @var Query
*/
protected
$query
;
public
function
setUp
()
{
$this
->
query
=
new
Query
;
}
public
function
testGetType
()
{
$this
->
assertEquals
(
Client
::
QUERY_EXTRACT
,
$this
->
query
->
getType
());
}
public
function
testGetResponseParser
()
{
$this
->
assertInstanceOf
(
'Solarium\QueryType\Update\ResponseParser'
,
$this
->
query
->
getResponseParser
());
}
public
function
testGetRequestBuilder
()
{
$this
->
assertInstanceOf
(
'Solarium\QueryType\Extract\RequestBuilder'
,
$this
->
query
->
getRequestBuilder
());
}
public
function
testConfigMode
()
{
$mappings
=
array
(
'from1'
=>
'to1'
,
'from2'
=>
'to2'
,
);
$options
=
array
(
'fmap'
=>
$mappings
);
$this
->
query
->
setOptions
(
$options
);
$this
->
assertEquals
(
$mappings
,
$this
->
query
->
getFieldMappings
()
);
}
public
function
testSetAndGetStart
()
{
$doc
=
new
Document
(
array
(
'field1'
,
'value1'
));
$this
->
query
->
setDocument
(
$doc
);
$this
->
assertEquals
(
$doc
,
$this
->
query
->
getDocument
());
}
public
function
testSetAndGetFilename
()
{
$this
->
query
->
setFile
(
__FILE__
);
$this
->
assertEquals
(
__FILE__
,
$this
->
query
->
getFile
());
}
public
function
testSetAndGetUprefix
()
{
$this
->
query
->
setUprefix
(
'dyn_'
);
$this
->
assertEquals
(
'dyn_'
,
$this
->
query
->
getUprefix
());
}
public
function
testSetAndGetDefaultField
()
{
$this
->
query
->
setDefaultField
(
'defaulttext'
);
$this
->
assertEquals
(
'defaulttext'
,
$this
->
query
->
getDefaultField
());
}
public
function
testSetAndGetLowernames
()
{
$this
->
query
->
setLowernames
(
true
);
$this
->
assertEquals
(
true
,
$this
->
query
->
getLowernames
());
}
public
function
testSetAndGetCommit
()
{
$this
->
query
->
setCommit
(
true
);
$this
->
assertEquals
(
true
,
$this
->
query
->
getCommit
());
}
public
function
testSetAndGetCommitWithin
()
{
$this
->
query
->
setCommitWithin
(
458
);
$this
->
assertEquals
(
458
,
$this
->
query
->
getCommitWithin
());
}
public
function
testSetAndGetDocumentClass
()
{
$this
->
query
->
setDocumentClass
(
'Solarium\Tests\QueryType\Extract\MyCustomDoc'
);
$this
->
assertEquals
(
'Solarium\Tests\QueryType\Extract\MyCustomDoc'
,
$this
->
query
->
getDocumentClass
());
return
$this
->
query
;
}
/**
* @depends testSetAndGetDocumentClass
*/
public
function
testCreateDocument
(
$query
)
{
$fields
=
array
(
'key1'
=>
'value1'
,
'key2'
=>
'value2'
);
$boosts
=
array
(
'key1'
=>
1
,
'key2'
=>
2
);
$document
=
$query
->
createDocument
(
$fields
,
$boosts
);
$this
->
assertInstanceOf
(
'Solarium\Tests\QueryType\Extract\MyCustomDoc'
,
$document
);
$this
->
assertEquals
(
$boosts
,
$document
->
getFieldBoosts
());
$this
->
assertEquals
(
$fields
,
$document
->
getFields
());
}
public
function
testAddFieldMapping
()
{
$expectedFields
=
$this
->
query
->
getFieldMappings
();
$expectedFields
[
'newfield'
]
=
'tofield'
;
$this
->
query
->
addFieldMapping
(
'newfield'
,
'tofield'
);
$this
->
assertEquals
(
$expectedFields
,
$this
->
query
->
getFieldMappings
());
return
$this
->
query
;
}
/**
* @depends testAddFieldMapping
* @param Query $query
*/
public
function
testClearFieldMappingss
(
$query
)
{
$query
->
clearFieldMappings
();
$this
->
assertEquals
(
array
(),
$query
->
getFieldMappings
());
return
$query
;
}
/**
* @depends testClearFieldMappingss
* @param Query $query
*/
public
function
testAddFieldMappings
(
$query
)
{
$fields
=
array
(
'field1'
=>
'target1'
,
'field2'
=>
'target2'
);
$query
->
addFieldMappings
(
$fields
);
$this
->
assertEquals
(
$fields
,
$query
->
getFieldMappings
());
return
$query
;
}
/**
* @depends testAddFieldMappings
* @param Query $query
*/
public
function
testRemoveFieldMapping
(
$query
)
{
$query
->
removeFieldMapping
(
'field1'
);
$this
->
assertEquals
(
array
(
'field2'
=>
'target2'
),
$query
->
getFieldMappings
());
return
$query
;
}
/**
* @depends testRemoveFieldMapping
* @param Query $query
*/
public
function
testSetFields
(
$query
)
{
$fields
=
array
(
'field3'
=>
'target3'
,
'field4'
=>
'target4'
);
$query
->
setFieldMappings
(
$fields
);
$this
->
assertEquals
(
$fields
,
$query
->
getFieldMappings
());
}
}
class
MyCustomDoc
extends
Document
{
}
tests/Solarium/Tests/QueryType/Extract/RequestBuilderTest.php
View file @
2463928e
...
...
@@ -84,5 +84,39 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
);
}
public
function
testDocumentFieldAndBoostParams
()
{
$fields
=
array
(
'field1'
=>
'value1'
,
'field2'
=>
'value2'
);
$boosts
=
array
(
'field1'
=>
1
,
'field2'
=>
5
);
$document
=
$this
->
query
->
createDocument
(
$fields
,
$boosts
);
$this
->
query
->
setDocument
(
$document
);
$request
=
$this
->
builder
->
build
(
$this
->
query
);
$this
->
assertEquals
(
array
(
'boost.field1'
=>
1
,
'boost.field2'
=>
5
,
'fmap.from-field'
=>
'to-field'
,
'literal.field1'
=>
'value1'
,
'literal.field2'
=>
'value2'
,
'omitHeader'
=>
true
,
'param1'
=>
'value1'
,
'resource.name'
=>
'RequestBuilderTest.php'
,
'wt'
=>
'json'
,
),
$request
->
getParams
()
);
}
public
function
testDocumentWithBoostThrowsException
()
{
$document
=
$this
->
query
->
createDocument
();
$document
->
setBoost
(
4
);
$this
->
query
->
setDocument
(
$document
);
$this
->
setExpectedException
(
'Solarium\Exception\RuntimeException'
);
$this
->
builder
->
build
(
$this
->
query
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment