diff --git a/.gitignore b/.gitignore index 85e7c1d..43b847e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ -/.idea/ +/vendor/ +/silverstripe-cache/ +/resources/ +/composer.lock +/assets/ diff --git a/.travis.yml b/.travis.yml index 6437f84..c214d5a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,27 +7,24 @@ dist: precise language: php php: - - 5.3 - - 5.4 - - 5.5 - 5.6 - 7.0 - 7.1 + - 7.2 + - 7.3 env: - - DB=MYSQL CORE_RELEASE=3.6 + - DB=MYSQL CORE_RELEASE=4.4 matrix: include: - php: 7.1 - env: DB=MYSQL CORE_RELEASE=3 + env: DB=MYSQL CORE_RELEASE=4.5 - php: 5.6 - env: DB=PGSQL CORE_RELEASE=3.5 + env: DB=PGSQL CORE_RELEASE=4.4 before_script: - composer self-update || true - - git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support - - php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss - - cd ~/builds/ss + - composer install --prefer-source --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile script: - - vendor/bin/phpunit masquerade/tests + - vendor/bin/phpunit tests diff --git a/composer.json b/composer.json index 19dc869..1a0e227 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,11 @@ "DHensby\\SilverStripeMasquerade\\": "src/" } }, + "autoload-dev": { + "psr-4": { + "DHensby\\SilverStripeMasquerade\\Test\\": "tests/" + } + }, "license": "ISC", "authors": [ { diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..be60684 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,18 @@ + + + + + tests/php + + + + src/ + + tests/php/ + + + + diff --git a/tests/MasqueradeMemberTest.php b/tests/MasqueradeMemberTest.php index 7c2d199..f11fcff 100644 --- a/tests/MasqueradeMemberTest.php +++ b/tests/MasqueradeMemberTest.php @@ -1,5 +1,11 @@ logInWithPermission('ADMIN'); - $admin = Member::currentUser(); + $admin = Security::getCurrentUser(); $member = $this->objFromFixture('Member', 'user'); //added function correctly @@ -30,7 +36,7 @@ public function testCanMasquerade() // member cannot masquerade as themeselves $this->assertFalse($member->canMasquerade($member)); - $member->logIn(); + Security::setCurrentUser($member); // member can't masquerade as themselves $this->assertFalse($member->canMasquerade()); @@ -41,15 +47,17 @@ public function testCanMasquerade() public function testMasquerade() { $this->logInWithPermission('ADMIN'); - $admin = Member::currentUser(); + $admin = Security::getCurrentUser(); $member = $this->objFromFixture('Member', 'user'); - $this->assertEquals($admin->ID, Session::get('loggedInAs')); + $session = Controller::curr()->getRequest()->getSession(); + + $this->assertEquals($admin->ID, $session->get('loggedInAs')); $member->masquerade(); - $this->assertEquals($member->ID, Session::get('loggedInAs')); - $this->assertEquals($admin->ID, Session::get('Masquerade.Old.loggedInAs')); + $this->assertEquals($member->ID, $session->get('loggedInAs')); + $this->assertEquals($admin->ID, $session->get('masqueradingAs')); } } diff --git a/tests/MasqueradeSecurityControllerTest.php b/tests/MasqueradeSecurityControllerTest.php index 188f000..14742bb 100644 --- a/tests/MasqueradeSecurityControllerTest.php +++ b/tests/MasqueradeSecurityControllerTest.php @@ -1,5 +1,11 @@ logInWithPermission('ADMIN'); - $admin = Member::currentUser(); + $admin = Security::getCurrentUser(); $member = $this->objFromFixture('Member', 'user'); $member->masquerade(); - $this->assertEquals($member->ID, Session::get('loggedInAs')); + $this->assertEquals($member->ID, Security::getCurrentUser()->ID); $sc = new MasqueradeSecurityController(); //$sc->init(); $sc->logout(false);