Source of file MobileSiteControllerExtensionTest.php
Size: 10,307 Bytes - Last Modified: 2021-12-23T10:33:12+00:00
/var/www/docs.ssmods.com/process/src/tests/MobileSiteControllerExtensionTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 | <?php /** * @package mobile * @subpackage tests */ class MobileSiteControllerExtensionTest extends FunctionalTest { public static $fixture_file = 'mobile/tests/MobileSiteControllerExtensionTest.yml'; public static $use_draft_site = true; protected static $originalUserAgent; protected static $originalHost; protected static $originalAccept; protected $autoFollowRedirection = false; public function setUp() { parent::setUp(); if(!self::$originalUserAgent) self::$originalUserAgent = $_SERVER['HTTP_USER_AGENT']; if(!self::$originalHost) self::$originalHost = $_SERVER['HTTP_HOST']; if(!self::$originalAccept) self::$originalAccept = $_SERVER['HTTP_ACCEPT']; } public function tearDown() { parent::tearDown(); $_SERVER['HTTP_USER_AGENT'] = self::$originalUserAgent; $_SERVER['HTTP_HOST'] = self::$originalHost; $_SERVER['HTTP_ACCEPT'] = self::$originalAccept; } public function testFullSiteLink() { $page = $this->objFromFixture('Page', 'page'); $controller = new ContentController($page); $this->assertTrue(strpos($controller->FullSiteLink(), 'page/?fullSite=1') !== false); } public function testRedirectToMobileSite() { $page = $this->objFromFixture('Page', 'page'); $config = SiteConfig::current_site_config(); $config->MobileSiteType = 'RedirectToDomain'; $config->write(); // Test common mobile agent strings foreach(array( 'Mozilla/5.0 (iPod; U; CPU iPhone OS 2_0 like Mac OS X; de-de) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5A347 Safari/525.20', 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7D11 Safari/528.16', 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3', 'Mozilla/5.0 (Linux; U; Android 2.1-update1; en-us; ADR6300 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17', 'iPod', 'iPhone', 'Android', 'palm os', 'hiptop', 'avantgo', 'iemobile', '502i', '3gso', '6310', 'windows ce; ppc;', 'Stuff; iPhone; Version details here', 'Stuff here; Android; Version details here', 'Opera/9.50 (J2ME/MIDP; Opera Mini/4.0.10031/298; U; en)', 'Opera/8.0.1 (J2ME/MIDP; Opera Mini/3.1.9427/1724; en; U; ssr)', 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, Like Gecko) Version/6.0.0.141 Mobile Safari/534.1+' ) as $agent) { $_SERVER['HTTP_USER_AGENT'] = $agent; $response = $this->get($page->URLSegment); $headers = $response->getHeaders(); $this->assertEquals(301, $response->getStatusCode()); $this->assertEquals('http://m.' . $_SERVER['HTTP_HOST'], $headers['Location']); } } public function testRedirectToMobileFromAcceptSetting() { $page = $this->objFromFixture('Page', 'page'); $config = SiteConfig::current_site_config(); $config->MobileSiteType = 'RedirectToDomain'; $config->write(); $_SERVER['HTTP_ACCEPT'] = 'text/vnd.wap.wml'; $response = $this->get($page->URLSegment); $headers = $response->getHeaders(); $this->assertEquals(301, $response->getStatusCode()); $this->assertEquals('http://m.' . $_SERVER['HTTP_HOST'], $headers['Location']); } public function testRedirectToMobileFromWAPProfile() { $page = $this->objFromFixture('Page', 'page'); $config = SiteConfig::current_site_config(); $config->MobileSiteType = 'RedirectToDomain'; $config->write(); $_SERVER['HTTP_X_WAP_PROFILE'] = 1; $response = $this->get($page->URLSegment); $headers = $response->getHeaders(); $this->assertEquals(301, $response->getStatusCode()); $this->assertEquals('http://m.' . $_SERVER['HTTP_HOST'], $headers['Location']); unset($_SERVER['HTTP_X_WAP_PROFILE']); } public function testNoRedirectToMobile() { $config = SiteConfig::current_site_config(); $config->MobileSiteType = 'MobileThemeOnly'; $config->write(); $page = $this->objFromFixture('Page', 'page'); $_SERVER['HTTP_USER_AGENT'] = 'iPhone'; $response = $this->get($page->URLSegment); $headers = $response->getHeaders(); $this->assertEquals(200, $response->getStatusCode()); } public function testRedirectToFullSiteFromMobile() { $config = SiteConfig::current_site_config(); $config->MobileSiteType = 'RedirectToDomain'; $config->write(); $page = $this->objFromFixture('Page', 'page'); $_SERVER['HTTP_HOST'] = 'm.' . $_SERVER['HTTP_HOST']; $response = $this->get($page->URLSegment . '?fullSite=1', null, null, array('fullSite' => 1)); $headers = $response->getHeaders(); $this->assertEquals(301, $response->getStatusCode()); $this->assertEquals($config->FullSiteDomainNormalized, $headers['Location']); } public function testRedirectToMobileSiteFromDesktop() { $config = SiteConfig::current_site_config(); $config->MobileSiteType = 'RedirectToDomain'; $config->write(); $page = $this->objFromFixture('Page', 'page'); $response = $this->get($page->URLSegment . '?fullSite=0', null, null, array('fullSite' => 0)); $headers = $response->getHeaders(); $this->assertEquals(301, $response->getStatusCode()); $this->assertEquals($config->MobileDomainNormalized, $headers['Location']); } public function testNoMobileRedirectWhenFullSiteSessionSetOnMobile() { $_SERVER['HTTP_USER_AGENT'] = 'Android'; $config = SiteConfig::current_site_config(); $config->MobileSiteType = 'RedirectToDomain'; $config->write(); $page = $this->objFromFixture('Page', 'page'); $response = $this->get($page->URLSegment, null, null, array('fullSite' => 1)); $headers = $response->getHeaders(); $this->assertEquals(200, $response->getStatusCode()); } public function testOnMobileSite() { $_SERVER['HTTP_HOST'] = str_replace('m.', '', $_SERVER['HTTP_HOST']); $controller = new ContentController(); $this->assertFalse($controller->onMobileDomain()); $_SERVER['HTTP_HOST'] = 'm.' . $_SERVER['HTTP_HOST']; $this->assertTrue($controller->onMobileDomain()); } public function testOnMobileSiteMultipleDomains() { $config = SiteConfig::current_site_config(); $config->FullSiteDomain = 'domain1.com,domain2.com'; $config->MobileDomain = 'm.domain1.com,m.domain2.com'; $config->write(); $_SERVER['HTTP_HOST'] = 'domain1.com'; $controller = new ContentController(); $this->assertFalse($controller->onMobileDomain()); $_SERVER['HTTP_HOST'] = 'm.domain1.com'; $this->assertTrue($controller->onMobileDomain()); $_SERVER['HTTP_HOST'] = 'm.domain2.com'; $this->assertTrue($controller->onMobileDomain()); } public function testDirectlyAccessingMobileSiteOnAnyDevice() { $_SERVER['HTTP_USER_AGENT'] = 'anything can be here'; $_SERVER['HTTP_HOST'] = 'm.' . $_SERVER['HTTP_HOST']; $page = $this->objFromFixture('Page', 'page'); $response = $this->get($page->URLSegment); $headers = $response->getHeaders(); $this->assertEquals(200, $response->getStatusCode()); } public function testIsiPhone() { $controller = new ContentController(); $_SERVER['HTTP_USER_AGENT'] = 'something else'; $this->assertFalse($controller->IsiPhone()); $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPod; U; CPU iPhone OS 2_0 like Mac OS X; de-de) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5A347 Safari/525.20'; $this->assertTrue($controller->IsiPhone()); $_SERVER['HTTP_USER_AGENT'] = 'Something here; iPhone; Probably something else here'; $this->assertTrue($controller->IsiPhone()); } public function testIsAndroid() { $controller = new ContentController(); $_SERVER['HTTP_USER_AGENT'] = 'something else'; $this->assertFalse($controller->IsAndroid()); $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Linux; U; Android 2.1-update1; en-us; ADR6300 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17'; $this->assertTrue($controller->IsAndroid()); $_SERVER['HTTP_USER_AGENT'] = 'Something here; Android; Probably something else here'; $this->assertTrue($controller->IsAndroid()); } public function testIsOperaMini() { $controller = new ContentController(); $_SERVER['HTTP_USER_AGENT'] = 'something else'; $this->assertFalse($controller->IsOperaMini()); $_SERVER['HTTP_USER_AGENT'] = 'Opera/9.50 (J2ME/MIDP; Opera Mini/4.0.10031/298; U; en)'; $this->assertTrue($controller->IsOperaMini()); $_SERVER['HTTP_USER_AGENT'] = 'Something here; Opera Mini; Probably something else here'; $this->assertTrue($controller->IsOperaMini()); } public function testIsBlackBerry() { $controller = new ContentController(); $_SERVER['HTTP_USER_AGENT'] = 'something else'; $this->assertFalse($controller->IsBlackBerry()); $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, Like Gecko) Version/6.0.0.141 Mobile Safari/534.1+'; $this->assertTrue($controller->IsBlackBerry()); $_SERVER['HTTP_USER_AGENT'] = 'Something here; BlackBerry; Probably something else here'; $this->assertTrue($controller->IsBlackBerry()); } public function testIsMobile() { $page = $this->objFromFixture('Page', 'page'); $config = SiteConfig::current_site_config(); // Immobile device $_SERVER['HTTP_USER_AGENT'] = 'immobile browser'; $response = $this->get($page->URLSegment); $this->assertFalse(MobileSiteControllerExtension::is_mobile()); // Force mobile site $_SERVER['HTTP_USER_AGENT'] = 'immobile browser'; $response = $this->get($page->URLSegment.'?fullSite=0'); $this->assertTrue(MobileSiteControllerExtension::is_mobile()); $config->MobileSiteType = 'MobileThemeOnly'; $config->write(); // Mobile device $_SERVER['HTTP_USER_AGENT'] = 'iPhone'; $response = $this->get($page->URLSegment); $this->assertTrue(MobileSiteControllerExtension::is_mobile()); // Force full site $_SERVER['HTTP_USER_AGENT'] = 'iPhone'; $response = $this->get($page->URLSegment.'?fullSite=1'); $this->assertFalse(MobileSiteControllerExtension::is_mobile()); $config->MobileSiteType = 'RedirectToDomain'; $config->write(); // Mobile domain $_SERVER['HTTP_USER_AGENT'] = 'anything can be here'; $_SERVER['HTTP_HOST'] = 'm.' . $_SERVER['HTTP_HOST']; $page = $this->objFromFixture('Page', 'page'); $response = $this->get($page->URLSegment); $this->assertTrue(MobileSiteControllerExtension::is_mobile()); } } |