Skip to content
Snippets Groups Projects
Commit 52ceecd9 authored by Demian Katz's avatar Demian Katz
Browse files

Dependency injection for Mobile class.

- Added tests.
parent 8a11fd02
No related merge requests found
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
* @link http://code.google.com/p/mobileesp/ MobileESP Project * @link http://code.google.com/p/mobileesp/ MobileESP Project
*/ */
namespace VuFindTheme; namespace VuFindTheme;
use uagent_info;
/** /**
* Mobile Device Detection Wrapper * Mobile Device Detection Wrapper
...@@ -44,6 +45,13 @@ namespace VuFindTheme; ...@@ -44,6 +45,13 @@ namespace VuFindTheme;
*/ */
class Mobile class Mobile
{ {
/**
* Mobile detection object
*
* @var uagent_info
*/
protected $detector;
/** /**
* Are mobile themes enabled? * Are mobile themes enabled?
* *
...@@ -51,6 +59,16 @@ class Mobile ...@@ -51,6 +59,16 @@ class Mobile
*/ */
protected $enabled = false; protected $enabled = false;
/**
* Constructor
*
* @param uagent_info $detector Detector object to wrap (null to create one)
*/
public function __construct(uagent_info $detector = null)
{
$this->detector = (null === $detector) ? new uagent_info() : $detector;
}
/** /**
* Function to detect if a mobile device is being used. * Function to detect if a mobile device is being used.
* *
...@@ -61,8 +79,7 @@ class Mobile ...@@ -61,8 +79,7 @@ class Mobile
// Do the most exhaustive device detection possible; other method calls // Do the most exhaustive device detection possible; other method calls
// may be used instead of DetectMobileLong if you want to target a narrower // may be used instead of DetectMobileLong if you want to target a narrower
// class of devices. // class of devices.
$mobile = new \uagent_info(); return $this->detector->DetectMobileLong();
return $mobile->DetectMobileLong();
} }
/** /**
......
<?php
/**
* Mobile Test Class
*
* PHP version 5
*
* Copyright (C) Villanova University 2010.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @category VuFind2
* @package Tests
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/vufind2:unit_tests Wiki
*/
namespace VuFindTest;
use VuFindTheme\Mobile;
/**
* Mobile Test Class
*
* @category VuFind2
* @package Tests
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/vufind2:unit_tests Wiki
*/
class ThemeMobileTest extends Unit\TestCase
{
/**
* Test namespace stripping.
*
* @return void
*/
public function testEnable()
{
$mobile = new Mobile();
// default behavior
$this->assertFalse($mobile->enabled());
// turn on
$mobile->enable();
$this->assertTrue($mobile->enabled());
// turn off
$mobile->enable(false);
$this->assertFalse($mobile->enabled());
}
/**
* Test detection wrapping.
*
* @return void
*/
public function testDetection()
{
$detector = $this->getMock('uagent_info', array('DetectMobileLong'));
$detector->expects($this->once())
->method('DetectMobileLong')->will($this->returnValue(true));
$mobile = new Mobile($detector);
$this->assertTrue($mobile->detect());
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment