From 1a365e77dfb8825136626202b1df462731b42060 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 16 Aug 2015 08:22:05 +0200 Subject: Update to MediaWiki 1.25.2 --- .../Test/Transport/AbstractTransportTest.php | 77 +++++++ .../lib/Elastica/Test/Transport/GuzzleTest.php | 163 +++++++++++++++ .../test/lib/Elastica/Test/Transport/HttpTest.php | 227 +++++++++++++++++++++ .../lib/Elastica/Test/Transport/MemcacheTest.php | 51 +++++ .../test/lib/Elastica/Test/Transport/NullTest.php | 59 ++++++ .../lib/Elastica/Test/Transport/ThriftTest.php | 132 ++++++++++++ 6 files changed, 709 insertions(+) create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/AbstractTransportTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/GuzzleTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/HttpTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/MemcacheTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/NullTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/ThriftTest.php (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Transport') diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/AbstractTransportTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/AbstractTransportTest.php new file mode 100644 index 00000000..4f1c7114 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/AbstractTransportTest.php @@ -0,0 +1,77 @@ + 'Http')), + array(array('type' => new Http())), + array(new Http()), + ); + } + + /** + * @dataProvider getValidDefinitions + */ + public function testCanCreateTransportInstances($transport) + { + $connection = new Connection(); + $params = array(); + $transport = AbstractTransport::create($transport, $connection, $params); + $this->assertInstanceOf('Elastica\Transport\AbstractTransport', $transport); + $this->assertSame($connection, $transport->getConnection()); + } + + public function getInvalidDefinitions() + { + return array( + array(array('transport' => 'Http')), + array('InvalidTransport'), + ); + } + + /** + * @dataProvider getInvalidDefinitions + * @expectedException Elastica\Exception\InvalidException + * @expectedExceptionMessage Invalid transport + */ + public function testThrowsExecptionOnInvalidTransportDefinition($transport) + { + AbstractTransport::create($transport, new Connection()); + } + + public function testCanInjectParamsWhenUsingArray() + { + $connection = new Connection(); + $params = array( + 'param1' => 'some value', + 'param3' => 'value3', + ); + + $transport = AbstractTransport::create(array( + 'type' => 'Http', + 'param1' => 'value1', + 'param2' => 'value2', + ), $connection, $params); + + $this->assertSame('value1', $transport->getParam('param1')); + $this->assertSame('value2', $transport->getParam('param2')); + $this->assertSame('value3', $transport->getParam('param3')); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/GuzzleTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/GuzzleTest.php new file mode 100644 index 00000000..b2e385bb --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/GuzzleTest.php @@ -0,0 +1,163 @@ +markTestSkipped('The DEBUG constant must be set to true for this test to run'); + } + + if (!defined('DEBUG')) { + define('DEBUG', true); + } + } + + /** + * Return transport configuration and the expected HTTP method + * + * @return array[] + */ + public function getConfig() + { + return array( + array( + array('transport' => 'Guzzle'), + 'GET' + ), + array( + array('transport' => array('type' => 'Guzzle', 'postWithRequestBody' => false)), + 'GET' + ), + array( + array('transport' => array('type' => 'Guzzle', 'postWithRequestBody' => true)), + 'POST' + ), + ); + } + + /** + * @dataProvider getConfig + */ + public function testDynamicHttpMethodBasedOnConfigParameter(array $config, $httpMethod) + { + $client = new Client($config); + + $index = $client->getIndex('dynamic_http_method_test'); + $index->create(array(), true); + $type = $index->getType('test'); + $type->addDocument(new Document(1, array('test' => 'test'))); + $index->refresh(); + $resultSet = $index->search('test'); + $info = $resultSet->getResponse()->getTransferInfo(); + $this->assertStringStartsWith($httpMethod, $info['request_header']); + } + + /** + * @dataProvider getConfig + */ + public function testDynamicHttpMethodOnlyAffectsRequestsWithBody(array $config, $httpMethod) + { + $client = new Client($config); + + $status = $client->getStatus(); + $info = $status->getResponse()->getTransferInfo(); + $this->assertStringStartsWith('GET', $info['request_header']); + } + + public function testWithEnvironmentalProxy() + { + putenv('http_proxy=http://127.0.0.1:12345/'); + + $client = new \Elastica\Client(array('transport' => 'Guzzle')); + $transferInfo = $client->request('/_nodes')->getTransferInfo(); + $this->assertEquals(200, $transferInfo['http_code']); + + $client->getConnection()->setProxy(null); // will not change anything + $transferInfo = $client->request('/_nodes')->getTransferInfo(); + $this->assertEquals(200, $transferInfo['http_code']); + + putenv('http_proxy='); + } + + public function testWithEnabledEnvironmentalProxy() + { + putenv('http_proxy=http://127.0.0.1:12346/'); + + $client = new \Elastica\Client(array('transport' => 'Guzzle')); + + $transferInfo = $client->request('/_nodes')->getTransferInfo(); + $this->assertEquals(403, $transferInfo['http_code']); + + $client = new \Elastica\Client(); + $client->getConnection()->setProxy(''); + $transferInfo = $client->request('/_nodes')->getTransferInfo(); + $this->assertEquals(200, $transferInfo['http_code']); + + putenv('http_proxy='); + } + + public function testWithProxy() + { + $client = new \Elastica\Client(array('transport' => 'Guzzle')); + $client->getConnection()->setProxy('http://127.0.0.1:12345'); + + $transferInfo = $client->request('/_nodes')->getTransferInfo(); + $this->assertEquals(200, $transferInfo['http_code']); + } + + public function testWithoutProxy() + { + $client = new \Elastica\Client(array('transport' => 'Guzzle')); + $client->getConnection()->setProxy(''); + + $transferInfo = $client->request('/_nodes')->getTransferInfo(); + $this->assertEquals(200, $transferInfo['http_code']); + } + + public function testBodyReuse() + { + $client = new Client(array('transport' => 'Guzzle')); + + $index = $client->getIndex('elastica_body_reuse_test'); + + $index->create(array(), true); + + $type = $index->getType('test'); + $type->addDocument(new Document(1, array('test' => 'test'))); + + $index->refresh(); + + $resultSet = $index->search(array( + 'query' => array( + 'query_string' => array( + 'query' => 'pew pew pew', + ), + ), + )); + + $this->assertEquals(0, $resultSet->getTotalHits()); + + $response = $index->request('/_search', 'POST'); + $resultSet = new ResultSet($response, Query::create(array())); + + $this->assertEquals(1, $resultSet->getTotalHits()); + } + +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/HttpTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/HttpTest.php new file mode 100644 index 00000000..88c93bea --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/HttpTest.php @@ -0,0 +1,227 @@ +markTestSkipped('The DEBUG constant must be set to true for this test to run'); + } + + if (!defined('DEBUG')) { + define('DEBUG', true); + } + } + + /** + * Return transport configuration and the expected HTTP method + * + * @return array[] + */ + public function getConfig() + { + return array( + array( + array('transport' => 'Http'), + 'GET' + ), + array( + array('transport' => array('type' => 'Http', 'postWithRequestBody' => false)), + 'GET' + ), + array( + array('transport' => array('type' => 'Http', 'postWithRequestBody' => true)), + 'POST' + ), + ); + } + + /** + * @dataProvider getConfig + */ + public function testDynamicHttpMethodBasedOnConfigParameter(array $config, $httpMethod) + { + $client = new Client($config); + + $index = $client->getIndex('dynamic_http_method_test'); + + $index->create(array(), true); + + $type = $index->getType('test'); + $type->addDocument(new Document(1, array('test' => 'test'))); + + $index->refresh(); + + $resultSet = $index->search('test'); + + $info = $resultSet->getResponse()->getTransferInfo(); + $this->assertStringStartsWith($httpMethod, $info['request_header']); + } + + /** + * @dataProvider getConfig + */ + public function testDynamicHttpMethodOnlyAffectsRequestsWithBody(array $config, $httpMethod) + { + $client = new Client($config); + + $status = $client->getStatus(); + $info = $status->getResponse()->getTransferInfo(); + $this->assertStringStartsWith('GET', $info['request_header']); + } + + public function testCurlNobodyOptionIsResetAfterHeadRequest() + { + $client = new \Elastica\Client(); + $index = $client->getIndex('curl_test'); + $type = $index->getType('item'); + + // Force HEAD request to set CURLOPT_NOBODY = true + $index->exists(); + + $id = 1; + $data = array('id' => $id, 'name' => 'Item 1'); + $doc = new \Elastica\Document($id, $data); + + $type->addDocument($doc); + + $index->refresh(); + + $doc = $type->getDocument($id); + + // Document should be retrieved correctly + $this->assertSame($data, $doc->getData()); + $this->assertEquals($id, $doc->getId()); + } + + public function testUnicodeData() + { + $client = new \Elastica\Client(); + $index = $client->getIndex('curl_test'); + $type = $index->getType('item'); + + // Force HEAD request to set CURLOPT_NOBODY = true + $index->exists(); + + $id = 22; + $data = array('id' => $id, 'name' => ' + Сегодня, я вижу, особенно грустен твой взгляд, / + И руки особенно тонки, колени обняв. / + Послушай: далеко, далеко, на озере Чад / + Изысканный бродит жираф.'); + + $doc = new \Elastica\Document($id, $data); + + $type->addDocument($doc); + + $index->refresh(); + + $doc = $type->getDocument($id); + + // Document should be retrieved correctly + $this->assertSame($data, $doc->getData()); + $this->assertEquals($id, $doc->getId()); + } + + public function testWithEnvironmentalProxy() + { + putenv('http_proxy=http://127.0.0.1:12345/'); + + $client = new \Elastica\Client(); + $transferInfo = $client->request('/_nodes')->getTransferInfo(); + $this->assertEquals(200, $transferInfo['http_code']); + + $client->getConnection()->setProxy(null); // will not change anything + $transferInfo = $client->request('/_nodes')->getTransferInfo(); + $this->assertEquals(200, $transferInfo['http_code']); + + putenv('http_proxy='); + } + + public function testWithEnabledEnvironmentalProxy() + { + putenv('http_proxy=http://127.0.0.1:12346/'); + + $client = new \Elastica\Client(); + + $transferInfo = $client->request('/_nodes')->getTransferInfo(); + $this->assertEquals(403, $transferInfo['http_code']); + + $client = new \Elastica\Client(); + $client->getConnection()->setProxy(''); + $transferInfo = $client->request('/_nodes')->getTransferInfo(); + $this->assertEquals(200, $transferInfo['http_code']); + + putenv('http_proxy='); + } + + public function testWithProxy() + { + $client = new \Elastica\Client(); + $client->getConnection()->setProxy('http://127.0.0.1:12345'); + + $transferInfo = $client->request('/_nodes')->getTransferInfo(); + $this->assertEquals(200, $transferInfo['http_code']); + } + + public function testWithoutProxy() + { + $client = new \Elastica\Client(); + $client->getConnection()->setProxy(''); + + $transferInfo = $client->request('/_nodes')->getTransferInfo(); + $this->assertEquals(200, $transferInfo['http_code']); + } + + public function testBodyReuse() + { + $client = new Client(); + + $index = $client->getIndex('elastica_body_reuse_test'); + + $index->create(array(), true); + + $type = $index->getType('test'); + $type->addDocument(new Document(1, array('test' => 'test'))); + + $index->refresh(); + + $resultSet = $index->search(array( + 'query' => array( + 'query_string' => array( + 'query' => 'pew pew pew', + ), + ), + )); + + $this->assertEquals(0, $resultSet->getTotalHits()); + + $response = $index->request('/_search', 'POST'); + $resultSet = new ResultSet($response, Query::create(array())); + + $this->assertEquals(1, $resultSet->getTotalHits()); + } + + public function testPostWith0Body() + { + $client = new Client(); + + $index = $client->getIndex('elastica_0_body'); + $index->create(array(), true); + $index->refresh(); + + $tokens = $index->analyze('0'); + + $this->assertNotEmpty($tokens); + } + +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/MemcacheTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/MemcacheTest.php new file mode 100644 index 00000000..17d46d88 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/MemcacheTest.php @@ -0,0 +1,51 @@ +markTestSkipped('pecl/memcache must be installed to run this test case'); + } + } + + public function testExample() + { + // Creates a new index 'xodoa' and a type 'user' inside this index + $host = 'localhost'; + $port = 11211; + $client = new Client(array('host' => $host, 'port' => $port, 'transport' => 'Memcache')); + + $index = $client->getIndex('elastica_test1'); + $index->create(array(), true); + + $type = $index->getType('user'); + + // Adds 1 document to the index + $doc1 = new Document(1, + array('username' => 'hans', 'test' => array('2', '3', '5')) + ); + $type->addDocument($doc1); + + // Adds a list of documents with _bulk upload to the index + $docs = array(); + $docs[] = new Document(2, + array('username' => 'john', 'test' => array('1', '3', '6')) + ); + $docs[] = new Document(3, + array('username' => 'rolf', 'test' => array('2', '3', '7')) + ); + $type->addDocuments($docs); + + // Refresh index + $index->refresh(); + $this->markTestIncomplete('Memcache implementation is not finished yet'); + $resultSet = $type->search('rolf'); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/NullTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/NullTest.php new file mode 100644 index 00000000..c07f5da1 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/NullTest.php @@ -0,0 +1,59 @@ + + */ +class NullTest extends BaseTest +{ + + public function testEmptyResult() + { + // Creates a client with any destination, and verify it returns a response object when executed + $client = $this->_getClient(); + $connection = new Connection(array('transport' => 'Null')); + $client->setConnections(array($connection)); + + $index = $client->getIndex('elasticaNullTransportTest1'); + + $resultSet = $index->search(new Query()); + $this->assertNotNull($resultSet); + + $response = $resultSet->getResponse(); + $this->assertNotNull($response); + + // Validate most of the expected fields in the response data. Consumers of the response + // object have a reasonable expectation of finding "hits", "took", etc + $responseData = $response->getData(); + $this->assertContains("took", $responseData); + $this->assertEquals(0, $responseData["took"]); + $this->assertContains("_shards", $responseData); + $this->assertContains("hits", $responseData); + $this->assertContains("total", $responseData["hits"]); + $this->assertEquals(0, $responseData["hits"]["total"]); + $this->assertContains("params", $responseData); + + $took = $response->getEngineTime(); + $this->assertEquals(0, $took); + + $errorString = $response->getError(); + $this->assertEmpty($errorString); + + $shards = $response->getShardsStatistics(); + $this->assertContains("total", $shards); + $this->assertEquals(0, $shards["total"]); + $this->assertContains("successful", $shards); + $this->assertEquals(0, $shards["successful"]); + $this->assertContains("failed", $shards); + $this->assertEquals(0, $shards["failed"]); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/ThriftTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/ThriftTest.php new file mode 100644 index 00000000..f1698ff6 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/ThriftTest.php @@ -0,0 +1,132 @@ + $host, 'port' => $port, 'transport' => 'Thrift')); + + $this->assertEquals($host, $client->getConnection()->getHost()); + $this->assertEquals($port, $client->getConnection()->getPort()); + } + + /** + * @dataProvider configProvider + */ + public function testSearchRequest($config) + { + $this->_checkPlugin(); + + // Creates a new index 'xodoa' and a type 'user' inside this index + $client = new Client($config); + + $index = $client->getIndex('elastica_test1'); + $index->create(array(), true); + + $type = $index->getType('user'); + + // Adds 1 document to the index + $doc1 = new Document(1, + array('username' => 'hans', 'test' => array('2', '3', '5')) + ); + $doc1->setVersion(0); + $type->addDocument($doc1); + + // Adds a list of documents with _bulk upload to the index + $docs = array(); + $docs[] = new Document(2, + array('username' => 'john', 'test' => array('1', '3', '6')) + ); + $docs[] = new Document(3, + array('username' => 'rolf', 'test' => array('2', '3', '7')) + ); + $type->addDocuments($docs); + + // Refresh index + $index->refresh(); + $resultSet = $type->search('rolf'); + + $this->assertEquals(1, $resultSet->getTotalHits()); + } + + /** + * @expectedException \Elastica\Exception\ConnectionException + */ + public function testInvalidHostRequest() + { + $this->_checkPlugin(); + + $client = new Client(array('host' => 'unknown', 'port' => 9555, 'transport' => 'Thrift')); + $client->getStatus(); + } + + /** + * @expectedException \Elastica\Exception\ResponseException + */ + public function testInvalidElasticRequest() + { + $this->_checkPlugin(); + + $connection = new Connection(); + $connection->setHost('localhost'); + $connection->setPort(9500); + $connection->setTransport('Thrift'); + + $client = new Client(); + $client->addConnection($connection); + + $index = new Index($client, 'missing_index'); + $index->getStatus(); + } + + public function configProvider() + { + return array( + array( + array( + 'host' => 'localhost', + 'port' => 9500, + 'transport' => 'Thrift' + ) + ), + array( + array( + 'host' => 'localhost', + 'port' => 9500, + 'transport' => 'Thrift', + 'config' => array( + 'framedTransport' => false, + 'sendTimeout' => 10000, + 'recvTimeout' => 20000, + ) + ) + ) + ); + } + + protected function _checkPlugin() + { + $nodes = $this->_getClient()->getCluster()->getNodes(); + if (!$nodes[0]->getInfo()->hasPlugin('transport-thrift')) { + $this->markTestSkipped("transport-thrift plugin not installed."); + } + } +} -- cgit v1.2.3-54-g00ecf