Kohana v3.3.5
This commit is contained in:
@@ -196,6 +196,30 @@ class Kohana_TextTest extends Unittest_TestCase
|
||||
$this->assertSame('yes', Text::alternate($val_a, $val_b, $val_c));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides test data for test_ucfirst
|
||||
*
|
||||
* @return array Test data
|
||||
*/
|
||||
public function provider_ucfirst()
|
||||
{
|
||||
return array(
|
||||
array('Content-Type', 'content-type', '-'),
|
||||
array('Բարեւ|Ձեզ', 'բարեւ|ձեզ', '|'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Covers Text::ucfirst()
|
||||
*
|
||||
* @test
|
||||
* @dataProvider provider_ucfirst
|
||||
*/
|
||||
public function test_ucfirst($expected, $string, $delimiter)
|
||||
{
|
||||
$this->assertSame($expected, Text::ucfirst($string, $delimiter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides test data for test_reducde_slashes()
|
||||
*
|
||||
@@ -386,9 +410,90 @@ class Kohana_TextTest extends Unittest_TestCase
|
||||
{
|
||||
return array
|
||||
(
|
||||
array('No gain, no pain', 'No gain, no pain'),
|
||||
array("spaces?what'rethey?", "spaces?what'rethey?"),
|
||||
array('', ''),
|
||||
// A very simple widont test
|
||||
array(
|
||||
'A very simple test',
|
||||
'A very simple test',
|
||||
),
|
||||
// Single word items shouldn't be changed
|
||||
array(
|
||||
'Test',
|
||||
'Test',
|
||||
),
|
||||
// Single word after single space shouldn't be changed either
|
||||
array(
|
||||
' Test',
|
||||
' Test',
|
||||
),
|
||||
// Single word with HTML all around
|
||||
array(
|
||||
'<ul><li><p>Test</p></li><ul>',
|
||||
'<ul><li><p>Test</p></li><ul>',
|
||||
),
|
||||
// Single word after single space with HTML all around
|
||||
array(
|
||||
'<ul><li><p> Test</p></li><ul>',
|
||||
'<ul><li><p> Test</p></li><ul>',
|
||||
),
|
||||
// Widont with more than one paragraph
|
||||
array(
|
||||
'<p>In a couple of paragraphs</p><p>paragraph two</p>',
|
||||
'<p>In a couple of paragraphs</p><p>paragraph two</p>',
|
||||
),
|
||||
// a link inside a heading
|
||||
array(
|
||||
'<h1><a href="#">In a link inside a heading </a></h1>',
|
||||
'<h1><a href="#">In a link inside a heading </a></h1>',
|
||||
),
|
||||
// a link followed by text
|
||||
array(
|
||||
'<h1><a href="#">In a link</a> followed by other text</h1>',
|
||||
'<h1><a href="#">In a link</a> followed by other text</h1>',
|
||||
),
|
||||
// empty html, with no text inside
|
||||
array(
|
||||
'<h1><a href="#"></a></h1>',
|
||||
'<h1><a href="#"></a></h1>',
|
||||
),
|
||||
// apparently, we don't love DIVs
|
||||
array(
|
||||
'<div>Divs get no love!</div>',
|
||||
'<div>Divs get no love!</div>',
|
||||
),
|
||||
// we don't love PREs, either
|
||||
array(
|
||||
'<pre>Neither do PREs</pre>',
|
||||
'<pre>Neither do PREs</pre>',
|
||||
),
|
||||
// but we love DIVs with paragraphs
|
||||
array(
|
||||
'<div><p>But divs with paragraphs do!</p></div>',
|
||||
'<div><p>But divs with paragraphs do!</p></div>',
|
||||
),
|
||||
array(
|
||||
'No gain, no pain',
|
||||
'No gain, no pain',
|
||||
),
|
||||
array(
|
||||
"spaces?what'rethey?",
|
||||
"spaces?what'rethey?",
|
||||
),
|
||||
/*
|
||||
* // @issue 3499, with HTML at the end
|
||||
* array(
|
||||
* 'with HTML at the end <strong>Kohana</strong>',
|
||||
* 'with HTML at the end <strong>Kohana</strong>',
|
||||
* ),
|
||||
* // @issue 3499, with HTML with attributes at the end
|
||||
* array(
|
||||
* 'with HTML at the end: <a href="#" title="Kohana">Kohana</a>',
|
||||
* 'with HTML at the end: <a href="#" title="Kohana">Kohana</a>',
|
||||
* ),
|
||||
*/
|
||||
array(
|
||||
'',
|
||||
'',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -639,4 +744,111 @@ class Kohana_TextTest extends Unittest_TestCase
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function provider_user_agents()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
"Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36",
|
||||
array(
|
||||
'browser' => 'Chrome',
|
||||
'version' => '37.0.2049.0',
|
||||
'platform' => "Windows 8.1"
|
||||
)
|
||||
),
|
||||
array(
|
||||
"Mozilla/5.0 (Macintosh; U; Mac OS X 10_6_1; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/ Safari/530.5",
|
||||
array(
|
||||
'browser' => 'Chrome',
|
||||
'version' => '530.5',
|
||||
'platform' => "Mac OS X"
|
||||
)
|
||||
),
|
||||
array(
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13+ (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",
|
||||
array(
|
||||
'browser' => 'Safari',
|
||||
'version' => '534.57.2',
|
||||
'platform' => 'Mac OS X'
|
||||
)
|
||||
),
|
||||
array(
|
||||
"Lynx/2.8.8dev.3 libwww-FM/2.14 SSL-MM/1.4.1",
|
||||
array(
|
||||
'browser' => 'Lynx',
|
||||
'version' => '2.8.8dev.3',
|
||||
'platform' => false
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Text::user_agent
|
||||
*
|
||||
* @dataProvider provider_user_agents
|
||||
* @group current
|
||||
*/
|
||||
public function test_user_agent_returns_correct_browser($userAgent, $expectedData)
|
||||
{
|
||||
$browser = Text::user_agent($userAgent, 'browser');
|
||||
|
||||
$this->assertEquals($expectedData['browser'], $browser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Text::user_agent
|
||||
*
|
||||
* @dataProvider provider_user_agents
|
||||
* @test
|
||||
*/
|
||||
public function test_user_agent_returns_correct_version($userAgent, $expectedData)
|
||||
{
|
||||
$version = Text::user_agent($userAgent, 'version');
|
||||
|
||||
$this->assertEquals($expectedData['version'], $version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Text::user_agent
|
||||
* @test
|
||||
*/
|
||||
public function test_user_agent_recognizes_robots()
|
||||
{
|
||||
$bot = Text::user_agent('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', 'robot');
|
||||
|
||||
$this->assertEquals('Googlebot', $bot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Text::user_agent
|
||||
*
|
||||
* @dataProvider provider_user_agents
|
||||
* @test
|
||||
*/
|
||||
public function test_user_agent_returns_correct_platform($userAgent, $expectedData)
|
||||
{
|
||||
$platform = Text::user_agent($userAgent, 'platform');
|
||||
|
||||
$this->assertEquals($expectedData['platform'], $platform);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests Text::user_agent
|
||||
* @test
|
||||
*/
|
||||
public function test_user_agent_accepts_array()
|
||||
{
|
||||
$agent_info = Text::user_agent(
|
||||
'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 '.
|
||||
'(KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36',
|
||||
array('browser', 'version', 'platform'));
|
||||
|
||||
$this->assertArrayHasKey('browser', $agent_info);
|
||||
$this->assertArrayHasKey('version', $agent_info);
|
||||
$this->assertArrayHasKey('platform', $agent_info);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user