Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51023b8
commit 064d08e
Showing
4 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
namespace RobBrazier\Piwik\Module; | ||
|
||
class DevicesDetectionModule extends Module | ||
{ | ||
/** | ||
* @param array[string]mixed $arguments extra arguments to be passed to the api call | ||
* @param string $format override format (defaults to one specified in config file) | ||
* | ||
* @return mixed | ||
*/ | ||
public function getType($arguments = [], $format = null) | ||
{ | ||
$options = $this->getOptions($format)->setArguments($arguments); | ||
|
||
return $this->request->send($options); | ||
} | ||
|
||
/** | ||
* @param array[string]mixed $arguments extra arguments to be passed to the api call | ||
* @param string $format override format (defaults to one specified in config file) | ||
* | ||
* @return mixed | ||
*/ | ||
public function getBrand($arguments = [], $format = null) | ||
{ | ||
$options = $this->getOptions($format)->setArguments($arguments); | ||
|
||
return $this->request->send($options); | ||
} | ||
|
||
/** | ||
* @param array[string]mixed $arguments extra arguments to be passed to the api call | ||
* @param string $format override format (defaults to one specified in config file) | ||
* | ||
* @return mixed | ||
*/ | ||
public function getModel($arguments = [], $format = null) | ||
{ | ||
$options = $this->getOptions($format)->setArguments($arguments); | ||
|
||
return $this->request->send($options); | ||
} | ||
|
||
/** | ||
* @param array[string]mixed $arguments extra arguments to be passed to the api call | ||
* @param string $format override format (defaults to one specified in config file) | ||
* | ||
* @return mixed | ||
*/ | ||
public function getOsFamilies($arguments = [], $format = null) | ||
{ | ||
$options = $this->getOptions($format)->setArguments($arguments); | ||
|
||
return $this->request->send($options); | ||
} | ||
|
||
/** | ||
* @param array[string]mixed $arguments extra arguments to be passed to the api call | ||
* @param string $format override format (defaults to one specified in config file) | ||
* | ||
* @return mixed | ||
*/ | ||
public function getOsVersions($arguments = [], $format = null) | ||
{ | ||
$options = $this->getOptions($format)->setArguments($arguments); | ||
|
||
return $this->request->send($options); | ||
} | ||
|
||
/** | ||
* @param array[string]mixed $arguments extra arguments to be passed to the api call | ||
* @param string $format override format (defaults to one specified in config file) | ||
* | ||
* @return mixed | ||
*/ | ||
public function getBrowsers($arguments = [], $format = null) | ||
{ | ||
$options = $this->getOptions($format)->setArguments($arguments); | ||
|
||
return $this->request->send($options); | ||
} | ||
|
||
/** | ||
* @param array[string]mixed $arguments extra arguments to be passed to the api call | ||
* @param string $format override format (defaults to one specified in config file) | ||
* | ||
* @return mixed | ||
*/ | ||
public function getBrowserVersions($arguments = [], $format = null) | ||
{ | ||
$options = $this->getOptions($format)->setArguments($arguments); | ||
|
||
return $this->request->send($options); | ||
} | ||
|
||
/** | ||
* @param array[string]mixed $arguments extra arguments to be passed to the api call | ||
* @param string $format override format (defaults to one specified in config file) | ||
* | ||
* @return mixed | ||
*/ | ||
public function getBrowserEngines($arguments = [], $format = null) | ||
{ | ||
$options = $this->getOptions($format)->setArguments($arguments); | ||
|
||
return $this->request->send($options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
tests/RobBrazier/Piwik/Module/DevicesDetectionModuleTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
|
||
namespace RobBrazier\Piwik\Module; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\Prophet; | ||
use RobBrazier\Piwik\Repository\RequestRepository; | ||
use RobBrazier\Piwik\Request\RequestOptions; | ||
|
||
class DevicesDetectionModuleTest extends TestCase | ||
{ | ||
/** | ||
* @var Prophet | ||
*/ | ||
private $prophet; | ||
|
||
private $request; | ||
|
||
/** | ||
* @var DevicesDetectionModule | ||
*/ | ||
private $devicesDetection; | ||
|
||
/** | ||
* @var RequestOptions | ||
*/ | ||
private $requestOptions; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $expectedResponse; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->prophet = new Prophet(); | ||
$this->request = $this->prophet->prophesize(RequestRepository::class); | ||
$this->devicesDetection = new DevicesDetectionModule($this->request->reveal()); | ||
$this->requestOptions = new RequestOptions(); | ||
$this->requestOptions | ||
->usePeriod(true) | ||
->useSiteId(true) | ||
->useFormat(true) | ||
->useTokenAuth(true); | ||
$this->expectedResponse = 'foo'; | ||
} | ||
|
||
public function testGetType() | ||
{ | ||
$this->requestOptions | ||
->setMethod('DevicesDetection.getType'); | ||
$this->request->send($this->requestOptions)->willReturn($this->expectedResponse); | ||
$response = $this->devicesDetection->getType(); | ||
$this->assertEquals($this->expectedResponse, $response); | ||
} | ||
|
||
public function testGetBrand() | ||
{ | ||
$this->requestOptions | ||
->setMethod('DevicesDetection.getBrand'); | ||
$this->request->send($this->requestOptions)->willReturn($this->expectedResponse); | ||
$response = $this->devicesDetection->getBrand(); | ||
$this->assertEquals($this->expectedResponse, $response); | ||
} | ||
|
||
public function testGetModel() | ||
{ | ||
$this->requestOptions | ||
->setMethod('DevicesDetection.getModel'); | ||
$this->request->send($this->requestOptions)->willReturn($this->expectedResponse); | ||
$response = $this->devicesDetection->getModel(); | ||
$this->assertEquals($this->expectedResponse, $response); | ||
} | ||
|
||
public function testGetOsFamilies() | ||
{ | ||
$this->requestOptions | ||
->setMethod('DevicesDetection.getOsFamilies'); | ||
$this->request->send($this->requestOptions)->willReturn($this->expectedResponse); | ||
$response = $this->devicesDetection->getOsFamilies(); | ||
$this->assertEquals($this->expectedResponse, $response); | ||
} | ||
|
||
public function testGetOsVersions() | ||
{ | ||
$this->requestOptions | ||
->setMethod('DevicesDetection.getOsVersions'); | ||
$this->request->send($this->requestOptions)->willReturn($this->expectedResponse); | ||
$response = $this->devicesDetection->getOsVersions(); | ||
$this->assertEquals($this->expectedResponse, $response); | ||
} | ||
|
||
public function testGetBrowsers() | ||
{ | ||
$this->requestOptions | ||
->setMethod('DevicesDetection.getBrowsers'); | ||
$this->request->send($this->requestOptions)->willReturn($this->expectedResponse); | ||
$response = $this->devicesDetection->getBrowsers(); | ||
$this->assertEquals($this->expectedResponse, $response); | ||
} | ||
|
||
public function testGetBrowserVersions() | ||
{ | ||
$this->requestOptions | ||
->setMethod('DevicesDetection.getBrowserVersions'); | ||
$this->request->send($this->requestOptions)->willReturn($this->expectedResponse); | ||
$response = $this->devicesDetection->getBrowserVersions(); | ||
$this->assertEquals($this->expectedResponse, $response); | ||
} | ||
|
||
public function testGetBrowserEngines() | ||
{ | ||
$this->requestOptions | ||
->setMethod('DevicesDetection.getBrowserEngines'); | ||
$this->request->send($this->requestOptions)->willReturn($this->expectedResponse); | ||
$response = $this->devicesDetection->getBrowserEngines(); | ||
$this->assertEquals($this->expectedResponse, $response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters