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
e67ed1f0
Commit
e67ed1f0
authored
Jul 22, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added unittests for grouping component and added some small improvements to component
parent
138699a3
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
188 additions
and
0 deletions
+188
-0
library/Solarium/Result/Select/Grouping.php
library/Solarium/Result/Select/Grouping.php
+15
-0
library/Solarium/Result/Select/Grouping/ValueGroup.php
library/Solarium/Result/Select/Grouping/ValueGroup.php
+10
-0
tests/Solarium/Client/ResponseParser/Select/Component/GroupingTest.php
...m/Client/ResponseParser/Select/Component/GroupingTest.php
+139
-0
tests/Solarium/Result/Select/Grouping/ValueGroupTest.php
tests/Solarium/Result/Select/Grouping/ValueGroupTest.php
+8
-0
tests/Solarium/Result/Select/GroupingTest.php
tests/Solarium/Result/Select/GroupingTest.php
+16
-0
No files found.
library/Solarium/Result/Select/Grouping.php
View file @
e67ed1f0
...
@@ -73,6 +73,21 @@ class Solarium_Result_Select_Grouping implements IteratorAggregate, Countable
...
@@ -73,6 +73,21 @@ class Solarium_Result_Select_Grouping implements IteratorAggregate, Countable
return
$this
->
_groups
;
return
$this
->
_groups
;
}
}
/**
* Get a group
*
* @param string $key
* @return Solarium_Result_Select_Grouping_FieldGroup|Solarium_Result_Select_Grouping_QueryGroup
*/
public
function
getGroup
(
$key
)
{
if
(
isset
(
$this
->
_groups
[
$key
]))
{
return
$this
->
_groups
[
$key
];
}
else
{
return
null
;
}
}
/**
/**
* IteratorAggregate implementation
* IteratorAggregate implementation
*
*
...
...
library/Solarium/Result/Select/Grouping/ValueGroup.php
View file @
e67ed1f0
...
@@ -120,6 +120,16 @@ class Solarium_Result_Select_Grouping_ValueGroup implements IteratorAggregate, C
...
@@ -120,6 +120,16 @@ class Solarium_Result_Select_Grouping_ValueGroup implements IteratorAggregate, C
return
$this
->
_start
;
return
$this
->
_start
;
}
}
/**
* Get all documents
*
* @return array
*/
public
function
getDocuments
()
{
return
$this
->
_documents
;
}
/**
/**
* IteratorAggregate implementation
* IteratorAggregate implementation
*
*
...
...
tests/Solarium/Client/ResponseParser/Select/Component/GroupingTest.php
0 → 100644
View file @
e67ed1f0
<?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_ResponseParser_Select_Component_GroupingTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Client_ResponseParser_Select_Component_Grouping
*/
protected
$_parser
;
/**
* @var Solarium_Query_Select
*/
protected
$_query
;
/**
* @var Solarium_Query_Select_Component_Grouping
*/
protected
$_grouping
;
/**
* @var Solarium_Result_Select_Grouping
*/
protected
$_result
;
public
function
setUp
()
{
$this
->
_parser
=
new
Solarium_Client_ResponseParser_Select_Component_Grouping
;
$this
->
_query
=
new
Solarium_Query_Select
();
$this
->
_grouping
=
$this
->
_query
->
getGrouping
();
$this
->
_grouping
->
addField
(
'fieldA'
);
$this
->
_grouping
->
addQuery
(
'cat:1'
);
$data
=
array
(
'grouped'
=>
array
(
'fieldA'
=>
array
(
'matches'
=>
25
,
'ngroups'
=>
12
,
'groups'
=>
array
(
array
(
'groupValue'
=>
'test value'
,
'doclist'
=>
array
(
'numFound'
=>
13
,
'docs'
=>
array
(
array
(
'id'
=>
1
,
'name'
=>
'test'
)
)
)
)
)
),
'cat:1'
=>
array
(
'matches'
=>
40
,
'doclist'
=>
array
(
'numFound'
=>
22
,
'docs'
=>
array
(
array
(
'id'
=>
2
,
'name'
=>
'dummy2'
),
array
(
'id'
=>
5
,
'name'
=>
'dummy5'
)
)
)
)
)
);
$this
->
_result
=
$this
->
_parser
->
parse
(
$this
->
_query
,
$this
->
_grouping
,
$data
);
}
public
function
testGroupParsing
()
{
$this
->
assertEquals
(
2
,
count
(
$this
->
_result
->
getGroups
()));
$fieldGroup
=
$this
->
_result
->
getGroup
(
'fieldA'
);
$queryGroup
=
$this
->
_result
->
getGroup
(
'cat:1'
);
$this
->
assertEquals
(
'Solarium_Result_Select_Grouping_FieldGroup'
,
get_class
(
$fieldGroup
));
$this
->
assertEquals
(
'Solarium_Result_Select_Grouping_QueryGroup'
,
get_class
(
$queryGroup
));
}
public
function
testFieldGroupParsing
()
{
$fieldGroup
=
$this
->
_result
->
getGroup
(
'fieldA'
);
$valueGroups
=
$fieldGroup
->
getValueGroups
();
$this
->
assertEquals
(
25
,
$fieldGroup
->
getMatches
());
$this
->
assertEquals
(
12
,
$fieldGroup
->
getNumberOfGroups
());
$this
->
assertEquals
(
1
,
count
(
$valueGroups
));
$valueGroup
=
$valueGroups
[
0
];
$this
->
assertEquals
(
13
,
$valueGroup
->
getNumFound
());
$docs
=
$valueGroup
->
getDocuments
();
$this
->
assertEquals
(
'test'
,
$docs
[
0
]
->
name
);
}
public
function
testQueryGroupParsing
()
{
$queryGroup
=
$this
->
_result
->
getGroup
(
'cat:1'
);
$this
->
assertEquals
(
40
,
$queryGroup
->
getMatches
());
$this
->
assertEquals
(
22
,
$queryGroup
->
getNumFound
());
$docs
=
$queryGroup
->
getDocuments
();
$this
->
assertEquals
(
'dummy5'
,
$docs
[
1
]
->
name
);
}
public
function
testParseNoData
()
{
$result
=
$this
->
_parser
->
parse
(
$this
->
_query
,
$this
->
_grouping
,
array
());
$this
->
assertEquals
(
array
(),
$result
->
getGroups
());
}
}
tests/Solarium/Result/Select/Grouping/ValueGroupTest.php
View file @
e67ed1f0
...
@@ -77,6 +77,14 @@ class Solarium_Result_Select_Grouping_ValueGroupTest extends PHPUnit_Framework_T
...
@@ -77,6 +77,14 @@ class Solarium_Result_Select_Grouping_ValueGroupTest extends PHPUnit_Framework_T
);
);
}
}
public
function
testGetDocuments
()
{
$this
->
assertEquals
(
$this
->
_items
,
$this
->
_group
->
getDocuments
()
);
}
public
function
testIterator
()
public
function
testIterator
()
{
{
$items
=
array
();
$items
=
array
();
...
...
tests/Solarium/Result/Select/GroupingTest.php
View file @
e67ed1f0
...
@@ -57,6 +57,22 @@ class Solarium_Result_Select_GroupingTest extends PHPUnit_Framework_TestCase
...
@@ -57,6 +57,22 @@ class Solarium_Result_Select_GroupingTest extends PHPUnit_Framework_TestCase
);
);
}
}
public
function
testGetGroup
()
{
$this
->
assertEquals
(
$this
->
_items
[
'key1'
],
$this
->
_grouping
->
getGroup
(
'key1'
)
);
}
public
function
testGetGroupInvalid
()
{
$this
->
assertEquals
(
null
,
$this
->
_grouping
->
getGroup
(
'invalidkey'
)
);
}
public
function
testIterator
()
public
function
testIterator
()
{
{
$items
=
array
();
$items
=
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