Skip to content

Commit

Permalink
Add UnitTest
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess committed Apr 24, 2020
1 parent 063fbd3 commit 33f339e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ before_script:

script: # PHP7 + precise のテストは実行されない
- if [[ $PHP_SAPI = 'phpdbg' ]] && [[ $CODENAME = 'trusty' ]]; then phpdbg -qrr ./vendor/bin/phpunit --coverage-clover=coverage.clover ; fi
- if [[ $PHP_SAPI != 'phpdbg' ]]; then ./vendor/bin/phpunit ; fi

# - if [[ $PHP_SAPI != 'phpdbg' ]]; then ./vendor/bin/phpunit ; fi
- 'sed -i -e "s|force_ssl:\(.*\)|force_ssl: 1|" app/config/eccube/config.yml' # force_ssl を有効にしてテスト
- if [[ $PHP_SAPI != 'phpdbg' ]]; then ./vendor/bin/phpunit tests/Eccube/Tests/Web/SameSiteCookieTest.php ; fi
after_script:
- if [[ $PHP_SAPI = 'phpdbg' ]]; then wget https://scrutinizer-ci.com/ocular.phar ; fi
- if [[ $PHP_SAPI = 'phpdbg' ]]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover ; fi
Expand Down
47 changes: 47 additions & 0 deletions tests/Eccube/Tests/Web/SameSiteCookieTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Eccube\Tests\Web;

class SameSiteCookieTest extends AbstractWebTestCase
{
public function setUp()
{
// parent::setUp() は, 各テストメソッドで行う
}

public function provideSession()
{
return array(
array('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130', true),
array('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Safari/605.1.15', false),
array('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15', true),
array('Mozilla/5.0 (iPhone; CPU iPhone OS 12_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 EdgiOS/44.8.0 Mobile/15E148 Safari/605.1.15', false),
array('Mozilla/5.0 (iPhone; CPU iPhone OS 13_1_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.1 Mobile/15E148 Safari/604.1', true)
);
}

/**
* @dataProvider provideSession
*/
public function testSessionParams($userAgent, $shouldSendSameSiteNone)
{
$_SERVER['HTTP_USER_AGENT'] = $userAgent;
parent::setUp();
if (!$this->app['config']['force_ssl']) {
$this->markTestSkipped('force_ssl required');
}
$this->client->request('GET', $this->app['url_generator']->generate('homepage'));
$this->assertTrue($this->client->getResponse()->isSuccessful());
$cookieParams = session_get_cookie_params();
if ($shouldSendSameSiteNone) {
if (PHP_VERSION_ID >= 70300) {
$this->assertEquals('/', $cookieParams['path']);
$this->assertEquals('none', $cookieParams['samesite']);
} else {
$this->assertEquals('/; SameSite=none', $cookieParams['path']);
}
} else {
$this->assertEquals('/', $cookieParams['path']);
}
}
}

0 comments on commit 33f339e

Please sign in to comment.