diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core/command/maintenance/singleusertest.php | 129 | ||||
-rw-r--r-- | tests/karma.config.js | 2 | ||||
-rw-r--r-- | tests/lib/connector/sabre/filesplugin.php | 31 |
3 files changed, 158 insertions, 4 deletions
diff --git a/tests/core/command/maintenance/singleusertest.php b/tests/core/command/maintenance/singleusertest.php new file mode 100644 index 00000000000..6629f39564f --- /dev/null +++ b/tests/core/command/maintenance/singleusertest.php @@ -0,0 +1,129 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace Tests\Core\Command\Maintenance; + + +use OC\Core\Command\Maintenance\SingleUser; +use Test\TestCase; + +class SingleUserTest extends TestCase { + /** @var \PHPUnit_Framework_MockObject_MockObject */ + protected $config; + /** @var \PHPUnit_Framework_MockObject_MockObject */ + protected $consoleInput; + /** @var \PHPUnit_Framework_MockObject_MockObject */ + protected $consoleOutput; + + /** @var \Symfony\Component\Console\Command\Command */ + protected $command; + + protected function setUp() { + parent::setUp(); + + $config = $this->config = $this->getMockBuilder('OCP\IConfig') + ->disableOriginalConstructor() + ->getMock(); + $this->consoleInput = $this->getMock('Symfony\Component\Console\Input\InputInterface'); + $this->consoleOutput = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); + + /** @var \OCP\IConfig $config */ + $this->command = new SingleUser($config); + } + + public function testChangeStateToOn() { + + $this->consoleInput->expects($this->once()) + ->method('getOption') + ->with('on') + ->willReturn(true); + + $this->config->expects($this->once()) + ->method('setSystemValue') + ->with('singleuser', true); + + $this->consoleOutput->expects($this->once()) + ->method('writeln') + ->with('Single user mode enabled'); + + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); + } + + public function testChangeStateToOff() { + + $this->consoleInput->expects($this->at(0)) + ->method('getOption') + ->with('on') + ->willReturn(false); + + $this->consoleInput->expects($this->at(1)) + ->method('getOption') + ->with('off') + ->willReturn(true); + + $this->config->expects($this->once()) + ->method('setSystemValue') + ->with('singleuser', false); + + $this->consoleOutput->expects($this->once()) + ->method('writeln') + ->with('Single user mode disabled'); + + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); + } + + public function stateData() { + return [ + [ true, 'Single user mode is currently enabled' ], + [ false, 'Single user mode is currently disabled' ], + ]; + } + + /** + * @dataProvider stateData + * + * @param $state + * @param $expectedOutput + */ + public function testState($state, $expectedOutput) { + + $this->consoleInput->expects($this->at(0)) + ->method('getOption') + ->with('on') + ->willReturn(false); + + $this->consoleInput->expects($this->at(1)) + ->method('getOption') + ->with('off') + ->willReturn(false); + + $this->config->expects($this->once()) + ->method('getSystemValue') + ->with('singleuser', false) + ->willReturn($state); + + $this->consoleOutput->expects($this->once()) + ->method('writeln') + ->with($expectedOutput); + + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); + } +} diff --git a/tests/karma.config.js b/tests/karma.config.js index 8aeadc123e7..7b3877f7766 100644 --- a/tests/karma.config.js +++ b/tests/karma.config.js @@ -121,7 +121,7 @@ module.exports = function(config) { } // extra test libs - files.push(corePath + 'tests/lib/sinon-1.7.3.js'); + files.push(corePath + 'tests/lib/sinon-1.15.4.js'); // core mocks files.push(corePath + 'tests/specHelper.js'); diff --git a/tests/lib/connector/sabre/filesplugin.php b/tests/lib/connector/sabre/filesplugin.php index 54d43d66dda..a4cf9f7bfb9 100644 --- a/tests/lib/connector/sabre/filesplugin.php +++ b/tests/lib/connector/sabre/filesplugin.php @@ -62,7 +62,7 @@ class FilesPlugin extends \Test\TestCase { ->will($this->returnValue('"abc"')); $node->expects($this->any()) ->method('getDavPermissions') - ->will($this->returnValue('R')); + ->will($this->returnValue('DWCKMSR')); return $node; } @@ -98,11 +98,36 @@ class FilesPlugin extends \Test\TestCase { $this->assertEquals('"abc"', $propFind->get(self::GETETAG_PROPERTYNAME)); $this->assertEquals(123, $propFind->get(self::FILEID_PROPERTYNAME)); $this->assertEquals(null, $propFind->get(self::SIZE_PROPERTYNAME)); - $this->assertEquals('R', $propFind->get(self::PERMISSIONS_PROPERTYNAME)); + $this->assertEquals('DWCKMSR', $propFind->get(self::PERMISSIONS_PROPERTYNAME)); $this->assertEquals('http://example.com/', $propFind->get(self::DOWNLOADURL_PROPERTYNAME)); $this->assertEquals(array(self::SIZE_PROPERTYNAME), $propFind->get404Properties()); } + public function testGetPublicPermissions() { + $this->plugin = new \OC\Connector\Sabre\FilesPlugin($this->tree, true); + $this->plugin->initialize($this->server); + + $propFind = new \Sabre\DAV\PropFind( + '/dummyPath', + [ + self::PERMISSIONS_PROPERTYNAME, + ], + 0 + ); + + $node = $this->createTestNode('\OC\Connector\Sabre\File'); + $node->expects($this->any()) + ->method('getDavPermissions') + ->will($this->returnValue('DWCKMSR')); + + $this->plugin->handleGetProperties( + $propFind, + $node + ); + + $this->assertEquals('DWCKR', $propFind->get(self::PERMISSIONS_PROPERTYNAME)); + } + public function testGetPropertiesForDirectory() { $node = $this->createTestNode('\OC\Connector\Sabre\Directory'); @@ -132,7 +157,7 @@ class FilesPlugin extends \Test\TestCase { $this->assertEquals('"abc"', $propFind->get(self::GETETAG_PROPERTYNAME)); $this->assertEquals(123, $propFind->get(self::FILEID_PROPERTYNAME)); $this->assertEquals(1025, $propFind->get(self::SIZE_PROPERTYNAME)); - $this->assertEquals('R', $propFind->get(self::PERMISSIONS_PROPERTYNAME)); + $this->assertEquals('DWCKMSR', $propFind->get(self::PERMISSIONS_PROPERTYNAME)); $this->assertEquals(null, $propFind->get(self::DOWNLOADURL_PROPERTYNAME)); $this->assertEquals(array(self::DOWNLOADURL_PROPERTYNAME), $propFind->get404Properties()); } |