Skip to content

Commit

Permalink
fixed ssl method
Browse files Browse the repository at this point in the history
  • Loading branch information
webuilder240 committed Jul 26, 2015
1 parent ae5666a commit 38c1f95
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
vendor/
.idea/
.idea/
35 changes: 22 additions & 13 deletions src/Is.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ class Is
* @var array
*/
private $_SERVER;
private $same_name;

/**
* set $_SERVER
* set $_SERVER,$php_same_name
*/
public function __construct()
{
$this->_SERVER = $_SERVER;
$this->same_name = php_sapi_name();
}

/**
* テスト用にSet出来るようにしている。
* 本当はsetできない方向にしたいが、
* 本当はsetできない方向にしたい
*
* for unit test
*/
public function set_SERVER($key,$value)
{
Expand All @@ -37,6 +41,17 @@ public function set_SERVER($key,$value)
}
}

/**
* テスト用にSet出来るようにしている。
* 本当はsetできない方向にしたい
*
* for unit test
*/
public function set_php_same_name($value)
{
$this->php_same_name = $value;
}

/**
* @return $this
*/
Expand Down Expand Up @@ -114,8 +129,8 @@ private function _check_server_software($soft_name)
*/
public function ssl()
{
if (isset($this->_SERVER['HTTPS'])) {
if ($this->_SERVER['HTTPS'] === 'on') {
if (isset($this->_SERVER['HTTPS']) && isset($this->_SERVER['HTTP_HTTPS'])) {
if ($this->_SERVER['HTTPS'] === 'on' || $this->_SERVER['HTTP_HTTPS'] === '1') {
return $this->_return_result(true);
}
}
Expand All @@ -138,14 +153,6 @@ public function cli()
return $this->_check_sapi_name('cli');
}

/**
* @return bool
*/
public function fpm()
{
return $this->_check_sapi_name('fpm-fcgi');
}

/**
* @return bool
*/
Expand Down Expand Up @@ -195,7 +202,7 @@ public function mobile()
*/
public function tablet()
{
$ua = mb_strtolower($_SERVER['HTTP_USER_AGENT']);
$ua = mb_strtolower($this->_SERVER['HTTP_USER_AGENT']);
$tablet_lists = [
'ipad',
'android',
Expand Down Expand Up @@ -239,6 +246,8 @@ public function tablet()
return $this->_return_result(true);
}
}

return $this->_return_result(false);
}

/**
Expand Down
61 changes: 31 additions & 30 deletions test/IsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@ public function testSsl()
$this->assertFalse($this->is->ssl());
$this->assertTrue($this->is->not()->ssl());

//emulated chrome set always set https : 1
$this->is->set_SERVER('HTTPS','1');
$this->assertFalse($this->is->ssl());
$this->assertTrue($this->is->not()->ssl());

// emulated ssl
$this->is->set_SERVER('HTTPS','on');
$this->is->set_SERVER('HTTP_HTTPS','1');
$this->assertTrue($this->is->ssl());
$this->assertFalse($this->is->not()->ssl());

}

public function testApache()
Expand All @@ -50,7 +58,6 @@ public function testApache()
$this->assertTrue($this->is->not()->apache());

$this->is->set_SERVER('SERVER_SOFTWARE','Apache Version: 2.2.10 (Unix)');

$this->assertTrue($this->is->apache());
$this->assertFalse($this->is->not()->apache());
}
Expand All @@ -61,7 +68,6 @@ public function testBuildInServer()
$this->assertTrue($this->is->not()->build_in_server());

$this->is->set_SERVER('SERVER_SOFTWARE','PHP 5.6.11 Development Server');

$this->assertTrue($this->is->build_in_server());
$this->assertFalse($this->is->not()->build_in_server());
}
Expand Down Expand Up @@ -136,33 +142,6 @@ public function testRequestDELETE()
$this->assertTrue($this->is->not()->request_delete());
}

// public function testRunUnit()
// {
// $this->assertTrue($this->is->run_unit());
// $this->assertFalse($this->is->not()->run_unit());
//
// $this->is->set_SERVER('REQUEST_METHOD','GET');
//
// $_SERVER['argv'][0] = "";
// $this->assertFalse($this->is->run_unit());
// $this->assertTrue($this->is->not()->run_unit());
//
// $_SERVER['argv'][0] = "vendor/bin/phpspec";
// $this->assertFalse($this->is->run_unit());
// $this->assertTrue($this->is->not()->run_unit());
// }
//
// public function testRunSpec()
// {
// $_SERVER['argv'][0] = "vendor/bin/phpspec";
// $this->assertTrue($this->is->run_spec());
// $this->assertFalse($this->is->not()->run_spec());
//
// $_SERVER['argv'][0] = "vendor/bin/phpunit";
// $this->assertFalse($this->is->run_spec());
// $this->assertTrue($this->is->not()->run_spec());
// }

public function testEmail()
{
$this->assertTrue($this->is->email('[email protected]'));
Expand Down Expand Up @@ -278,5 +257,27 @@ public function testMobile()
}

public function testTablet()
{}
{
// Android Tablet
$this->is->set_SERVER('HTTP_USER_AGENT',
'Mozilla/5.0 (Linux; Android 5.1.1; Nexus 7 Build/LMY48G) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.93 Safari/537.36');
$this->assertTrue($this->is->tablet());

// Android Mobile
$this->is->set_SERVER('HTTP_USER_AGENT',
'Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LMY47Z) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.93 Mobile Safari/537.36');
$this->assertFalse($this->is->tablet());
$this->assertTrue($this->is->not()->tablet());

// iPad
$this->is->set_SERVER('HTTP_USER_AGENT',
'Mozilla/5.0 (iPad; CPU OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53');
$this->assertTrue($this->is->tablet());

//iPhone
$this->is->set_SERVER('HTTP_USER_AGENT',
'Mozilla/5.0 (iPhone; CPU iPhone OS 8_4 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12H143 Safari/600.1.4');
$this->assertFalse($this->is->tablet());
$this->assertTrue($this->is->not()->tablet());
}
}

0 comments on commit 38c1f95

Please sign in to comment.