Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for UA returned value [not verified]
  • Loading branch information
dero committed Jun 16, 2020
commit 99878a0f0653e02d3e713baeea130eaf5a7912ef
28 changes: 20 additions & 8 deletions packages/mobile/tests/php/test_Mobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,31 @@ class Test_Mobile extends TestCase {
/**
* The is_mobile tests.
*
* @param string $ua User agent string.
* @param bool $expected_dumb Expected value for `dumb` mobile detection.
* @param bool $expected_smart Expected value for `smart` mobile detection.
* @param bool $expected_mobile Expected value for `any` mobile detection.
* @param string $ua User agent string.
* @param bool $expected_dumb Expected value for `dumb` mobile detection.
* @param bool $expected_smart Expected value for `smart` mobile detection.
* @param bool $expected_mobile Expected value for `any` mobile detection.
* @param bool $expected_ua_returned Expected value for UA returned by the method.
*
* @return void
*
* @dataProvider ua_provider
*/
public function test_is_mobile( $ua, $expected_dumb, $expected_smart, $expected_mobile ) {
public function test_is_mobile( $ua, $expected_dumb, $expected_smart, $expected_mobile, $expected_ua_returned ) {
$_SERVER['HTTP_USER_AGENT'] = $ua;

$dumb_test = Mobile::is_mobile( 'dumb', false );
$smart_test = Mobile::is_mobile( 'smart', false );
$mobile_test = Mobile::is_mobile( 'any', false );
$dumb_test = Mobile::is_mobile( 'dumb', false );
$smart_test = Mobile::is_mobile( 'smart', false );
$mobile_test = Mobile::is_mobile( 'any', false );
$mobile_test_ua = Mobile::is_mobile( 'any', true );

$this->assertEquals( $dumb_test, $expected_dumb );
$this->assertEquals( $smart_test, $expected_smart );
$this->assertEquals( $mobile_test, $expected_mobile );
$this->assertEquals( $mobile_test_ua, $expected_mobile ? $expected_ua_returned : false );
}


/**
* Data provider for test_is_mobile.
*
Expand All @@ -49,6 +53,7 @@ public function ua_provider() {
true,
false,
true,
'nokia',
),

// Samsung Galaxy S8 smart phone.
Expand All @@ -57,6 +62,7 @@ public function ua_provider() {
false,
true,
true,
'android',
),

// iPhone X smart phone.
Expand All @@ -65,6 +71,7 @@ public function ua_provider() {
false,
true,
true,
'iphone',
),

// iPad 2 10.5 tablet.
Expand All @@ -73,6 +80,7 @@ public function ua_provider() {
false,
false,
false, // not considered a mobile device, this is intended.
false,
),

// Kindle 3.
Expand All @@ -81,6 +89,7 @@ public function ua_provider() {
false,
true,
true,
'android',
),

// Huawei p20 smartphone.
Expand All @@ -89,6 +98,7 @@ public function ua_provider() {
false,
true,
true,
'android',
),

// Googlebot smartphone.
Expand All @@ -97,6 +107,7 @@ public function ua_provider() {
false,
true,
true,
'android',
),

// Googlebot desktop.
Expand All @@ -105,6 +116,7 @@ public function ua_provider() {
false,
false,
false,
false,
),
);
}
Expand Down