File: mbstring_test.php

package info (click to toggle)
php-codeigniter-framework 3.1.13%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,228 kB
  • sloc: php: 37,178; xml: 205; makefile: 138; python: 66; sh: 65
file content (57 lines) | stat: -rw-r--r-- 1,888 bytes parent folder | download
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
55
56
57
<?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
	 */
	#[PHPUnit\Framework\Attributes\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_bootstrap
	 */
	#[PHPUnit\Framework\Attributes\Depends('test_bootstrap')]
	public function test_mb_strpos()
	{
		$this->assertEquals(ICONV_ENABLED ? 2 : 4, mb_strpos('тест', 'с'));
		$this->assertFalse(mb_strpos('тест', 'с', 3));
		$this->assertEquals(ICONV_ENABLED ? 2 : 4, mb_strpos('тест', 'с', 1, 'UTF-8'));
	}

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

	/**
	 * @depends	test_bootstrap
	 */
	#[PHPUnit\Framework\Attributes\Depends('test_bootstrap')]
	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, NULL, 'UTF-8'));
		$this->assertEquals(ICONV_ENABLED ? 'нг' : 'г', mb_substr('тестинг', -2, NULL, 'UTF-8'));
		$this->assertEquals(ICONV_ENABLED ? 'ст' : 'е', mb_substr('тестинг', 2, 2, 'UTF-8'));
	}

}