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
138699a3
Commit
138699a3
authored
Jul 22, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added unittests for grouping component
parent
88b116ab
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
754 additions
and
13 deletions
+754
-13
library/Solarium/Query/Select/Component/Grouping.php
library/Solarium/Query/Select/Component/Grouping.php
+33
-2
tests/Solarium/Client/RequestBuilder/Select/Component/FacetSetTest.php
...m/Client/RequestBuilder/Select/Component/FacetSetTest.php
+1
-1
tests/Solarium/Client/RequestBuilder/Select/Component/GroupingTest.php
...m/Client/RequestBuilder/Select/Component/GroupingTest.php
+69
-0
tests/Solarium/Client/RequestBuilder/Select/Component/HighlightingTest.php
...ient/RequestBuilder/Select/Component/HighlightingTest.php
+6
-6
tests/Solarium/Client/RequestTest.php
tests/Solarium/Client/RequestTest.php
+18
-0
tests/Solarium/Client/ResponseParser/SelectTest.php
tests/Solarium/Client/ResponseParser/SelectTest.php
+32
-0
tests/Solarium/Query/Select/Component/GroupingTest.php
tests/Solarium/Query/Select/Component/GroupingTest.php
+199
-0
tests/Solarium/Query/SelectTest.php
tests/Solarium/Query/SelectTest.php
+12
-2
tests/Solarium/Result/Select/Grouping/FieldGroupTest.php
tests/Solarium/Result/Select/Grouping/FieldGroupTest.php
+87
-0
tests/Solarium/Result/Select/Grouping/QueryGroupTest.php
tests/Solarium/Result/Select/Grouping/QueryGroupTest.php
+113
-0
tests/Solarium/Result/Select/Grouping/ValueGroupTest.php
tests/Solarium/Result/Select/Grouping/ValueGroupTest.php
+96
-0
tests/Solarium/Result/Select/GroupingTest.php
tests/Solarium/Result/Select/GroupingTest.php
+76
-0
tests/Solarium/Result/SelectTest.php
tests/Solarium/Result/SelectTest.php
+12
-2
No files found.
library/Solarium/Query/Select/Component/Grouping.php
View file @
138699a3
...
...
@@ -77,6 +77,28 @@ class Solarium_Query_Select_Component_Grouping extends Solarium_Query_Select_Com
*/
protected
$_queries
=
array
();
/**
* Initialize options
*
* Several options need some extra checks or setup work, for these options
* the setters are called.
*
* @return void
*/
protected
function
_init
()
{
foreach
(
$this
->
_options
AS
$name
=>
$value
)
{
switch
(
$name
)
{
case
'queries'
:
$this
->
setQueries
(
$value
);
break
;
case
'fields'
:
$this
->
setFields
(
$value
);
break
;
}
}
}
/**
* Add a grouping field
*
...
...
@@ -95,11 +117,18 @@ class Solarium_Query_Select_Component_Grouping extends Solarium_Query_Select_Com
/**
* Add multiple grouping fields
*
* @param array $fields
* You can use an array or a comma separated string as input
*
* @param array|string $fields
* @return Solarium_Field_Select_Component_Grouping Provides fluent interface
*/
public
function
addFields
(
$fields
)
{
if
(
is_string
(
$fields
))
{
$fields
=
explode
(
','
,
$fields
);
$fields
=
array_map
(
'trim'
,
$fields
);
}
$this
->
_fields
=
array_merge
(
$this
->
_fields
,
$fields
);
return
$this
;
...
...
@@ -157,11 +186,13 @@ class Solarium_Query_Select_Component_Grouping extends Solarium_Query_Select_Com
/**
* Add multiple grouping queries
*
* @param array $queries
* @param array
|string
$queries
* @return Solarium_Query_Select_Component_Grouping Provides fluent interface
*/
public
function
addQueries
(
$queries
)
{
if
(
!
is_array
(
$queries
))
$queries
=
array
(
$queries
);
$this
->
_queries
=
array_merge
(
$this
->
_queries
,
$queries
);
return
$this
;
...
...
tests/Solarium/Client/RequestBuilder/Select/Component/FacetSetTest.php
View file @
138699a3
...
...
@@ -126,7 +126,7 @@ class Solarium_Client_RequestBuilder_Select_Component_FacetSetTest extends PHPUn
);
$this
->
assertEquals
(
'?facet=true&facet.missing=
1
&facet.limit=10&facet.field={!key=f1}owner&facet.query={!key=f2}category:23&facet.query={!key=f4}category:40'
,
'?facet=true&facet.missing=
true
&facet.limit=10&facet.field={!key=f1}owner&facet.query={!key=f2}category:23&facet.query={!key=f4}category:40'
,
urldecode
(
$request
->
getUri
())
);
}
...
...
tests/Solarium/Client/RequestBuilder/Select/Component/GroupingTest.php
0 → 100644
View file @
138699a3
<?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.
*/
class
Solarium_Client_RequestBuilder_Select_Component_GroupingTest
extends
PHPUnit_Framework_TestCase
{
public
function
testBuild
()
{
$builder
=
new
Solarium_Client_RequestBuilder_Select_Component_Grouping
;
$request
=
new
Solarium_Client_Request
();
$component
=
new
Solarium_Query_Select_Component_Grouping
();
$component
->
setFields
(
array
(
'fieldA'
,
'fieldB'
));
$component
->
setQueries
(
array
(
'cat:1'
,
'cat:2'
));
$component
->
setLimit
(
12
);
$component
->
setOffset
(
2
);
$component
->
setSort
(
'score desc'
);
$component
->
setMainResult
(
true
);
$component
->
setNumberOfGroups
(
false
);
$component
->
setCachePercentage
(
50
);
$request
=
$builder
->
build
(
$component
,
$request
);
$this
->
assertEquals
(
array
(
'group'
=>
'true'
,
'group.field'
=>
array
(
'fieldA'
,
'fieldB'
),
'group.query'
=>
array
(
'cat:1'
,
'cat:2'
),
'group.limit'
=>
12
,
'group.offset'
=>
2
,
'group.sort'
=>
'score desc'
,
'group.main'
=>
'true'
,
'group.ngroups'
=>
'false'
,
'group.cache.percent'
=>
50
,
),
$request
->
getParams
()
);
}
}
tests/Solarium/Client/RequestBuilder/Select/Component/HighlightingTest.php
View file @
138699a3
...
...
@@ -63,12 +63,12 @@ class Solarium_Client_RequestBuilder_Select_Component_HighlightingTest extends P
$this
->
assertEquals
(
array
(
'hl'
=>
true
,
'hl'
=>
'true'
,
'hl.fl'
=>
'fieldA,fieldB'
,
'hl.snippets'
=>
2
,
'hl.fragsize'
=>
3
,
'hl.mergeContiguous'
=>
true
,
'hl.requireFieldMatch'
=>
false
,
'hl.mergeContiguous'
=>
'true'
,
'hl.requireFieldMatch'
=>
'false'
,
'hl.maxAnalyzedChars'
=>
100
,
'hl.alternateField'
=>
'fieldC'
,
'hl.maxAlternateFieldLength'
=>
5
,
...
...
@@ -78,9 +78,9 @@ class Solarium_Client_RequestBuilder_Select_Component_HighlightingTest extends P
'hl.fragmenter'
=>
'myFragmenter'
,
'hl.fragListBuilder'
=>
'myFragListBuilder'
,
'hl.fragmentsBuilder'
=>
'myFragmentsBuilder'
,
'hl.useFastVectorHighlighter'
=>
false
,
'hl.usePhraseHighlighter'
=>
true
,
'hl.highlightMultiTerm'
=>
true
,
'hl.useFastVectorHighlighter'
=>
'false'
,
'hl.usePhraseHighlighter'
=>
'true'
,
'hl.highlightMultiTerm'
=>
'true'
,
'hl.regex.slop'
=>
1.3
,
'hl.regex.pattern'
=>
'mypattern'
,
),
...
...
tests/Solarium/Client/RequestTest.php
View file @
138699a3
...
...
@@ -172,6 +172,24 @@ class Solarium_Client_RequestTest extends PHPUnit_Framework_TestCase
);
}
public
function
testAddParamBoolean
()
{
$params
=
array
(
'param1'
=>
true
,
'param2'
=>
false
,
);
$this
->
_request
->
addParams
(
$params
);
$this
->
assertEquals
(
array
(
'param1'
=>
'true'
,
'param2'
=>
'false'
,
),
$this
->
_request
->
getParams
()
);
}
public
function
testAddParamMultivalue
()
{
$params
=
array
(
...
...
tests/Solarium/Client/ResponseParser/SelectTest.php
View file @
138699a3
...
...
@@ -76,8 +76,40 @@ class Solarium_Client_ResponseParser_SelectTest extends PHPUnit_Framework_TestCa
Solarium_Query_Select
::
COMPONENT_FACETSET
=>
new
Solarium_Result_Select_FacetSet
(
array
())
);
$this
->
assertEquals
(
$components
,
$result
[
'components'
]);
}
public
function
testParseWithoutNumFound
()
{
$data
=
array
(
'response'
=>
array
(
'docs'
=>
array
(
array
(
'fieldA'
=>
1
,
'fieldB'
=>
'Test'
),
array
(
'fieldA'
=>
2
,
'fieldB'
=>
'Test2'
)
),
),
'responseHeader'
=>
array
(
'status'
=>
1
,
'QTime'
=>
13
,
)
);
$query
=
new
Solarium_Query_Select
(
array
(
'documentclass'
=>
'Solarium_Document_ReadWrite'
));
$query
->
getFacetSet
();
$resultStub
=
$this
->
getMock
(
'Solarium_Result_Select'
,
array
(),
array
(),
''
,
false
);
$resultStub
->
expects
(
$this
->
once
())
->
method
(
'getData'
)
->
will
(
$this
->
returnValue
(
$data
));
$resultStub
->
expects
(
$this
->
once
())
->
method
(
'getQuery'
)
->
will
(
$this
->
returnValue
(
$query
));
$parser
=
new
Solarium_Client_ResponseParser_Select
;
$result
=
$parser
->
parse
(
$resultStub
);
$this
->
assertEquals
(
1
,
$result
[
'status'
]);
$this
->
assertEquals
(
13
,
$result
[
'queryTime'
]);
$this
->
assertEquals
(
null
,
$result
[
'numfound'
]);
}
}
tests/Solarium/Query/Select/Component/GroupingTest.php
0 → 100644
View file @
138699a3
<?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.
*/
class
Solarium_Query_Select_Component_GroupingTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Select_Component_Grouping
*/
protected
$_grouping
;
public
function
setUp
()
{
$this
->
_grouping
=
new
Solarium_Query_Select_Component_Grouping
;
}
public
function
testConfigMode
()
{
$options
=
array
(
'fields'
=>
array
(
'fieldA'
,
'fieldB'
),
'queries'
=>
array
(
'cat:3'
,
'cat:4'
),
'limit'
=>
8
,
'offset'
=>
1
,
'sort'
=>
'score desc'
,
'mainresult'
=>
false
,
'numberofgroups'
=>
true
,
'cachepercentage'
=>
45
,
);
$this
->
_grouping
->
setOptions
(
$options
);
$this
->
assertEquals
(
$options
[
'fields'
],
$this
->
_grouping
->
getFields
());
$this
->
assertEquals
(
$options
[
'queries'
],
$this
->
_grouping
->
getQueries
());
$this
->
assertEquals
(
$options
[
'limit'
],
$this
->
_grouping
->
getLimit
());
$this
->
assertEquals
(
$options
[
'offset'
],
$this
->
_grouping
->
getOffset
());
$this
->
assertEquals
(
$options
[
'sort'
],
$this
->
_grouping
->
getSort
());
$this
->
assertEquals
(
$options
[
'mainresult'
],
$this
->
_grouping
->
getMainResult
());
$this
->
assertEquals
(
$options
[
'numberofgroups'
],
$this
->
_grouping
->
getNumberOfGroups
());
$this
->
assertEquals
(
$options
[
'cachepercentage'
],
$this
->
_grouping
->
getCachePercentage
());
}
public
function
testGetType
()
{
$this
->
assertEquals
(
Solarium_Query_Select
::
COMPONENT_GROUPING
,
$this
->
_grouping
->
getType
());
}
public
function
testSetAndGetFieldsSingle
()
{
$value
=
'fieldC'
;
$this
->
_grouping
->
setFields
(
$value
);
$this
->
assertEquals
(
array
(
$value
),
$this
->
_grouping
->
getFields
()
);
}
public
function
testSetAndGetFieldsCommaSeparated
()
{
$value
=
'fieldD, fieldE'
;
$this
->
_grouping
->
setFields
(
$value
);
$this
->
assertEquals
(
array
(
'fieldD'
,
'fieldE'
,
),
$this
->
_grouping
->
getFields
()
);
}
public
function
testSetAndGetFieldsArray
()
{
$values
=
array
(
'fieldD'
,
'fieldE'
);
$this
->
_grouping
->
setFields
(
$values
);
$this
->
assertEquals
(
$values
,
$this
->
_grouping
->
getFields
()
);
}
public
function
testSetAndGetQueriesSingle
()
{
$value
=
'cat:3'
;
$this
->
_grouping
->
setQueries
(
$value
);
$this
->
assertEquals
(
array
(
$value
),
$this
->
_grouping
->
getQueries
()
);
}
public
function
testSetAndGetQueriesArray
()
{
$values
=
array
(
'cat:5'
,
'cat:6'
);
$this
->
_grouping
->
setQueries
(
$values
);
$this
->
assertEquals
(
$values
,
$this
->
_grouping
->
getQueries
()
);
}
public
function
testSetAndGetLimit
()
{
$value
=
'12'
;
$this
->
_grouping
->
setLimit
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_grouping
->
getLimit
()
);
}
public
function
testSetAndGetOffset
()
{
$value
=
'2'
;
$this
->
_grouping
->
setOffset
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_grouping
->
getOffset
()
);
}
public
function
testSetAndGetSort
()
{
$value
=
'price desc'
;
$this
->
_grouping
->
setSort
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_grouping
->
getSort
()
);
}
public
function
testSetAndGetMainResult
()
{
$value
=
true
;
$this
->
_grouping
->
setMainResult
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_grouping
->
getMainResult
()
);
}
public
function
testSetAndGetNumberOfGroups
()
{
$value
=
true
;
$this
->
_grouping
->
setNumberOfGroups
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_grouping
->
getNumberOfGroups
()
);
}
public
function
testSetAndGetCachePercentage
()
{
$value
=
40
;
$this
->
_grouping
->
setCachePercentage
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_grouping
->
getCachePercentage
()
);
}
}
tests/Solarium/Query/SelectTest.php
View file @
138699a3
...
...
@@ -477,11 +477,21 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
public
function
testGetHighlighting
()
{
$
dismax
=
$this
->
_query
->
getHighlighting
();
$
hlt
=
$this
->
_query
->
getHighlighting
();
$this
->
assertEquals
(
'Solarium_Query_Select_Component_Highlighting'
,
get_class
(
$dismax
)
get_class
(
$hlt
)
);
}
public
function
testGetGrouping
()
{
$grouping
=
$this
->
_query
->
getGrouping
();
$this
->
assertEquals
(
'Solarium_Query_Select_Component_Grouping'
,
get_class
(
$grouping
)
);
}
...
...
tests/Solarium/Result/Select/Grouping/FieldGroupTest.php
0 → 100644
View file @
138699a3
<?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.
*/
class
Solarium_Result_Select_Grouping_FieldGroupTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Grouping_FieldGroup
*/
protected
$_group
;
protected
$_matches
,
$_numberOfGroups
,
$_items
;
public
function
setUp
()
{
$this
->
_matches
=
12
;
$this
->
_numberOfGroups
=
6
;
$this
->
_items
=
array
(
'key1'
=>
'content1'
,
'key2'
=>
'content2'
,
);
$this
->
_group
=
new
Solarium_Result_Select_Grouping_FieldGroup
(
$this
->
_matches
,
$this
->
_numberOfGroups
,
$this
->
_items
);
}
public
function
testGetMatches
()
{
$this
->
assertEquals
(
$this
->
_matches
,
$this
->
_group
->
getMatches
()
);
}
public
function
testGetNumberOfGroups
()
{
$this
->
assertEquals
(
$this
->
_numberOfGroups
,
$this
->
_group
->
getNumberOfGroups
()
);
}
public
function
testIterator
()
{
$items
=
array
();
foreach
(
$this
->
_group
AS
$key
=>
$item
)
{
$items
[
$key
]
=
$item
;
}
$this
->
assertEquals
(
$this
->
_items
,
$items
);
}
public
function
testCount
()
{
$this
->
assertEquals
(
count
(
$this
->
_items
),
count
(
$this
->
_group
));
}
}
tests/Solarium/Result/Select/Grouping/QueryGroupTest.php
0 → 100644
View file @
138699a3
<?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.
*/
class
Solarium_Result_Select_Grouping_QueryGroupTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Grouping_QueryGroup
*/
protected
$_group
;
protected
$_matches
,
$_numFound
,
$_start
,
$_maximumScore
,
$_items
;
public
function
setUp
()
{
$this
->
_matches
=
12
;
$this
->
_numFound
=
6
;
$this
->
_start
=
2
;
$this
->
_maximumScore
=
0.89
;
$this
->
_items
=
array
(
'key1'
=>
'content1'
,
'key2'
=>
'content2'
,
);
$this
->
_group
=
new
Solarium_Result_Select_Grouping_QueryGroup
(
$this
->
_matches
,
$this
->
_numFound
,
$this
->
_start
,
$this
->
_maximumScore
,
$this
->
_items
);
}
public
function
testGetMatches
()
{
$this
->
assertEquals
(
$this
->
_matches
,
$this
->
_group
->
getMatches
()
);
}
public
function
testGetNumFound
()
{
$this
->
assertEquals
(
$this
->
_numFound
,
$this
->
_group
->
getNumFound
()
);
}
public
function
testGetStart
()
{
$this
->
assertEquals
(
$this
->
_start
,
$this
->
_group
->
getStart
()
);
}
public
function
testGetMaximumScore
()
{
$this
->
assertEquals
(
$this
->
_maximumScore
,
$this
->
_group
->
getMaximumScore
()
);
}
public
function
testGetDocuments
()
{
$this
->
assertEquals
(
$this
->
_items
,
$this
->
_group
->
getDocuments
()
);
}
public
function
testIterator
()
{
$items
=
array
();
foreach
(
$this
->
_group
AS
$key
=>
$item
)
{
$items
[
$key
]
=
$item
;
}
$this
->
assertEquals
(
$this
->
_items
,
$items
);
}
public
function
testCount
()
{
$this
->
assertEquals
(
count
(
$this
->
_items
),
count
(
$this
->
_group
));
}
}
tests/Solarium/Result/Select/Grouping/ValueGroupTest.php
0 → 100644
View file @
138699a3
<?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.
*/
class
Solarium_Result_Select_Grouping_ValueGroupTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Grouping_ValueGroup
*/
protected
$_group
;
protected
$_value
,
$_numFound
,
$_start
,
$_items
;
public
function
setUp
()
{
$this
->
_value
=
'test value'
;
$this
->
_numFound
=
6
;
$this
->
_start
=
2
;
$this
->
_items
=
array
(
'key1'
=>
'content1'
,
'key2'
=>
'content2'
,
);
$this
->
_group
=
new
Solarium_Result_Select_Grouping_ValueGroup
(
$this
->
_value
,
$this
->
_numFound
,
$this
->
_start
,
$this
->
_items
);
}
public
function
testGetValue
()
{
$this
->
assertEquals
(
$this
->
_value
,
$this
->
_group
->
getValue
()
);
}
public
function
testGetNumFound
()
{
$this
->
assertEquals
(
$this
->
_numFound
,
$this
->
_group
->
getNumFound
()
);
}
public
function
testGetStart
()
{
$this
->
assertEquals
(
$this
->
_start
,
$this
->
_group
->
getStart
()
);
}
public
function
testIterator
()
{
$items
=
array
();
foreach
(
$this
->
_group
AS
$key
=>
$item
)
{
$items
[
$key
]
=
$item
;
}
$this
->
assertEquals
(
$this
->
_items
,
$items
);
}
public
function
testCount
()
{
$this
->
assertEquals
(
count
(
$this
->
_items
),
count
(
$this
->
_group
));
}
}
tests/Solarium/Result/Select/GroupingTest.php
0 → 100644
View file @
138699a3
<?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.
*/
class
Solarium_Result_Select_GroupingTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Grouping
*/
protected
$_grouping
;
protected
$_items
;
public
function
setUp
()
{
$this
->
_items
=
array
(
'key1'
=>
'content1'
,
'key2'
=>
'content2'
,
);
$this
->
_grouping
=
new
Solarium_Result_Select_Grouping
(
$this
->
_items
);
}
public
function
testGetGroups
()
{
$this
->
assertEquals
(
$this
->
_items
,
$this
->
_grouping
->
getGroups
()
);
}
public
function
testIterator
()
{
$items
=
array
();
foreach
(
$this
->
_grouping
AS
$key
=>
$item
)
{
$items
[
$key
]
=
$item
;
}
$this
->
assertEquals
(
$this
->
_items
,
$items
);
}
public
function
testCount
()
{
$this
->
assertEquals
(
count
(
$this
->
_items
),
count
(
$this
->
_grouping
));
}
}
tests/Solarium/Result/SelectTest.php
View file @
138699a3
...
...
@@ -37,7 +37,7 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
*/
protected
$_result
;
protected
$_numFound
,
$_docs
,
$_components
,
$_facetSet
,
$_moreLikeThis
,
$_highlighting
;
protected
$_numFound
,
$_docs
,
$_components
,
$_facetSet
,
$_moreLikeThis
,
$_highlighting
,
$_grouping
;
public
function
setUp
()
{
...
...
@@ -51,11 +51,13 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
$this
->
_facetSet
=
'dummy-facetset-value'
;
$this
->
_moreLikeThis
=
'dummy-facetset-value'
;
$this
->
_highlighting
=
'dummy-highlighting-value'
;
$this
->
_grouping
=
'dummy-grouping-value'
;
$this
->
_components
=
array
(
Solarium_Query_Select
::
COMPONENT_FACETSET
=>
$this
->
_facetSet
,
Solarium_Query_Select
::
COMPONENT_MORELIKETHIS
=>
$this
->
_moreLikeThis
,
Solarium_Query_Select
::
COMPONENT_HIGHLIGHTING
=>
$this
->
_highlighting
Solarium_Query_Select
::
COMPONENT_HIGHLIGHTING
=>
$this
->
_highlighting
,
Solarium_Query_Select
::
COMPONENT_GROUPING
=>
$this
->
_grouping
);
$this
->
_result
=
new
Solarium_Result_SelectDummy
(
1
,
12
,
$this
->
_numFound
,
$this
->
_docs
,
$this
->
_components
);
...
...
@@ -118,6 +120,14 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
);
}
public
function
testGetGrouping
()
{
$this
->
assertEquals
(
$this
->
_components
[
Solarium_Query_Select
::
COMPONENT_GROUPING
],
$this
->
_result
->
getGrouping
()
);
}
public
function
testIterator
()
{
$docs
=
array
();
...
...
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