123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <?php
- /**
- * Lithium: the most rad php framework
- *
- * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
- * @license http://opensource.org/licenses/bsd-license.php The BSD License
- */
- namespace lithium\tests\cases\g11n\multibyte\adapter;
- use lithium\g11n\multibyte\adapter\Iconv;
- class IconvTest extends \lithium\test\Unit {
- public $adapter;
- public function skip() {
- $this->skipIf(!Iconv::enabled(), 'The `Iconv` adapter is not enabled.');
- }
- public function setUp() {
- $this->adapter = new Iconv();
- }
- public function testStrlen() {
- $data = 'äbc';
- $result = $this->adapter->strlen($data);
- $expected = 3;
- $this->assertEqual($expected, $result);
- }
- public function testStrlenAscii() {
- $data = 'abc';
- $result = $this->adapter->strlen($data);
- $expected = 3;
- $this->assertEqual($expected, $result);
- }
- public function testStrlenEmptyish() {
- $data = '';
- $result = $this->adapter->strlen($data);
- $expected = 0;
- $this->assertEqual($expected, $result);
- $data = ' ';
- $result = $this->adapter->strlen($data);
- $expected = 1;
- $this->assertEqual($expected, $result);
- $data = false;
- $result = $this->adapter->strlen($data);
- $expected = 0;
- $this->assertEqual($expected, $result);
- $data = null;
- $result = $this->adapter->strlen($data);
- $expected = 0;
- $this->assertEqual($expected, $result);
- $data = 0;
- $result = $this->adapter->strlen($data);
- $expected = 1;
- $this->assertEqual($expected, $result);
- $data = '0';
- $result = $this->adapter->strlen($data);
- $expected = 1;
- $this->assertEqual($expected, $result);
- }
- public function testStrlenInvalidTriggersError() {
- $this->expectException('/Detected an incomplete multibyte character in input string/');
- $data = "ab\xe9";
- $result = $this->adapter->strlen($data);
- }
- public function testStrpos() {
- $haystack = 'abäab';
- $needle = 'ä';
- $offset = 0;
- $result = $this->adapter->strpos($haystack, $needle, $offset);
- $expected = 2;
- $this->assertEqual($expected, $result);
- $haystack = 'abäab';
- $needle = 'X';
- $offset = 0;
- $result = $this->adapter->strpos($haystack, $needle, $offset);
- $this->assertFalse($result);
- }
- public function testStrposAscii() {
- $haystack = 'abcab';
- $needle = 'c';
- $offset = 0;
- $result = $this->adapter->strpos($haystack, $needle, $offset);
- $expected = 2;
- $this->assertEqual($expected, $result);
- }
- public function testStrposWithOffset() {
- $haystack = 'abäab';
- $needle = 'b';
- $offset = 0;
- $result = $this->adapter->strpos($haystack, $needle, $offset);
- $expected = 1;
- $this->assertEqual($expected, $result);
- $haystack = 'abäab';
- $needle = 'a';
- $offset = 1;
- $result = $this->adapter->strpos($haystack, $needle, $offset);
- $expected = 3;
- $this->assertEqual($expected, $result);
- }
- public function testStrposNeedleAsOrdinalIsNotApplied() {
- $haystack = 'abcab';
- $needle = 99;
- $offset = 0;
- $result = $this->adapter->strpos($haystack, $needle, $offset);
- $this->assertFalse($result);
- }
- public function testStrposTriggersError() {
- $haystack = "ab\xe9cab";
- $needle = 'c';
- $offset = 0;
- $this->expectException('/Detected an illegal character in input string/');
- $this->adapter->strpos($haystack, $needle, $offset);
- }
- public function testStrposInvalidOffset() {
- $haystack = 'abäab';
- $needle = 'a';
- $offset = -1;
- $this->expectException('/Offset not contained in string/');
- $this->adapter->strpos($haystack, $needle, $offset);
- }
- public function testStrrpos() {
- $haystack = 'abäab';
- $needle = 'ä';
- $result = $this->adapter->strrpos($haystack, $needle);
- $expected = 2;
- $this->assertEqual($expected, $result);
- $haystack = 'abäab';
- $needle = 'X';
- $result = $this->adapter->strrpos($haystack, $needle);
- $this->assertFalse($result);
- }
- public function testStrrposAscii() {
- $haystack = 'abcab';
- $needle = 'c';
- $result = $this->adapter->strrpos($haystack, $needle);
- $expected = 2;
- $this->assertEqual($expected, $result);
- }
- public function testStrrposWithOffset() {
- $haystack = 'abäab';
- $needle = 'b';
- $result = $this->adapter->strrpos($haystack, $needle);
- $expected = 4;
- $this->assertEqual($expected, $result);
- $haystack = 'abäab';
- $needle = 'a';
- $result = $this->adapter->strrpos($haystack, $needle);
- $expected = 3;
- $this->assertEqual($expected, $result);
- }
- public function testStrrposTriggersError() {
- $haystack = "ab\xe9cab";
- $needle = 'c';
- $this->expectException('/Detected an illegal character in input string/');
- $this->adapter->strrpos($haystack, $needle);
- }
- public function testSubstr() {
- $string = 'abäab';
- $start = 0;
- $length = 3;
- $result = $this->adapter->substr($string, $start, $length);
- $expected = 'abä';
- $this->assertEqual($expected, $result);
- $string = 'abäab';
- $start = 2;
- $length = 3;
- $result = $this->adapter->substr($string, $start, $length);
- $expected = 'äab';
- $this->assertEqual($expected, $result);
- $string = 'abäab';
- $start = -3;
- $length = 3;
- $result = $this->adapter->substr($string, $start, $length);
- $expected = 'äab';
- $this->assertEqual($expected, $result);
- }
- public function testSubstrAscii() {
- $string = 'abcab';
- $start = 0;
- $length = 3;
- $result = $this->adapter->substr($string, $start, $length);
- $expected = 'abc';
- $this->assertEqual($expected, $result);
- }
- public function testSubstrInvalidTriggersError() {
- $string = "ab\xe9cab";
- $start = 0;
- $length = 3;
- $this->expectException('/Detected an illegal character in input string/');
- $this->adapter->substr($string, $start, $length);
- }
- }
- ?>
|