agent.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. /**
  3. * Part of the Fuel framework.
  4. *
  5. * @package Fuel
  6. * @version 1.5
  7. * @author Fuel Development Team
  8. * @license MIT License
  9. * @copyright 2010 - 2013 Fuel Development Team
  10. * @link http://fuelphp.com
  11. */
  12. namespace Fuel\Core;
  13. /**
  14. * Agent class tests
  15. *
  16. * @group Core
  17. * @group Agent
  18. */
  19. class Test_Agent extends TestCase
  20. {
  21. /**
  22. * need to setup a fake browser environment
  23. */
  24. protected function setUp()
  25. {
  26. $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-us,en;q=0.8,nl-be;q=0.5,nl;q=0.3';
  27. $_SERVER['HTTP_ACCEPT_CHARSET'] = 'UTF-8,ISO-8859-1,*';
  28. $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.16) Gecko/20110322 Fedora/3.6.16-1.fc14 Firefox/3.6.16';
  29. }
  30. /**
  31. * Tests Agent::browser()
  32. *
  33. * @test
  34. */
  35. public function test_browser()
  36. {
  37. $expected = "Firefox";
  38. $output = Agent::browser();
  39. $this->assertEquals($expected, $output);
  40. }
  41. /**
  42. * Tests Agent::platform()
  43. *
  44. * @test
  45. */
  46. public function test_platform()
  47. {
  48. $expected = "Linux";
  49. $output = Agent::platform();
  50. $this->assertEquals($expected, $output);
  51. }
  52. /**
  53. * Tests Agent::version()
  54. *
  55. * @test
  56. */
  57. public function test_version()
  58. {
  59. $expected = 3.6;
  60. $output = Agent::version();
  61. $this->assertInternalType('float', $output);
  62. $this->assertEquals($expected, $output);
  63. }
  64. public function property_provider()
  65. {
  66. return array(
  67. array(
  68. 'Browser','Firefox',
  69. ),
  70. array(
  71. 'Version',3.6,
  72. ),
  73. array(
  74. 'MajorVer',3,
  75. ),
  76. array(
  77. 'MinorVer',6,
  78. ),
  79. array(
  80. 'Platform','Linux',
  81. ),
  82. array(
  83. 'Alpha',false,
  84. ),
  85. array(
  86. 'Beta',false,
  87. ),
  88. array(
  89. 'Win16',false,
  90. ),
  91. array(
  92. 'Win32',false,
  93. ),
  94. array(
  95. 'Win64',false,
  96. ),
  97. array(
  98. 'Frames',true,
  99. ),
  100. array(
  101. 'IFrames',true,
  102. ),
  103. array(
  104. 'Tables',true,
  105. ),
  106. array(
  107. 'Cookies',true,
  108. ),
  109. array(
  110. 'BackgroundSounds',false,
  111. ),
  112. array(
  113. 'JavaScript',true,
  114. ),
  115. array(
  116. 'VBScript',false,
  117. ),
  118. array(
  119. 'JavaApplets',true,
  120. ),
  121. array(
  122. 'ActiveXControls',false,
  123. ),
  124. array(
  125. 'isBanned',false,
  126. ),
  127. array(
  128. 'isMobile',false,
  129. ),
  130. array(
  131. 'isSyndicationReader',false,
  132. ),
  133. array(
  134. 'Crawler',false,
  135. ),
  136. array(
  137. 'CssVersion',3,
  138. ),
  139. array(
  140. 'AolVersion',0,
  141. ),
  142. );
  143. }
  144. /**
  145. * Tests Agent::property()
  146. *
  147. * @test
  148. * @dataProvider property_provider
  149. */
  150. public function test_property($property, $expected)
  151. {
  152. $output = Agent::property($property);
  153. $this->assertEquals($expected, $output);
  154. }
  155. /**
  156. * Tests Agent::is_robot()
  157. *
  158. * @test
  159. */
  160. public function test_is_robot()
  161. {
  162. $output = Agent::is_robot();
  163. $this->assertFalse($output);
  164. }
  165. /**
  166. * Tests Agent::is_mobiledevice()
  167. *
  168. * @test
  169. */
  170. public function test_is_mobiledevice()
  171. {
  172. $output = Agent::is_mobiledevice();
  173. $this->assertFalse($output);
  174. }
  175. /**
  176. * Tests Agent::languages()
  177. *
  178. * @test
  179. */
  180. public function test_languages()
  181. {
  182. $expected = array("en-us", "en", "nl-be", "nl");
  183. $output = Agent::languages();
  184. $this->assertEquals($expected, $output);
  185. }
  186. /**
  187. * Tests Agent::accepts_language()
  188. *
  189. * @test
  190. */
  191. public function test_accepts_language_success()
  192. {
  193. $output = Agent::accepts_language('en-us');
  194. $this->assertTrue($output);
  195. }
  196. public function test_accepts_language_fail()
  197. {
  198. $output = Agent::accepts_language('pt-br');
  199. $this->assertFalse($output);
  200. }
  201. /**
  202. * Tests Agent::charsets()
  203. *
  204. * @test
  205. */
  206. public function test_charsets()
  207. {
  208. $expected = array("utf-8", "iso-8859-1", "*");
  209. $output = Agent::charsets();
  210. $this->assertEquals($expected, $output);
  211. }
  212. /**
  213. * Tests Agent::accepts_charset()
  214. *
  215. * @test
  216. */
  217. public function test_accepts_charset_success()
  218. {
  219. $output = Agent::accepts_charset('utf-8');
  220. $this->assertTrue($output);
  221. }
  222. public function test_accepts_charset_fail()
  223. {
  224. $output = Agent::accepts_charset('cp2');
  225. $this->assertFalse($output);
  226. }
  227. }