From a1789ddde42033f1b05cc4929491214ee6e79383 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 17 Dec 2015 09:15:42 +0100 Subject: Update to MediaWiki 1.26.0 --- .../elastica/test/lib/Elastica/Test/ResultTest.php | 131 +++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/ResultTest.php (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/ResultTest.php') diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/ResultTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/ResultTest.php new file mode 100644 index 00000000..a905fcc5 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/ResultTest.php @@ -0,0 +1,131 @@ +_createIndex(); + $type = $index->getType($typeName); + + // Adds 1 document to the index + $docId = 3; + $doc1 = new Document($docId, array('username' => 'hans')); + $type->addDocument($doc1); + + // Refreshes index + $index->refresh(); + + $resultSet = $type->search('hans'); + + $this->assertEquals(1, $resultSet->count()); + + $result = $resultSet->current(); + + $this->assertInstanceOf('Elastica\Result', $result); + $this->assertEquals($index->getName(), $result->getIndex()); + $this->assertEquals($typeName, $result->getType()); + $this->assertEquals($docId, $result->getId()); + $this->assertGreaterThan(0, $result->getScore()); + $this->assertInternalType('array', $result->getData()); + $this->assertTrue(isset($result->username)); + $this->assertEquals('hans', $result->username); + } + + /** + * @group functional + */ + public function testGetIdNoSource() + { + // Creates a new index 'xodoa' and a type 'user' inside this index + $indexName = 'xodoa'; + $typeName = 'user'; + + $client = $this->_getClient(); + $index = $client->getIndex($indexName); + $index->create(array(), true); + $type = $index->getType($typeName); + + $mapping = new Mapping($type); + $mapping->disableSource(); + $mapping->send(); + + // Adds 1 document to the index + $docId = 3; + $doc1 = new Document($docId, array('username' => 'hans')); + $type->addDocument($doc1); + + // Refreshes index + $index->refresh(); + + $resultSet = $type->search('hans'); + + $this->assertEquals(1, $resultSet->count()); + + $result = $resultSet->current(); + + $this->assertEquals(array(), $result->getSource()); + $this->assertInstanceOf('Elastica\Result', $result); + $this->assertEquals($indexName, $result->getIndex()); + $this->assertEquals($typeName, $result->getType()); + $this->assertEquals($docId, $result->getId()); + $this->assertGreaterThan(0, $result->getScore()); + $this->assertInternalType('array', $result->getData()); + } + + /** + * @group functional + */ + public function testGetTotalTimeReturnsExpectedResults() + { + $typeName = 'user'; + $index = $this->_createIndex(); + $type = $index->getType($typeName); + + // Adds 1 document to the index + $docId = 3; + $doc1 = new Document($docId, array('username' => 'hans')); + $type->addDocument($doc1); + + // Refreshes index + $index->refresh(); + + $resultSet = $type->search('hans'); + + $this->assertNotNull($resultSet->getTotalTime(), 'Get Total Time should never be a null value'); + $this->assertEquals( + 'integer', + getType($resultSet->getTotalTime()), + 'Total Time should be an integer' + ); + } + + /** + * @group unit + */ + public function testHasFields() + { + $data = array('value set'); + + $result = new Result(array()); + $this->assertFalse($result->hasFields()); + + $result = new Result(array('_source' => $data)); + $this->assertFalse($result->hasFields()); + + $result = new Result(array('fields' => $data)); + $this->assertTrue($result->hasFields()); + $this->assertEquals($data, $result->getFields()); + } +} -- cgit v1.2.3-54-g00ecf