Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7450915
DeviceDetectorServiceTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
DeviceDetectorServiceTest.php
View Options
<?php
namespace
Tests\MobileFrontend\Devices
;
use
MediaWiki\Request\FauxRequest
;
use
MediaWiki\Request\WebRequest
;
use
MobileFrontend\Devices\DeviceDetector
;
use
MobileFrontend\Devices\DeviceDetectorService
;
use
MobileFrontend\Devices\DeviceProperties
;
/**
* @group MobileFrontend
*/
class
DeviceDetectorServiceTest
extends
\MediaWikiUnitTestCase
{
private
FauxRequest
$request
;
protected
function
setUp
():
void
{
parent
::
setUp
();
$this
->
request
=
new
FauxRequest
();
}
/**
* Creates a list of child device detectors from a list of results, which are
* then used to create an instance of `CompositeDeviceDetector`.
*
* @param array $results
* @return CompositeDeviceDetector
*/
private
function
createDetector
(
array
$results
)
{
$childFactory
=
static
function
(
$result
)
{
return
new
StubDeviceDetector
(
$result
);
};
return
new
DeviceDetectorService
(
array_map
(
$childFactory
,
$results
)
);
}
/**
* @covers \MobileFrontend\Devices\DeviceDetectorService::detectDeviceProperties
* @covers \MobileFrontend\Devices\DeviceDetectorService::__construct
* @covers \MobileFrontend\Devices\DeviceProperties::__construct
*/
public
function
testItShouldHandleOneChild
()
{
$expectedProperties
=
new
DeviceProperties
(
true
,
false
);
$detector
=
$this
->
createDetector
(
[
$expectedProperties
]
);
$properties
=
$detector
->
detectDeviceProperties
(
$this
->
request
,
[]
);
$this
->
assertSame
(
$expectedProperties
,
$properties
);
}
/**
* @covers \MobileFrontend\Devices\DeviceDetectorService::detectDeviceProperties
* @covers \MobileFrontend\Devices\DeviceDetectorService::__construct
* @covers \MobileFrontend\Devices\DeviceProperties::__construct
*/
public
function
testItShouldHandleManyChildren
()
{
$expectedProperties
=
new
DeviceProperties
(
true
,
false
);
$detector
=
$this
->
createDetector
(
[
null
,
null
,
$expectedProperties
]
);
$properties
=
$detector
->
detectDeviceProperties
(
$this
->
request
,
[]
);
$this
->
assertSame
(
$expectedProperties
,
$properties
);
}
/**
* @covers \MobileFrontend\Devices\DeviceDetectorService::detectDeviceProperties
* @covers \MobileFrontend\Devices\DeviceDetectorService::__construct
*/
public
function
testItShouldHandleZeroChildren
()
{
$detector
=
$this
->
createDetector
(
[]
);
$properties
=
$detector
->
detectDeviceProperties
(
$this
->
request
,
[]
);
$this
->
assertNull
(
$properties
);
}
}
class
StubDeviceDetector
implements
DeviceDetector
{
/** @var DeviceProperties|null */
private
$result
;
public
function
__construct
(
$result
)
{
$this
->
result
=
$result
;
}
public
function
detectDeviceProperties
(
WebRequest
$request
,
array
$server
)
{
return
$this
->
result
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 21:09 (2 d, 1 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
b0/e5/7c35e2ef844f483e5f5c14481882
Default Alt Text
DeviceDetectorServiceTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment