@@ -23,6 +23,16 @@ protected function setUp()
2323 $ this ->mock = $ this ->getMock ('Archive7z\Archive7z ' , null , array ('fake.7z ' , $ this ->cliPath ));
2424 }
2525
26+
27+ protected function getCurrentFilesystemEncoding ()
28+ {
29+ if (stripos (PHP_OS , 'WIN ' ) !== false ) { // windows
30+ return 'Windows-1251 ' ;
31+ }
32+ return exec ('locale charmap ' );
33+ }
34+
35+
2636 protected function tearDown ()
2737 {
2838 $ this ->cleanDir ($ this ->tmpDir );
@@ -110,7 +120,7 @@ public function testExtract()
110120 public function testExtractCyrillic ()
111121 {
112122 $ dirCyrillic = $ this ->tmpDir . '/папка ' ;
113- $ chavezFile = iconv ('UTF-8 ' , ' Windows-1251 ' , 'чавес.jpg ' );
123+ $ chavezFile = iconv ('UTF-8 ' , $ this -> getCurrentFilesystemEncoding () , 'чавес.jpg ' );
114124
115125 if (!mkdir ($ dirCyrillic )) {
116126 self ::markTestIncomplete ('Cant create cyrillic directory. ' );
@@ -231,9 +241,9 @@ public function testExtractEntryOverwrite()
231241 }
232242
233243
234- public function testExtractEntryUnicode ()
244+ public function testExtractEntryCyrillic ()
235245 {
236- $ file = iconv ('UTF-8 ' , ' Windows-1251 ' , 'чавес.jpg ' );
246+ $ file = iconv ('UTF-8 ' , $ this -> getCurrentFilesystemEncoding () , 'чавес.jpg ' );
237247 $ obj = new Archive7z ($ this ->fixturesDir . '/test.7z ' , $ this ->cliPath );
238248 $ obj ->setOutputDirectory ($ this ->tmpDir );
239249 $ obj ->extractEntry ($ file );
@@ -396,4 +406,25 @@ public function testRenameEntryPasswd()
396406 $ resultDest = $ obj ->getEntry ('test ' . DIRECTORY_SEPARATOR . 'newTest.txt ' );
397407 self ::assertInstanceOf ('Archive7z\Entry ' , $ resultDest );
398408 }
409+
410+
411+ public function testChangeSystemLocale ()
412+ {
413+ $ file = iconv ('UTF-8 ' , $ this ->getCurrentFilesystemEncoding (), 'чавес.jpg ' );
414+ $ obj = new Archive7z ($ this ->fixturesDir . '/test.7z ' , $ this ->cliPath );
415+ $ obj ->setChangeSystemLocale (true );
416+ $ obj ->setOutputDirectory ($ this ->tmpDir );
417+ $ obj ->extractEntry ($ file );
418+
419+ self ::assertFileExists ($ this ->tmpDir . '/ ' . $ file );
420+ }
421+
422+ public function testChangeSystemLocaleFail ()
423+ {
424+ $ new = new Archive7z ($ this ->tmpDir . '/test.7z ' , $ this ->cliPath );
425+ $ new ->setChangeSystemLocale (true );
426+ $ this ->setExpectedException ('Archive7z\Exception ' );
427+ $ new ->getContent ('file.txt ' );
428+ }
429+
399430}
0 commit comments