diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-20 09:00:55 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-20 09:00:55 +0100 |
commit | a2190ac74dd4d7080b12bab90e552d7aa81209ef (patch) | |
tree | 8b31f38de9882d18df54cf8d9e0de74167a094eb /vendor/ruflin/elastica/test/lib/Elastica/Test/UtilTest.php | |
parent | 15e69f7b20b6596b9148030acce5b59993b95a45 (diff) | |
parent | 257401d8b2cf661adf36c84b0e3fd1cf85e33c22 (diff) |
Merge branch 'mw-1.26'
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/UtilTest.php')
-rw-r--r-- | vendor/ruflin/elastica/test/lib/Elastica/Test/UtilTest.php | 78 |
1 files changed, 70 insertions, 8 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/UtilTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/UtilTest.php index 09d4b5b1..a5b0f42e 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/UtilTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/UtilTest.php @@ -1,15 +1,15 @@ <?php - namespace Elastica\Test; -use Elastica\Util; -use Elastica\Request; use Elastica\Connection; +use Elastica\Request; use Elastica\Test\Base as BaseTest; +use Elastica\Util; class UtilTest extends BaseTest { /** + * @group unit * @dataProvider getEscapeTermPairs */ public function testEscapeTerm($unescaped, $escaped) @@ -25,18 +25,45 @@ class UtilTest extends BaseTest array('oh yeah!', 'oh yeah\\!'), // Seperate test below because phpunit seems to have some problems //array('\\+-&&||!(){}[]^"~*?:', '\\\\\\+\\-\\&&\\||\\!\\(\\)\\{\\}\\[\\]\\^\\"\\~\\*\\?\\:'), - array('some signs, can stay.', 'some signs, can stay.') + array('some signs, can stay.', 'some signs, can stay.'), ); } + /** + * @group unit + * @dataProvider getReplaceBooleanWordsPairs + */ + public function testReplaceBooleanWords($before, $after) + { + $this->assertEquals($after, Util::replaceBooleanWords($before)); + } + + public function getReplaceBooleanWordsPairs() + { + return array( + array('to be OR not to be', 'to be || not to be'), + array('ORIGINAL GIFTS', 'ORIGINAL GIFTS'), + array('Black AND White', 'Black && White'), + array('TIMBERLAND Men`s', 'TIMBERLAND Men`s'), + array('hello NOT kitty', 'hello !kitty'), + array('SEND NOTIFICATION', 'SEND NOTIFICATION'), + ); + } + + /** + * @group unit + */ public function testEscapeTermSpecialCharacters() { - $before = '\\+-&&||!(){}[]^"~*?:/'; - $after = '\\\\\\+\\-\\&&\\||\\!\\(\\)\\{\\}\\[\\]\\^\\"\\~\\*\\?\\:\\\\/'; + $before = '\\+-&&||!(){}[]^"~*?:/<>'; + $after = '\\\\\\+\\-\\&&\\||\\!\\(\\)\\{\\}\\[\\]\\^\\"\\~\\*\\?\\:\\/\<\>'; $this->assertEquals(Util::escapeTerm($before), $after); } + /** + * @group unit + */ public function testToCamelCase() { $string = 'hello_world'; @@ -46,6 +73,9 @@ class UtilTest extends BaseTest $this->assertEquals('HowAreYouToday', Util::toCamelCase($string)); } + /** + * @group unit + */ public function testToSnakeCase() { $string = 'HelloWorld'; @@ -55,6 +85,9 @@ class UtilTest extends BaseTest $this->assertEquals('how_are_you_today', Util::toSnakeCase($string)); } + /** + * @group unit + */ public function testConvertRequestToCurlCommand() { $path = 'test'; @@ -63,15 +96,44 @@ class UtilTest extends BaseTest $data = array('key' => 'value'); $connection = new Connection(); - $connection->setHost('localhost'); + $connection->setHost($this->_getHost()); $connection->setPort('9200'); $request = new Request($path, $method, $data, $query, $connection); $curlCommand = Util::convertRequestToCurlCommand($request); - $expected = 'curl -XPOST \'http://localhost:9200/test?no=params\' -d \'{"key":"value"}\''; + $expected = 'curl -XPOST \'http://'.$this->_getHost().':9200/test?no=params\' -d \'{"key":"value"}\''; $this->assertEquals($expected, $curlCommand); + } + + /** + * @group unit + */ + public function testConvertDateTimeObjectWithTimezone() + { + $dateTimeObject = new \DateTime(); + $timestamp = $dateTimeObject->getTimestamp(); + + $convertedString = Util::convertDateTimeObject($dateTimeObject); + + $date = date('Y-m-d\TH:i:sP', $timestamp); + + $this->assertEquals($convertedString, $date); + } + + /** + * @group unit + */ + public function testConvertDateTimeObjectWithoutTimezone() + { + $dateTimeObject = new \DateTime(); + $timestamp = $dateTimeObject->getTimestamp(); + + $convertedString = Util::convertDateTimeObject($dateTimeObject, false); + + $date = date('Y-m-d\TH:i:s\Z', $timestamp); + $this->assertEquals($convertedString, $date); } } |