|
|
@ -1,6 +1,7 @@ |
|
|
|
<?php |
|
|
|
<?php |
|
|
|
namespace yiiunit\framework\helpers; |
|
|
|
namespace yiiunit\framework\helpers; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use yii\helpers\FileHelper; |
|
|
|
use yii\helpers\StringHelper; |
|
|
|
use yii\helpers\StringHelper; |
|
|
|
use yiiunit\TestCase; |
|
|
|
use yiiunit\TestCase; |
|
|
|
|
|
|
|
|
|
|
@ -12,57 +13,57 @@ class StringHelperTest extends TestCase |
|
|
|
{ |
|
|
|
{ |
|
|
|
public function testStrlen() |
|
|
|
public function testStrlen() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->assertEquals(4, StringHelper::strlen('this')); |
|
|
|
$this->assertEquals(4, StringHelper::byteLen('this')); |
|
|
|
$this->assertEquals(6, StringHelper::strlen('это')); |
|
|
|
$this->assertEquals(6, StringHelper::byteLen('это')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testSubstr() |
|
|
|
public function testSubstr() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->assertEquals('th', StringHelper::substr('this', 0, 2)); |
|
|
|
$this->assertEquals('th', StringHelper::byteSubstr('this', 0, 2)); |
|
|
|
$this->assertEquals('э', StringHelper::substr('это', 0, 2)); |
|
|
|
$this->assertEquals('э', StringHelper::byteSubstr('это', 0, 2)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testBasename() |
|
|
|
public function testBasename() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->assertEquals('', StringHelper::basename('')); |
|
|
|
$this->assertEquals('', FileHelper::basename('')); |
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('file', StringHelper::basename('file')); |
|
|
|
$this->assertEquals('file', FileHelper::basename('file')); |
|
|
|
$this->assertEquals('file.test', StringHelper::basename('file.test', '.test2')); |
|
|
|
$this->assertEquals('file.test', FileHelper::basename('file.test', '.test2')); |
|
|
|
$this->assertEquals('file', StringHelper::basename('file.test', '.test')); |
|
|
|
$this->assertEquals('file', FileHelper::basename('file.test', '.test')); |
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('file', StringHelper::basename('/file')); |
|
|
|
$this->assertEquals('file', FileHelper::basename('/file')); |
|
|
|
$this->assertEquals('file.test', StringHelper::basename('/file.test', '.test2')); |
|
|
|
$this->assertEquals('file.test', FileHelper::basename('/file.test', '.test2')); |
|
|
|
$this->assertEquals('file', StringHelper::basename('/file.test', '.test')); |
|
|
|
$this->assertEquals('file', FileHelper::basename('/file.test', '.test')); |
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('file', StringHelper::basename('/path/to/file')); |
|
|
|
$this->assertEquals('file', FileHelper::basename('/path/to/file')); |
|
|
|
$this->assertEquals('file.test', StringHelper::basename('/path/to/file.test', '.test2')); |
|
|
|
$this->assertEquals('file.test', FileHelper::basename('/path/to/file.test', '.test2')); |
|
|
|
$this->assertEquals('file', StringHelper::basename('/path/to/file.test', '.test')); |
|
|
|
$this->assertEquals('file', FileHelper::basename('/path/to/file.test', '.test')); |
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('file', StringHelper::basename('\file')); |
|
|
|
$this->assertEquals('file', FileHelper::basename('\file')); |
|
|
|
$this->assertEquals('file.test', StringHelper::basename('\file.test', '.test2')); |
|
|
|
$this->assertEquals('file.test', FileHelper::basename('\file.test', '.test2')); |
|
|
|
$this->assertEquals('file', StringHelper::basename('\file.test', '.test')); |
|
|
|
$this->assertEquals('file', FileHelper::basename('\file.test', '.test')); |
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('file', StringHelper::basename('C:\file')); |
|
|
|
$this->assertEquals('file', FileHelper::basename('C:\file')); |
|
|
|
$this->assertEquals('file.test', StringHelper::basename('C:\file.test', '.test2')); |
|
|
|
$this->assertEquals('file.test', FileHelper::basename('C:\file.test', '.test2')); |
|
|
|
$this->assertEquals('file', StringHelper::basename('C:\file.test', '.test')); |
|
|
|
$this->assertEquals('file', FileHelper::basename('C:\file.test', '.test')); |
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('file', StringHelper::basename('C:\path\to\file')); |
|
|
|
$this->assertEquals('file', FileHelper::basename('C:\path\to\file')); |
|
|
|
$this->assertEquals('file.test', StringHelper::basename('C:\path\to\file.test', '.test2')); |
|
|
|
$this->assertEquals('file.test', FileHelper::basename('C:\path\to\file.test', '.test2')); |
|
|
|
$this->assertEquals('file', StringHelper::basename('C:\path\to\file.test', '.test')); |
|
|
|
$this->assertEquals('file', FileHelper::basename('C:\path\to\file.test', '.test')); |
|
|
|
|
|
|
|
|
|
|
|
// mixed paths |
|
|
|
// mixed paths |
|
|
|
$this->assertEquals('file.test', StringHelper::basename('/path\to/file.test')); |
|
|
|
$this->assertEquals('file.test', FileHelper::basename('/path\to/file.test')); |
|
|
|
$this->assertEquals('file.test', StringHelper::basename('/path/to\file.test')); |
|
|
|
$this->assertEquals('file.test', FileHelper::basename('/path/to\file.test')); |
|
|
|
$this->assertEquals('file.test', StringHelper::basename('\path/to\file.test')); |
|
|
|
$this->assertEquals('file.test', FileHelper::basename('\path/to\file.test')); |
|
|
|
|
|
|
|
|
|
|
|
// \ and / in suffix |
|
|
|
// \ and / in suffix |
|
|
|
$this->assertEquals('file', StringHelper::basename('/path/to/filete/st', 'te/st')); |
|
|
|
$this->assertEquals('file', FileHelper::basename('/path/to/filete/st', 'te/st')); |
|
|
|
$this->assertEquals('st', StringHelper::basename('/path/to/filete/st', 'te\st')); |
|
|
|
$this->assertEquals('st', FileHelper::basename('/path/to/filete/st', 'te\st')); |
|
|
|
$this->assertEquals('file', StringHelper::basename('/path/to/filete\st', 'te\st')); |
|
|
|
$this->assertEquals('file', FileHelper::basename('/path/to/filete\st', 'te\st')); |
|
|
|
$this->assertEquals('st', StringHelper::basename('/path/to/filete\st', 'te/st')); |
|
|
|
$this->assertEquals('st', FileHelper::basename('/path/to/filete\st', 'te/st')); |
|
|
|
|
|
|
|
|
|
|
|
// http://www.php.net/manual/en/function.basename.php#72254 |
|
|
|
// http://www.php.net/manual/en/function.basename.php#72254 |
|
|
|
$this->assertEquals('foo', StringHelper::basename('/bar/foo/')); |
|
|
|
$this->assertEquals('foo', FileHelper::basename('/bar/foo/')); |
|
|
|
$this->assertEquals('foo', StringHelper::basename('\\bar\\foo\\')); |
|
|
|
$this->assertEquals('foo', FileHelper::basename('\\bar\\foo\\')); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|