forked from solariumphp/solarium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added essential functions for API calls (solariumphp#650)
* added essential functions for API calls * switched to V1 as default
- Loading branch information
Markus Kalkbrenner
authored
Feb 5, 2019
1 parent
1d46fc1
commit bc0b705
Showing
4 changed files
with
238 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Solarium\Tests\QueryType\Server\Api; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Solarium\Core\Client\Client; | ||
use Solarium\Core\Client\Request; | ||
use Solarium\QueryType\Server\Api\Query; | ||
|
||
class QueryTest extends TestCase | ||
{ | ||
/** | ||
* @var Query | ||
*/ | ||
protected $query; | ||
|
||
public function setUp() | ||
{ | ||
$this->query = new Query(); | ||
} | ||
|
||
public function testGetType() | ||
{ | ||
$this->assertSame(Client::QUERY_API, $this->query->getType()); | ||
} | ||
|
||
public function testSetGetVersion() | ||
{ | ||
$this->assertSame(Request::API_V1, $this->query->getVersion()); | ||
|
||
$this->query->setVersion(Request::API_V2); | ||
$this->assertSame(Request::API_V2, $this->query->getVersion()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
|
||
namespace Solarium\Tests\QueryType\Server\Api; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Solarium\Core\Client\Request; | ||
use Solarium\QueryType\Server\Api\Query; | ||
use Solarium\QueryType\Server\Api\RequestBuilder; | ||
|
||
class RequestBuilderTest extends TestCase | ||
{ | ||
/** | ||
* @var Query | ||
*/ | ||
protected $query; | ||
|
||
/** | ||
* @var RequestBuilder | ||
*/ | ||
protected $builder; | ||
|
||
public function setUp() | ||
{ | ||
$this->query = new Query(); | ||
$this->builder = new RequestBuilder(); | ||
} | ||
|
||
public function testBuildParams() | ||
{ | ||
$request = $this->builder->build($this->query); | ||
|
||
$this->assertEquals( | ||
[ | ||
'wt' => 'json', | ||
'json.nl' => 'flat', | ||
], | ||
$request->getParams() | ||
); | ||
$this->assertSame(Request::METHOD_GET, $request->getMethod()); | ||
$this->assertTrue($request->getIsServerRequest()); | ||
$this->assertSame('?wt=json&json.nl=flat', $request->getUri()); | ||
|
||
$this->query->setHandler('dummy'); | ||
$request = $this->builder->build($this->query); | ||
|
||
$this->assertEquals( | ||
[ | ||
'wt' => 'json', | ||
'json.nl' => 'flat', | ||
], | ||
$request->getParams() | ||
); | ||
$this->assertSame(Request::METHOD_GET, $request->getMethod()); | ||
$this->assertTrue($request->getIsServerRequest()); | ||
$this->assertSame('dummy?wt=json&json.nl=flat', $request->getUri()); | ||
|
||
$this->query->setAccept('foo/bar'); | ||
$request = $this->builder->build($this->query); | ||
|
||
$this->assertEquals( | ||
[ | ||
'wt' => 'json', | ||
'json.nl' => 'flat', | ||
], | ||
$request->getParams() | ||
); | ||
$this->assertSame(Request::METHOD_GET, $request->getMethod()); | ||
$this->assertTrue($request->getIsServerRequest()); | ||
$this->assertSame('dummy?wt=json&json.nl=flat', $request->getUri()); | ||
$this->arrayHasKey('Accept: foo/bar', array_flip($request->getHeaders())); | ||
|
||
$this->query->setContentType('foo;bar'); | ||
$request = $this->builder->build($this->query); | ||
|
||
$this->assertEquals( | ||
[ | ||
'wt' => 'json', | ||
'json.nl' => 'flat', | ||
], | ||
$request->getParams() | ||
); | ||
$this->assertSame(Request::METHOD_GET, $request->getMethod()); | ||
$this->assertTrue($request->getIsServerRequest()); | ||
$this->assertSame('dummy?wt=json&json.nl=flat', $request->getUri()); | ||
$this->arrayHasKey('Accept: foo/bar', array_flip($request->getHeaders())); | ||
$this->arrayHasKey('Content-Type: foo;bar', array_flip($request->getHeaders())); | ||
|
||
$this->query->setMethod(Request::METHOD_HEAD); | ||
$request = $this->builder->build($this->query); | ||
|
||
$this->assertEquals( | ||
[ | ||
'wt' => 'json', | ||
'json.nl' => 'flat', | ||
], | ||
$request->getParams() | ||
); | ||
$this->assertSame(Request::METHOD_HEAD, $request->getMethod()); | ||
$this->assertTrue($request->getIsServerRequest()); | ||
$this->assertSame('dummy?wt=json&json.nl=flat', $request->getUri()); | ||
$this->arrayHasKey('Accept: foo/bar', array_flip($request->getHeaders())); | ||
$this->arrayHasKey('Content-Type: foo;bar', array_flip($request->getHeaders())); | ||
|
||
$this->query->setMethod(Request::METHOD_POST); | ||
$this->query->setRawData('some data'); | ||
$request = $this->builder->build($this->query); | ||
|
||
$this->assertEquals( | ||
[ | ||
'wt' => 'json', | ||
'json.nl' => 'flat', | ||
], | ||
$request->getParams() | ||
); | ||
$this->assertSame(Request::METHOD_POST, $request->getMethod()); | ||
$this->assertTrue($request->getIsServerRequest()); | ||
$this->assertSame('dummy?wt=json&json.nl=flat', $request->getUri()); | ||
$this->arrayHasKey('Accept: foo/bar', array_flip($request->getHeaders())); | ||
$this->arrayHasKey('Content-Type: foo;bar', array_flip($request->getHeaders())); | ||
$this->assertSame('some data', $request->getRawData()); | ||
} | ||
} |