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
892eb74c
Commit
892eb74c
authored
Jul 27, 2012
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented basic upload support in all client adapters and improved unittests
parent
4dcfb999
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
97 additions
and
17 deletions
+97
-17
examples/2.7-extract-query.php
examples/2.7-extract-query.php
+1
-2
library/Solarium/Core/Client/Adapter/Curl.php
library/Solarium/Core/Client/Adapter/Curl.php
+5
-1
library/Solarium/Core/Client/Adapter/Http.php
library/Solarium/Core/Client/Adapter/Http.php
+15
-5
library/Solarium/Core/Client/Adapter/PeclHttp.php
library/Solarium/Core/Client/Adapter/PeclHttp.php
+11
-3
library/Solarium/Core/Client/Adapter/ZendHttp.php
library/Solarium/Core/Client/Adapter/ZendHttp.php
+6
-6
tests/Solarium/Tests/Core/Client/ClientTest.php
tests/Solarium/Tests/Core/Client/ClientTest.php
+25
-0
tests/Solarium/Tests/Core/Client/RequestTest.php
tests/Solarium/Tests/Core/Client/RequestTest.php
+21
-0
tests/Solarium/Tests/QueryType/Update/Query/DocumentTest.php
tests/Solarium/Tests/QueryType/Update/Query/DocumentTest.php
+13
-0
No files found.
examples/2.7-extract-query.php
View file @
892eb74c
...
...
@@ -5,7 +5,6 @@ htmlHeader();
// create a client instance
$client
=
new
Solarium\Client
(
$config
);
$client
->
setAdapter
(
'Solarium\Core\Client\Adapter\ZendHttp'
);
// get an extract query instance and add settings
$query
=
$client
->
createExtract
();
...
...
@@ -17,7 +16,7 @@ $query->setOmitHeader(false);
// add document
$doc
=
$query
->
createDocument
();
$doc
->
id
=
time
()
;
$doc
->
id
=
'extract-test'
;
$doc
->
some
=
'more fields'
;
$query
->
setDocument
(
$doc
);
...
...
library/Solarium/Core/Client/Adapter/Curl.php
View file @
892eb74c
...
...
@@ -168,7 +168,11 @@ class Curl extends Configurable implements AdapterInterface
if
(
$method
==
Request
::
METHOD_POST
)
{
curl_setopt
(
$handler
,
CURLOPT_POST
,
true
);
if
(
$request
->
getFileUpload
())
{
curl_setopt
(
$handler
,
CURLOPT_POSTFIELDS
,
array
(
'content'
=>
'@'
.
$request
->
getFileUpload
()));
}
else
{
curl_setopt
(
$handler
,
CURLOPT_POSTFIELDS
,
$request
->
getRawData
());
}
$httpResponse
=
curl_exec
(
$handler
);
}
elseif
(
$method
==
Request
::
METHOD_GET
)
{
curl_setopt
(
$handler
,
CURLOPT_HTTPGET
,
true
);
...
...
library/Solarium/Core/Client/Adapter/Http.php
View file @
892eb74c
...
...
@@ -105,6 +105,15 @@ class Http extends Configurable implements AdapterInterface
);
if
(
$method
==
Request
::
METHOD_POST
)
{
if
(
$request
->
getFileUpload
())
{
stream_context_set_option
(
$context
,
'http'
,
'content'
,
file_get_contents
(
$request
->
getFileUpload
())
);
$request
->
addHeader
(
'Content-Type: multipart/form-data'
);
}
else
{
$data
=
$request
->
getRawData
();
if
(
null
!==
$data
)
{
stream_context_set_option
(
...
...
@@ -117,6 +126,7 @@ class Http extends Configurable implements AdapterInterface
$request
->
addHeader
(
'Content-Type: text/xml; charset=UTF-8'
);
}
}
}
$authData
=
$request
->
getAuthentication
();
if
(
!
empty
(
$authData
[
'username'
])
&&
!
empty
(
$authData
[
'password'
]))
{
...
...
library/Solarium/Core/Client/Adapter/PeclHttp.php
View file @
892eb74c
...
...
@@ -161,10 +161,18 @@ class PeclHttp extends Configurable implements AdapterInterface
break
;
case
Request
::
METHOD_POST
:
$method
=
HTTP_METH_POST
;
if
(
$request
->
getFileUpload
())
{
$httpRequest
->
addPostFile
(
'content'
,
$request
->
getFileUpload
(),
'application/octet-stream; charset=binary'
);
}
else
{
$httpRequest
->
setBody
(
$request
->
getRawData
());
if
(
!
isset
(
$headers
[
'Content-Type'
]))
{
$headers
[
'Content-Type'
]
=
'text/xml; charset=utf-8'
;
}
}
break
;
case
Request
::
METHOD_HEAD
:
$method
=
HTTP_METH_HEAD
;
...
...
library/Solarium/Core/Client/Adapter/ZendHttp.php
View file @
892eb74c
...
...
@@ -260,12 +260,12 @@ class ZendHttp extends Configurable implements AdapterInterface
protected
function
prepareFileUpload
(
$client
,
$request
)
{
$filename
=
$request
->
getFileUpload
();
if
((
$content
=
@
file_get_contents
(
$filename
))
===
false
)
{
throw
new
RuntimeException
(
"Unable to read file '
{
$filename
}
' for upload"
);
}
$client
->
setFileUpload
(
'content'
,
'content'
,
$content
,
'application/octet-stream; charset=binary'
);
$client
->
setFileUpload
(
'content'
,
'content'
,
file_get_contents
(
$filename
),
'application/octet-stream; charset=binary'
);
// set query params as "multipart/form-data" fields
foreach
(
$request
->
getParams
()
as
$name
=>
$value
)
{
...
...
tests/Solarium/Tests/Core/Client/ClientTest.php
View file @
892eb74c
...
...
@@ -41,6 +41,7 @@ use Solarium\QueryType\Update\Query\Query as UpdateQuery;
use
Solarium\QueryType\Analysis\Query\Field
as
AnalysisQueryField
;
use
Solarium\QueryType\Terms\Query
as
TermsQuery
;
use
Solarium\QueryType\Suggester\Query
as
SuggesterQuery
;
use
Solarium\QueryType\Extract\Query
as
ExtractQuery
;
use
Solarium\Core\Client\Adapter\Http
as
ClientAdapterHttp
;
use
Solarium\Core\Plugin
;
...
...
@@ -895,6 +896,18 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$observer
->
suggester
(
$query
);
}
public
function
testExtract
()
{
$query
=
new
ExtractQuery
();
$observer
=
$this
->
getMock
(
'Solarium\Core\Client\Client'
,
array
(
'execute'
));
$observer
->
expects
(
$this
->
once
())
->
method
(
'execute'
)
->
with
(
$this
->
equalTo
(
$query
));
$observer
->
extract
(
$query
);
}
public
function
testCreateQuery
()
{
$options
=
array
(
'optionA'
=>
1
,
'optionB'
=>
2
);
...
...
@@ -1070,6 +1083,18 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$observer
->
createSuggester
(
$options
);
}
public
function
testCreateExtract
()
{
$options
=
array
(
'optionA'
=>
1
,
'optionB'
=>
2
);
$observer
=
$this
->
getMock
(
'Solarium\Core\Client\Client'
,
array
(
'createQuery'
));
$observer
->
expects
(
$this
->
once
())
->
method
(
'createQuery'
)
->
with
(
$this
->
equalTo
(
Client
::
QUERY_EXTRACT
),
$this
->
equalTo
(
$options
));
$observer
->
createExtract
(
$options
);
}
public
function
testTriggerEvent
()
{
$eventName
=
'Test'
;
...
...
tests/Solarium/Tests/Core/Client/RequestTest.php
View file @
892eb74c
...
...
@@ -63,6 +63,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
'username'
=>
'testuser'
,
'password'
=>
'testpass'
,
),
'file'
=>
__FILE__
,
);
$this
->
request
->
setOptions
(
$options
);
...
...
@@ -101,6 +102,11 @@ class RequestTest extends \PHPUnit_Framework_TestCase
),
$this
->
request
->
getAuthentication
()
);
$this
->
assertEquals
(
$options
[
'file'
],
$this
->
request
->
getFileUpload
()
);
}
public
function
testGetDefaultMethod
()
...
...
@@ -510,4 +516,19 @@ file upload:
);
}
public
function
testSetAndGetFileUpload
()
{
$this
->
request
->
setFileUpload
(
__FILE__
);
$this
->
assertEquals
(
__FILE__
,
$this
->
request
->
getFileUpload
()
);
}
public
function
testSetAndGetFileUploadWithInvalidFile
()
{
$this
->
setExpectedException
(
'Solarium\Exception\RuntimeException'
);
$this
->
request
->
setFileUpload
(
'invalid-filename.dummy'
);
}
}
tests/Solarium/Tests/QueryType/Update/Query/DocumentTest.php
View file @
892eb74c
...
...
@@ -201,6 +201,19 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
);
}
public
function
testSetAndGetFieldBoosts
()
{
$this
->
doc
->
setFieldBoost
(
'name'
,
2.5
);
$this
->
doc
->
setFieldBoost
(
'category'
,
1.5
);
$this
->
assertEquals
(
array
(
'name'
=>
2.5
,
'category'
=>
1.5
,
),
$this
->
doc
->
getFieldBoosts
()
);
}
public
function
testGetInvalidFieldBoost
()
{
$this
->
assertEquals
(
...
...
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