Skip to content

Commit

Permalink
Update test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensby committed Mar 29, 2020
1 parent bb25cc1 commit 51367fe
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 19 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/.idea/
/vendor/
/silverstripe-cache/
/resources/
/composer.lock
/assets/
17 changes: 7 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"DHensby\\SilverStripeMasquerade\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"DHensby\\SilverStripeMasquerade\\Test\\": "tests/"
}
},
"license": "ISC",
"authors": [
{
Expand Down
18 changes: 18 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Standard module phpunit configuration.
Requires PHPUnit ^5.7
-->
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
<testsuite name="Default">
<directory>tests/php</directory>
</testsuite>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
<exclude>
<directory suffix=".php">tests/php/</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
20 changes: 14 additions & 6 deletions tests/MasqueradeMemberTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<?php

namespace DHensby\SilverStripeMasquerade\Test;

use SilverStripe\Control\Controller;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Security\Security;

class MasqueradeMemberTest extends SapphireTest {

protected static $fixture_file = 'MasqueradeMemberTest.yml';

public function testCanMasquerade()
{
$this->logInWithPermission('ADMIN');
$admin = Member::currentUser();
$admin = Security::getCurrentUser();
$member = $this->objFromFixture('Member', 'user');

//added function correctly
Expand All @@ -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());

Expand All @@ -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'));
}

}
10 changes: 8 additions & 2 deletions tests/MasqueradeSecurityControllerTest.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
<?php

namespace DHensby\SilverStripeMasquerade\Test;

use SilverStripe\Control\Session;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Security\Security;

class MasqueradeSecurityControllerTest extends SapphireTest {

protected static $fixture_file = 'MasqueradeMemberTest.yml';

public function testLogout()
{
$this->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);
Expand Down

0 comments on commit 51367fe

Please sign in to comment.