Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
31 / 31
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
phpbb_utf_utf8_wordwrap_test
100.00% covered (success)
100.00%
31 / 31
100.00% covered (success)
100.00%
4 / 4
6
100.00% covered (success)
100.00%
1 / 1
 test_utf8_wordwrap_ascii
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
1
 turn_into_greek
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
 test_utf8_wordwrap_utf8
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 test_utf8_wordwrap_utf8_cut
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14class phpbb_utf_utf8_wordwrap_test extends phpbb_test_case
15{
16    public function test_utf8_wordwrap_ascii()
17    {
18        // if the input is all ascii it should work exactly like php's wordwrap
19
20        $text = 'The quick brown fox jumped over the lazy dog.';
21
22        $php_wordwrap = wordwrap($text, 20);
23        $phpbb_utf8_wordwrap = utf8_wordwrap($text, 20);
24        $this->assertEquals($php_wordwrap, $phpbb_utf8_wordwrap, "Checking ASCII standard behaviour with length 20");
25
26        $php_wordwrap = wordwrap($text, 30, "<br />\n");
27        $phpbb_utf8_wordwrap = utf8_wordwrap($text, 30, "<br />\n");
28        $this->assertEquals($php_wordwrap, $phpbb_utf8_wordwrap, "Checking ASCII special break string with length 30");
29
30        $text = 'A very long woooooooooooord.';
31
32        $php_wordwrap = wordwrap($text, 8, "\n");
33        $phpbb_utf8_wordwrap = utf8_wordwrap($text, 8, "\n");
34        $this->assertEquals($php_wordwrap, $phpbb_utf8_wordwrap, 'Checking ASCII not cutting long words');
35
36        $php_wordwrap = wordwrap($text, 8, "\n", true);
37        $phpbb_utf8_wordwrap = utf8_wordwrap($text, 8, "\n", true);
38        $this->assertEquals($php_wordwrap, $phpbb_utf8_wordwrap, 'Checking ASCII cutting long words');
39    }
40
41    /**
42    * Helper function that generates meaningless greek text
43    */
44    private function turn_into_greek($string)
45    {
46        $greek_chars = array("\xCE\x90", "\xCE\x91", "\xCE\x92", "\xCE\x93", "\xCE\x94", "\xCE\x95", "\xCE\x96", "\xCE\x97", "\xCE\x98", "\xCE\x99");
47
48        $greek = '';
49        for ($i = 0, $n = strlen($string); $i < $n; $i++)
50        {
51            // replace each number with the character from the array
52            if (ctype_digit($string[$i]))
53            {
54                $greek .= $greek_chars[(int) $string[$i]];
55            }
56            else
57            {
58                $greek .= $string[$i];
59            }
60        }
61
62        return $greek;
63    }
64
65    public function test_utf8_wordwrap_utf8()
66    {
67        $text = "0123456 0123 012345 01234";
68        $greek = $this->turn_into_greek($text);
69
70        $expected = $this->turn_into_greek(wordwrap($text, 10));
71        $phpbb_utf8_wordwrap = utf8_wordwrap($greek, 10);
72        $this->assertEquals($expected, $phpbb_utf8_wordwrap, 'Checking UTF-8 standard behaviour with length 10');
73    }
74
75    public function test_utf8_wordwrap_utf8_cut()
76    {
77        $text = "0123456 0123 012345 01234";
78        $greek = $this->turn_into_greek($text);
79
80        $expected = $this->turn_into_greek(wordwrap($text, 5, "\n", true));
81        $phpbb_utf8_wordwrap = utf8_wordwrap($greek, 5, "\n", true);
82        $this->assertEquals($expected, $phpbb_utf8_wordwrap, 'Checking UTF-8 cutting long words');
83    }
84}
85