Skip to content

Commit

Permalink
MDL-43679 core: Handle Meridio user agents with MS Word
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed Jan 2, 2015
1 parent 0bbddb0 commit 848e0ce
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/classes/useragent.php
Expand Up @@ -818,11 +818,12 @@ public static function is_msword() {
$useragent = self::get_user_agent_string();
if (!preg_match('/(\bWord\b|ms-office|MSOffice|Microsoft Office)/i', $useragent)) {
return false;
}
if (strpos($useragent, 'Outlook') !== false) {
} else if (strpos($useragent, 'Outlook') !== false) {
return false;
} else if (strpos($useragent, 'Meridio') !== false) {
return false;
}
// It's Office and not Outlook - so it's probably Word, but we can't really be sure in most cases.
// It's Office, not Outlook and not Meridio - so it's probably Word, but we can't really be sure in most cases.
return true;
}

Expand Down
28 changes: 28 additions & 0 deletions lib/tests/useragent_test.php
Expand Up @@ -49,6 +49,9 @@ class core_useragent_testcase extends basic_testcase {
'7.0' => array(
'Windows XP SP2' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; YPC 3.0.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)'
),
'7.0b' => array(
'Windows XP' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Meridio for Excel 5.0.251; Meridio for PowerPoint 5.0.251; Meridio for Word 5.0.251; Meridio Protocol; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)'
),
'8.0' => array(
'Windows Vista' => 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648)'
),
Expand Down Expand Up @@ -167,6 +170,11 @@ class core_useragent_testcase extends basic_testcase {
'2010' => array(
'Windows 7' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; Microsoft Outlook 14.0.7113; ms-office; MSOffice 14)'
)
),
'Meridio' => array(
'5.0.251' => array(
'Windows XP' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Meridio for Excel 5.0.251; Meridio for PowerPoint 5.0.251; Meridio for Word 5.0.251; Meridio Protocol; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)'
)
)
);

Expand Down Expand Up @@ -274,6 +282,22 @@ public function test_check_browser_version() {
$this->assertFalse(core_useragent::check_ie_version('7.0'));
$this->assertFalse(core_useragent::is_msword());

core_useragent::instance(true, $this->user_agents['MSIE']['7.0']['Windows XP SP2']);
$this->assertTrue(core_useragent::is_ie());
$this->assertTrue(core_useragent::check_ie_version());
$this->assertTrue(core_useragent::check_ie_version('7.0'));
$this->assertFalse(core_useragent::check_ie_compatibility_view());
$this->assertFalse(core_useragent::check_ie_version('8.0'));
$this->assertFalse(core_useragent::is_msword());

core_useragent::instance(true, $this->user_agents['MSIE']['7.0b']['Windows XP']);
$this->assertTrue(core_useragent::is_ie());
$this->assertTrue(core_useragent::check_ie_version());
$this->assertTrue(core_useragent::check_ie_version('7.0'));
$this->assertFalse(core_useragent::check_ie_compatibility_view());
$this->assertFalse(core_useragent::check_ie_version('8.0'));
$this->assertFalse(core_useragent::is_msword());

core_useragent::instance(true, $this->user_agents['MSIE']['9.0']['Windows 7']);
$this->assertTrue(core_useragent::is_ie());
$this->assertTrue(core_useragent::check_ie_version());
Expand Down Expand Up @@ -478,6 +502,10 @@ public function test_check_browser_version() {
// Outlook should not be considered to be MS Word.
core_useragent::instance(true, $this->user_agents['MS Outlook']['2010']['Windows 7']);
$this->assertFalse(core_useragent::is_msword());

// Meridio should not be considered to be MS Word.
core_useragent::instance(true, $this->user_agents['Meridio']['5.0.251']['Windows XP']);
$this->assertFalse(core_useragent::is_msword());
}

/**
Expand Down

0 comments on commit 848e0ce

Please sign in to comment.