Skip to content

Commit

Permalink
cleaned os detections; added at least one test for each os
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl committed Aug 28, 2014
1 parent ffd6271 commit 6681818
Show file tree
Hide file tree
Showing 4 changed files with 636 additions and 5 deletions.
5 changes: 2 additions & 3 deletions Parser/OperatingSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class OperatingSystem extends ParserAbstract
'KBT' => 'Kubuntu',
'LIN' => 'GNU/Linux',
'LBT' => 'Lubuntu',
'VLN' => 'VectorLinux',
'MAC' => 'Mac',
'MDR' => 'Mandriva',
'SMG' => 'MeeGo',
Expand All @@ -68,8 +69,6 @@ class OperatingSystem extends ParserAbstract
'OBS' => 'OpenBSD',
'PSP' => 'PlayStation Portable',
'PS3' => 'PlayStation',
'PRS' => 'Presto',
'PPY' => 'Puppy',
'RHT' => 'Red Hat',
'ROS' => 'RISC OS',
'SAB' => 'Sabayon',
Expand Down Expand Up @@ -130,7 +129,7 @@ class OperatingSystem extends ParserAbstract
'IBM' => array('OS2'),
'iOS' => array('IOS'),
'RISC OS' => array('ROS'),
'GNU/Linux' => array('LIN', 'ARL', 'DEB', 'KNO', 'MIN', 'UBT', 'KBT', 'XBT', 'LBT', 'FED', 'RHT', 'MDR', 'GNT', 'SAB', 'SLW', 'SSE', 'PPY', 'CES', 'BTR', 'YNS', 'PRS', 'SAF'),
'GNU/Linux' => array('LIN', 'ARL', 'DEB', 'KNO', 'MIN', 'UBT', 'KBT', 'XBT', 'LBT', 'FED', 'RHT', 'VLN', 'MDR', 'GNT', 'SAB', 'SLW', 'SSE', 'CES', 'BTR', 'YNS', 'SAF'),
'Mac' => array('MAC'),
'Mobile Gaming Console' => array('PSP', 'NDS', 'XBX'),
'Other Mobile' => array('WOS', 'POS', 'SBA', 'TIZ', 'SMG'),
Expand Down
42 changes: 42 additions & 0 deletions Tests/Parser/OperatingSystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@

class OperatingSystemTest extends \PHPUnit_Framework_TestCase
{
static $osTested = array();

/**
* @dataProvider getFixtures
*/
public function testParse($useragent, $os)
{
$osParser = new OperatingSystem();
$osParser->setUserAgent($useragent);
$this->assertEquals($os, $osParser->parse());
self::$osTested[] = $os['short_name'];
}

public function getFixtures()
{
$fixtureData = \Spyc::YAMLLoad(realpath(dirname(__FILE__)) . '/fixtures/oss.yml');
return $fixtureData;
}

/**
* @dataProvider getAllOs
*/
Expand All @@ -28,6 +47,22 @@ public function getAllOs()
return $allOs;
}

/**
* @dataProvider getAllFamilyOs
*/
public function testFamilyOSExists($os)
{
$allOs = array_keys(OperatingSystem::getAvailableOperatingSystems());
$this->assertContains($os, $allOs);
}

public function getAllFamilyOs()
{
$allFamilyOs = call_user_func_array('array_merge', OperatingSystem::getAvailableOperatingSystemFamilies());
$allFamilyOs = array_map(function($os){ return array($os); }, $allFamilyOs);
return $allFamilyOs;
}

public function testGetAvailableOperatingSystems()
{
$this->assertGreaterThan(70, OperatingSystem::getAvailableOperatingSystems());
Expand All @@ -50,4 +85,11 @@ public function getNameFromIds()
array('XXX', '4.5', false),
);
}

public function testAllBrowsersTested()
{
$allBrowsers = array_keys(OperatingSystem::getAvailableOperatingSystems());
$osNotTested = array_diff($allBrowsers, self::$osTested);
$this->assertEmpty($osNotTested, 'Following browsers are not tested: '.implode(', ', $osNotTested));
}
}
Loading

0 comments on commit 6681818

Please sign in to comment.