2016-10-13 05:53:30 +02:00
|
|
|
<?php
|
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\Dev\Tests;
|
|
|
|
|
2016-10-13 05:53:30 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2017-09-26 13:16:02 +02:00
|
|
|
use SilverStripe\Security\Member;
|
|
|
|
use SilverStripe\Security\Permission;
|
2016-10-13 05:53:30 +02:00
|
|
|
|
|
|
|
class SapphireTestTest extends SapphireTest
|
|
|
|
{
|
2016-12-16 05:34:21 +01:00
|
|
|
public function testResolveFixturePath()
|
|
|
|
{
|
|
|
|
// Same directory
|
|
|
|
$this->assertEquals(
|
|
|
|
__DIR__ . '/CsvBulkLoaderTest.yml',
|
|
|
|
$this->resolveFixturePath('./CsvBulkLoaderTest.yml')
|
|
|
|
);
|
|
|
|
// Filename only
|
|
|
|
$this->assertEquals(
|
|
|
|
__DIR__ . '/CsvBulkLoaderTest.yml',
|
|
|
|
$this->resolveFixturePath('CsvBulkLoaderTest.yml')
|
|
|
|
);
|
|
|
|
// Parent path
|
|
|
|
$this->assertEquals(
|
|
|
|
dirname(__DIR__) . '/ORM/DataObjectTest.yml',
|
|
|
|
$this->resolveFixturePath('../ORM/DataObjectTest.yml')
|
|
|
|
);
|
|
|
|
// Absolute path
|
|
|
|
$this->assertEquals(
|
|
|
|
dirname(__DIR__) . '/ORM/DataObjectTest.yml',
|
|
|
|
$this->resolveFixturePath(dirname(__DIR__) .'/ORM/DataObjectTest.yml')
|
|
|
|
);
|
|
|
|
}
|
2017-09-26 13:16:02 +02:00
|
|
|
|
|
|
|
public function testActWithPermission()
|
|
|
|
{
|
|
|
|
$this->logOut();
|
|
|
|
$this->assertFalse(Permission::check('ADMIN'));
|
|
|
|
$this->actWithPermission('ADMIN', function () {
|
|
|
|
$this->assertTrue(Permission::check('ADMIN'));
|
|
|
|
// check nested actAs calls work as expected
|
|
|
|
Member::actAs(null, function () {
|
|
|
|
$this->assertFalse(Permission::check('ADMIN'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreateMemberWithPermission()
|
|
|
|
{
|
|
|
|
$this->assertCount(0, Member::get()->filter([ 'Email' => 'TESTPERM@example.org' ]));
|
|
|
|
$this->createMemberWithPermission('TESTPERM');
|
|
|
|
$this->assertCount(1, Member::get()->filter([ 'Email' => 'TESTPERM@example.org' ]));
|
|
|
|
}
|
2016-10-13 05:53:30 +02:00
|
|
|
}
|