@ -27,6 +27,7 @@ namespace OCA\Spreed\Tests\Unit;
use OCA\Spreed\Capabilities ;
use OCA\Spreed\Config ;
use OCP\Capabilities\IPublicCapability ;
use OCP\IConfig ;
use OCP\IUser ;
use OCP\IUserSession ;
use PHPUnit\Framework\MockObject\MockObject ;
@ -34,20 +35,24 @@ use Test\TestCase;
class CapabilitiesTest extends TestCase {
/** @var IConfig|MockObject */
protected $serverConfig ;
/** @var Config|MockObject */
protected $config ;
protected $talkC onfig ;
/** @var IUserSession|MockObject */
protected $userSession ;
public function setUp () {
parent :: setUp ();
$this -> config = $this -> createMock ( Config :: class );
$this -> serverConfig = $this -> createMock ( IConfig :: class );
$this -> talkConfig = $this -> createMock ( Config :: class );
$this -> userSession = $this -> createMock ( IUserSession :: class );
}
public function testGetCapabilitiesGuest () : void {
$capabilities = new Capabilities (
$this -> config ,
$this -> serverConfig ,
$this -> talkConfig ,
$this -> userSession
);
@ -55,9 +60,14 @@ class CapabilitiesTest extends TestCase {
-> method ( 'getUser' )
-> willReturn ( null );
$this -> c onfig-> expects ( $this -> never ())
$this -> talkC onfig-> expects ( $this -> never ())
-> method ( 'isDisabledForUser' );
$this -> serverConfig -> expects ( $this -> once ())
-> method ( 'getSystemValueString' )
-> with ( 'version' , '0.0.0' )
-> willReturn ( '16.0.1' );
$this -> assertInstanceOf ( IPublicCapability :: class , $capabilities );
$this -> assertSame ([
'spreed' => [
@ -80,13 +90,19 @@ class CapabilitiesTest extends TestCase {
'locked-one-to-one-rooms' ,
'read-only-rooms' ,
],
'config' => [
'chat' => [
'max-length' => 1000 ,
],
],
],
], $capabilities -> getCapabilities ());
}
public function testGetCapabilitiesUserAllowed () : void {
$capabilities = new Capabilities (
$this -> config ,
$this -> serverConfig ,
$this -> talkConfig ,
$this -> userSession
);
@ -95,11 +111,16 @@ class CapabilitiesTest extends TestCase {
-> method ( 'getUser' )
-> willReturn ( $user );
$this -> c onfig-> expects ( $this -> once ())
$this -> talkC onfig-> expects ( $this -> once ())
-> method ( 'isDisabledForUser' )
-> with ( $user )
-> willReturn ( false );
$this -> serverConfig -> expects ( $this -> once ())
-> method ( 'getSystemValueString' )
-> with ( 'version' , '0.0.0' )
-> willReturn ( '16.0.2' );
$this -> assertInstanceOf ( IPublicCapability :: class , $capabilities );
$this -> assertSame ([
'spreed' => [
@ -122,13 +143,19 @@ class CapabilitiesTest extends TestCase {
'locked-one-to-one-rooms' ,
'read-only-rooms' ,
],
'config' => [
'chat' => [
'max-length' => 32000 ,
],
],
],
], $capabilities -> getCapabilities ());
}
public function testGetCapabilitiesUserDisallowed () : void {
$capabilities = new Capabilities (
$this -> config ,
$this -> serverConfig ,
$this -> talkConfig ,
$this -> userSession
);
@ -137,11 +164,14 @@ class CapabilitiesTest extends TestCase {
-> method ( 'getUser' )
-> willReturn ( $user );
$this -> c onfig-> expects ( $this -> once ())
$this -> talkC onfig-> expects ( $this -> once ())
-> method ( 'isDisabledForUser' )
-> with ( $user )
-> willReturn ( true );
$this -> serverConfig -> expects ( $this -> never ())
-> method ( 'getSystemValueString' );
$this -> assertInstanceOf ( IPublicCapability :: class , $capabilities );
$this -> assertSame ([], $capabilities -> getCapabilities ());
}