forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSupportStrTest.php
More file actions
executable file
·98 lines (76 loc) · 2.71 KB
/
SupportStrTest.php
File metadata and controls
executable file
·98 lines (76 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
use Illuminate\Support\Str;
class SupportStrTest extends PHPUnit_Framework_TestCase {
/**
* Test the Str::words method.
*
* @group laravel
*/
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 testStringTrimmedOnlyWhereNecessary()
{
$this->assertEquals(' Taylor Otwell ', Str::words(' Taylor Otwell ', 3));
$this->assertEquals(' Taylor...', Str::words(' Taylor Otwell ', 1));
}
public function testStringWithoutWordsDoesntProduceError()
{
$nbsp = chr(0xC2).chr(0xA0);
$this->assertEquals(' ', Str::words(' '));
$this->assertEquals($nbsp, Str::words($nbsp));
}
public function testStringMacros()
{
Illuminate\Support\Str::macro(__CLASS__, function() { return 'foo'; });
$this->assertEquals('foo', Str::SupportStrTest());
}
public function testStartsWith()
{
$this->assertTrue(Str::startsWith('jason', 'jas'));
$this->assertTrue(Str::startsWith('jason', 'jason'));
$this->assertTrue(Str::startsWith('jason', array('jas')));
$this->assertFalse(Str::startsWith('jason', 'day'));
$this->assertFalse(Str::startsWith('jason', array('day')));
$this->assertFalse(Str::startsWith('jason', ''));
}
public function testEndsWith()
{
$this->assertTrue(Str::endsWith('jason', 'on'));
$this->assertTrue(Str::endsWith('jason', 'jason'));
$this->assertTrue(Str::endsWith('jason', array('on')));
$this->assertFalse(Str::endsWith('jason', 'no'));
$this->assertFalse(Str::endsWith('jason', array('no')));
$this->assertFalse(Str::endsWith('jason', ''));
}
public function testStrContains()
{
$this->assertTrue(Str::contains('taylor', 'ylo'));
$this->assertTrue(Str::contains('taylor', array('ylo')));
$this->assertFalse(Str::contains('taylor', 'xxx'));
$this->assertFalse(Str::contains('taylor', array('xxx')));
$this->assertFalse(Str::contains('taylor', ''));
}
public function testParseCallback()
{
$this->assertEquals(array('Class', 'method'), Str::parseCallback('Class@method', 'foo'));
$this->assertEquals(array('Class', 'foo'), Str::parseCallback('Class', 'foo'));
}
public function testFinish()
{
$this->assertEquals('abbc', Str::finish('ab', 'bc'));
$this->assertEquals('abbc', Str::finish('abbcbc', 'bc'));
$this->assertEquals('abcbbc', Str::finish('abcbbcbc', 'bc'));
}
public function testIs()
{
$this->assertTrue(Str::is('/', '/'));
$this->assertFalse(Str::is('/', ' /'));
$this->assertFalse(Str::is('/', '/a'));
$this->assertTrue(Str::is('foo/*', 'foo/bar/baz'));
$this->assertTrue(Str::is('*/foo', 'blah/baz/foo'));
}
}