2019-01-27 06:28:57 -05:00
< ? php
2020-04-09 05:50:14 -04:00
2019-01-27 08:47:19 -05:00
declare ( strict_types = 1 );
2019-01-27 06:28:57 -05:00
/**
2024-05-10 09:09:14 -04:00
* SPDX - FileCopyrightText : 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX - License - Identifier : AGPL - 3.0 - or - later
2019-01-27 06:28:57 -05:00
*/
namespace Tests\Core\Command\Config ;
use OC\Core\Command\App\Enable ;
use Symfony\Component\Console\Tester\CommandTester ;
use Test\TestCase ;
/**
* Class AppsEnableTest
*
* @ group DB
*/
class AppsEnableTest extends TestCase {
/** @var CommandTester */
private $commandTester ;
2019-11-27 09:27:18 -05:00
protected function setUp () : void {
2019-01-27 06:28:57 -05:00
parent :: setUp ();
$command = new Enable (
\OC :: $server -> getAppManager (),
\OC :: $server -> getGroupManager ()
);
$this -> commandTester = new CommandTester ( $command );
2019-01-27 08:47:19 -05:00
\OC :: $server -> getAppManager () -> disableApp ( 'admin_audit' );
\OC :: $server -> getAppManager () -> disableApp ( 'comments' );
2019-01-27 06:28:57 -05:00
}
/**
* @ dataProvider dataCommandInput
* @ param $appId
* @ param $groups
* @ param $statusCode
2021-10-01 16:30:02 -04:00
* @ param $pattern
2019-01-27 06:28:57 -05:00
*/
2021-10-01 16:30:02 -04:00
public function testCommandInput ( $appId , $groups , $statusCode , $pattern ) : void {
2019-01-27 06:28:57 -05:00
$input = [ 'app-id' => $appId ];
if ( is_array ( $groups )) {
$input [ '--groups' ] = $groups ;
}
$this -> commandTester -> execute ( $input );
2022-05-24 07:26:58 -04:00
$this -> assertMatchesRegularExpression ( '/' . $pattern . '/' , $this -> commandTester -> getDisplay ());
2019-01-27 06:28:57 -05:00
$this -> assertSame ( $statusCode , $this -> commandTester -> getStatusCode ());
}
2019-01-27 08:47:19 -05:00
public function dataCommandInput () : array {
2021-06-25 05:18:30 -04:00
return [
2021-10-01 16:30:02 -04:00
[[ 'admin_audit' ], null , 0 , 'admin_audit ([\d\.]*) enabled' ],
[[ 'comments' ], null , 0 , 'comments ([\d\.]*) enabled' ],
[[ 'comments' , 'comments' ], null , 0 , " comments ([ \ d \ .]*) enabled \n comments already enabled " ],
2019-01-27 15:53:09 -05:00
[[ 'invalid_app' ], null , 1 , 'Could not download app invalid_app' ],
2019-01-27 06:28:57 -05:00
2021-10-01 16:30:02 -04:00
[[ 'admin_audit' , 'comments' ], null , 0 , " admin_audit ([ \ d \ .]*) enabled \n comments ([ \ d \ .]*) enabled " ],
[[ 'admin_audit' , 'comments' , 'invalid_app' ], null , 1 , " admin_audit ([ \ d \ .]*) enabled \n comments ([ \ d \ .]*) enabled \n Could not download app invalid_app " ],
2019-01-27 06:28:57 -05:00
[[ 'admin_audit' ], [ 'admin' ], 1 , " admin_audit can't be enabled for groups " ],
[[ 'comments' ], [ 'admin' ], 1 , " comments can't be enabled for groups " ],
2021-10-01 16:30:02 -04:00
[[ 'updatenotification' ], [ 'admin' ], 0 , 'updatenotification ([\d\.]*) enabled for groups: admin' ],
2022-04-20 08:21:42 -04:00
[[ 'updatenotification' , 'dashboard' ], [ 'admin' ], 0 , " updatenotification ([ \ d \ .]*) enabled for groups: admin \n dashboard ([ \ d \ .]*) enabled for groups: admin " ],
2019-01-27 06:28:57 -05:00
2021-10-01 16:30:02 -04:00
[[ 'updatenotification' ], [ 'admin' , 'invalid_group' ], 0 , 'updatenotification ([\d\.]*) enabled for groups: admin' ],
2022-04-20 08:21:42 -04:00
[[ 'updatenotification' , 'dashboard' ], [ 'admin' , 'invalid_group' ], 0 , " updatenotification ([ \ d \ .]*) enabled for groups: admin \n dashboard ([ \ d \ .]*) enabled for groups: admin " ],
[[ 'updatenotification' , 'dashboard' , 'invalid_app' ], [ 'admin' , 'invalid_group' ], 1 , " updatenotification ([ \ d \ .]*) enabled for groups: admin \n dashboard ([ \ d \ .]*) enabled for groups: admin \n Could not download app invalid_app " ],
2019-01-27 06:28:57 -05:00
];
}
}