FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
EncodingConverterTest.php
1 <?php
2 /*
3 Copyright (C) 2014, Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 namespace Fossology\Lib\Text;
20 
21 class EncodingConverterTest extends \PHPUnit\Framework\TestCase
22 {
23 
24  private $testString = "äöüßÄÖÜ";
25 
27  private $converter;
28 
29  protected function setUp()
30  {
31  $detected = mb_detect_encoding($this->testString);
32  assertThat($detected, is("UTF-8"));
33  $this->converter = new EncodingConverter();
34  }
35 
36  public function testUtf8IsKept()
37  {
38  assertThat( $this->converter->convert($this->testString), is($this->testString));
39  }
40 
41  public function testLatin15IsConverted()
42  {
43  $encodedString = iconv("UTF-8", "ISO-8859-15", $this->testString);
44  assertThat( $this->converter->convert($encodedString), is($this->testString));
45  }
46 
47  public function testMixedEncodingIsConvertedAndCoercedToUtf8()
48  {
49  $inputString = $this->testString;
50  $inputString .= iconv("UTF-8", "ISO-8859-15", $this->testString);
51  $outputString = $this->converter->convert($inputString);
52  assertThat( $outputString, endsWith($this->testString));
53  assertThat( strlen($outputString), is(greaterThan(2 * strlen($this->testString))));
54  }
55 
56  public function testMixedEncodingStartingWithLatin1IsConvertedAndCoercedToUtf8()
57  {
58  $inputString = iconv("UTF-8", "ISO-8859-15", $this->testString);
59  $inputString .= $this->testString;
60  $outputString = $this->converter->convert($inputString);
61  assertThat( $outputString, startsWith($this->testString));
62  assertThat( strlen($outputString), is(greaterThan(2 * strlen($this->testString))));
63  }
64 }