blob: e3726554eff9718a76b6438b6136d7343284228e [file] [log] [blame]
Greg Aker9512ab82011-04-21 15:10:48 -05001<?php
2
Taufan Adityaac5373a2012-03-28 16:03:38 +07003class UserAgent_test extends CI_TestCase {
Andrey Andreevc1862882012-06-09 23:16:58 +03004
Greg Aker9512ab82011-04-21 15:10:48 -05005 protected $_user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27';
6 protected $_mobile_ua = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7';
Eric Barnes051a3172011-11-27 00:49:25 -05007
Eric Barnes68286a42011-04-21 22:00:33 -04008 public function set_up()
Greg Aker9512ab82011-04-21 15:10:48 -05009 {
10 // set a baseline user agent
11 $_SERVER['HTTP_USER_AGENT'] = $this->_user_agent;
Eric Barnes051a3172011-11-27 00:49:25 -050012
dchill427ecc5cd2012-10-12 16:25:51 -040013 $this->ci_vfs_clone('application/config/user_agents.php');
Eric Barnes051a3172011-11-27 00:49:25 -050014
dchill427ecc5cd2012-10-12 16:25:51 -040015 $this->agent = new Mock_Libraries_UserAgent();
Eric Barnes051a3172011-11-27 00:49:25 -050016
dchill427ecc5cd2012-10-12 16:25:51 -040017 $this->ci_instance_var('agent', $this->agent);
Greg Aker9512ab82011-04-21 15:10:48 -050018 }
19
20 // --------------------------------------------------------------------
21
Eric Barnes68286a42011-04-21 22:00:33 -040022 public function test_accept_lang()
Greg Aker9512ab82011-04-21 15:10:48 -050023 {
24 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en';
Eric Barnes051a3172011-11-27 00:49:25 -050025 $this->assertTrue($this->agent->accept_lang());
Greg Aker9512ab82011-04-21 15:10:48 -050026 unset($_SERVER['HTTP_ACCEPT_LANGUAGE']);
Eric Barnes051a3172011-11-27 00:49:25 -050027 $this->assertTrue($this->agent->accept_lang('en'));
28 $this->assertFalse($this->agent->accept_lang('fr'));
Greg Aker9512ab82011-04-21 15:10:48 -050029 }
30
31 // --------------------------------------------------------------------
32
Eric Barnes68286a42011-04-21 22:00:33 -040033 public function test_mobile()
Greg Aker9512ab82011-04-21 15:10:48 -050034 {
35 // Mobile Not Set
36 $_SERVER['HTTP_USER_AGENT'] = $this->_mobile_ua;
37 $this->assertEquals('', $this->agent->mobile());
38 unset($_SERVER['HTTP_USER_AGENT']);
39 }
40
41 // --------------------------------------------------------------------
42
Eric Barnes68286a42011-04-21 22:00:33 -040043 public function test_util_is_functions()
Greg Aker9512ab82011-04-21 15:10:48 -050044 {
45 $this->assertTrue($this->agent->is_browser());
46 $this->assertFalse($this->agent->is_robot());
47 $this->assertFalse($this->agent->is_mobile());
48 $this->assertFalse($this->agent->is_referral());
49 }
50
51 // --------------------------------------------------------------------
52
Eric Barnes68286a42011-04-21 22:00:33 -040053 public function test_agent_string()
Greg Aker9512ab82011-04-21 15:10:48 -050054 {
55 $this->assertEquals($this->_user_agent, $this->agent->agent_string());
56 }
57
58 // --------------------------------------------------------------------
59
Eric Barnes68286a42011-04-21 22:00:33 -040060 public function test_browser_info()
Greg Aker9512ab82011-04-21 15:10:48 -050061 {
62 $this->assertEquals('Mac OS X', $this->agent->platform());
63 $this->assertEquals('Safari', $this->agent->browser());
64 $this->assertEquals('533.20.27', $this->agent->version());
65 $this->assertEquals('', $this->agent->robot());
66 $this->assertEquals('', $this->agent->referrer());
67 }
Eric Barnes051a3172011-11-27 00:49:25 -050068
Greg Aker9512ab82011-04-21 15:10:48 -050069 // --------------------------------------------------------------------
70
Eric Barnes68286a42011-04-21 22:00:33 -040071 public function test_charsets()
Greg Aker9512ab82011-04-21 15:10:48 -050072 {
73 $_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf8';
Eric Barnes051a3172011-11-27 00:49:25 -050074
Greg Aker9512ab82011-04-21 15:10:48 -050075 $charsets = $this->agent->charsets();
Eric Barnes051a3172011-11-27 00:49:25 -050076
Greg Aker9512ab82011-04-21 15:10:48 -050077 $this->assertEquals('utf8', $charsets[0]);
Eric Barnes051a3172011-11-27 00:49:25 -050078
Greg Aker9512ab82011-04-21 15:10:48 -050079 unset($_SERVER['HTTP_ACCEPT_CHARSET']);
Eric Barnes051a3172011-11-27 00:49:25 -050080
Greg Aker9512ab82011-04-21 15:10:48 -050081 $this->assertFalse($this->agent->accept_charset());
82 }
83
Greg Aker9512ab82011-04-21 15:10:48 -050084}