summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/core/compat/mbstring_test.php
blob: 415222446d22b14020b14f23e6d8ca4a7891c3a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php

class mbstring_test extends CI_TestCase {

	public function test_bootstrap()
	{
		if (MB_ENABLED)
		{
			return $this->markTestSkipped('ext/mbstring is loaded');
		}

		$this->assertTrue(function_exists('mb_strlen'));
		$this->assertTrue(function_exists('mb_substr'));
	}

	// ------------------------------------------------------------------------

	/**
	 * @depends	test_bootstrap
	 */
	public function test_mb_strlen()
	{
		$this->assertEquals(ICONV_ENABLED ? 4 : 8, mb_strlen('тест'));
		$this->assertEquals(ICONV_ENABLED ? 4 : 8, mb_strlen('тест', 'UTF-8'));
	}

	// ------------------------------------------------------------------------

	/**
	 * @depends	test_boostrap
	 */
	public function test_mb_strpos()
	{
		$this->assertEquals(ICONV_ENABLED ? 3 : 6, mb_strpos('тест', 'с'));
		$this->assertFalse(mb_strpos('тест', 'с', 3));
		$this->assertEquals(ICONV_ENABLED ? 3 : 6, mb_strpos('тест', 'с', 1, 'UTF-8'));
	}

	// ------------------------------------------------------------------------

	/**
	 * @depends	test_boostrap
	 */
	public function test_mb_substr()
	{
		$this->assertEquals(ICONV_ENABLED ? 'стинг' : 'естинг', mb_substr('тестинг', 2));
		$this->assertEquals(ICONV_ENABLED ? 'нг' : 'г', mb_substr('тестинг', -2));
		$this->assertEquals(ICONV_ENABLED ? 'ст' : 'е', mb_substr('тестинг', 2, 2));
		$this->assertEquals(ICONV_ENABLED ? 'стинг' : 'естинг', mb_substr('тестинг', 2, 'UTF-8'));
		$this->assertEquals(ICONV_ENABLED ? 'нг' : 'г', mb_substr('тестинг', -2, 'UTF-8'));
		$this->assertEquals(ICONV_ENABLED ? 'ст' : 'е', mb_substr('тестинг', 2, 2, 'UTF-8'));
	}

}