123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- class StrTest extends PHPUnit_Framework_TestCase {
-
- public function testEncodingShouldReturnApplicationEncoding()
- {
- $this->assertEquals('UTF-8', Config::get('application.encoding'));
- Config::set('application.encoding', 'foo');
- $this->assertEquals('foo', Config::get('application.encoding'));
- Config::set('application.encoding', 'UTF-8');
- }
-
- public function testStringLengthIsCorrect()
- {
- $this->assertEquals(6, Str::length('Taylor'));
- $this->assertEquals(5, Str::length('ラドクリフ'));
- }
-
- public function testStringCanBeConvertedToLowercase()
- {
- $this->assertEquals('taylor', Str::lower('TAYLOR'));
- $this->assertEquals('άχιστη', Str::lower('ΆΧΙΣΤΗ'));
- }
-
- public function testStringCanBeConvertedToUppercase()
- {
- $this->assertEquals('TAYLOR', Str::upper('taylor'));
- $this->assertEquals('ΆΧΙΣΤΗ', Str::upper('άχιστη'));
- }
-
- public function testStringCanBeConvertedToTitleCase()
- {
- $this->assertEquals('Taylor', Str::title('taylor'));
- $this->assertEquals('Άχιστη', Str::title('άχιστη'));
- }
-
- public function testStringCanBeLimitedByCharacters()
- {
- $this->assertEquals('Tay...', Str::limit('Taylor', 3));
- $this->assertEquals('Taylor', Str::limit('Taylor', 6));
- $this->assertEquals('Tay___', Str::limit('Taylor', 3, '___'));
- }
-
- public function testStringCanBeLimitedByWords()
- {
- $this->assertEquals('Taylor...', Str::words('Taylor Otwell', 1));
- $this->assertEquals('Taylor___', Str::words('Taylor Otwell', 1, '___'));
- $this->assertEquals('Taylor Otwell', Str::words('Taylor Otwell', 3));
- }
-
- public function testStringsCanBeSingularOrPlural()
- {
- $this->assertEquals('user', Str::singular('users'));
- $this->assertEquals('user', Str::singular('USERS'));
- $this->assertEquals('users', Str::plural('user'));
- $this->assertEquals('users', Str::plural('USER'));
- $this->assertEquals('user', Str::plural('user', 1));
- $this->assertEquals('users', Str::plural('user', 2));
- }
-
- public function testStringsCanBeSlugged()
- {
- $this->assertEquals('my-new-post', Str::slug('My nEw post!!!'));
- $this->assertEquals('my_new_post', Str::slug('My nEw post!!!', '_'));
- }
-
- public function testStringsCanBeClassified()
- {
- $this->assertEquals('Something_Else', Str::classify('something.else'));
- $this->assertEquals('Something_Else', Str::classify('something_else'));
- }
-
- public function testRandomStringsCanBeGenerated()
- {
- $this->assertEquals(40, strlen(Str::random(40)));
- }
- }
|