Skip to content

Commit

Permalink
Add DevicesDetection Module
Browse files Browse the repository at this point in the history
  • Loading branch information
cammackmatthew committed Mar 14, 2023
1 parent 51023b8 commit 064d08e
Show file tree
Hide file tree
Showing 4 changed files with 249 additions and 0 deletions.
110 changes: 110 additions & 0 deletions src/RobBrazier/Piwik/Module/DevicesDetectionModule.php
@@ -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);
}
}
13 changes: 13 additions & 0 deletions src/RobBrazier/Piwik/Piwik.php
Expand Up @@ -5,6 +5,7 @@
use RobBrazier\Piwik\Module\ActionsModule;
use RobBrazier\Piwik\Module\APIModule;
use RobBrazier\Piwik\Module\ContentsModule;
use RobBrazier\Piwik\Module\DevicesDetectionModule;
use RobBrazier\Piwik\Module\EventsModule;
use RobBrazier\Piwik\Module\LiveModule;
use RobBrazier\Piwik\Module\ProviderModule;
Expand Down Expand Up @@ -220,6 +221,18 @@ public function getUserCountry()
return new UserCountryModule($this->request);
}

/**
* Initialise the DevicesDetection Module.
*
* @see https://developer.matomo.org/api-reference/reporting-api#DevicesDetection for arguments
*
* @return DevicesDetectionModule
*/
public function getDevicesDetection()
{
return new DevicesDetectionModule($this->request);
}

/**
* Get javascript tag for use in tracking the website.
*
Expand Down
119 changes: 119 additions & 0 deletions tests/RobBrazier/Piwik/Module/DevicesDetectionModuleTest.php
@@ -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);
}
}
7 changes: 7 additions & 0 deletions tests/RobBrazier/Piwik/PiwikTest.php
Expand Up @@ -8,6 +8,7 @@
use RobBrazier\Piwik\Module\ActionsModule;
use RobBrazier\Piwik\Module\APIModule;
use RobBrazier\Piwik\Module\ContentsModule;
use RobBrazier\Piwik\Module\DevicesDetectionModule;
use RobBrazier\Piwik\Module\EventsModule;
use RobBrazier\Piwik\Module\LiveModule;
use RobBrazier\Piwik\Module\ProviderModule;
Expand Down Expand Up @@ -136,6 +137,12 @@ public function testGetUserCountry()
$this->assertInstanceOf(UserCountryModule::class, $userCountry);
}

public function testGetDevicesDetection()
{
$devicesDetection = $this->piwik->getDevicesDetection();
$this->assertInstanceOf(DevicesDetectionModule::class, $devicesDetection);
}

public function testGetTag()
{
$siteId = '1';
Expand Down

0 comments on commit 064d08e

Please sign in to comment.