3 * This file is part of vfsStream.
5 * For the full copyright and license information, please view the LICENSE
6 * file that was distributed with this source code.
8 * @package org\bovigo\vfs
10 namespace org\bovigo\vfs;
12 * Test for permissions related functionality.
16 class PermissionsTestCase extends \PHPUnit_Framework_TestCase
19 * @type vfsStreamDirectory
24 * set up test environment
26 public function setup()
28 $structure = array('test_directory' => array('test.file' => ''));
29 $this->root = vfsStream::setup('root', null, $structure);
36 public function canNotChangePermissionWhenDirectoryNotWriteable()
38 $this->root->getChild('test_directory')->chmod(0444);
39 $this->assertFalse(@chmod(vfsStream::url('root/test_directory/test.file'), 0777));
46 public function canNotChangePermissionWhenFileNotOwned()
48 $this->root->getChild('test_directory')->getChild('test.file')->chown(vfsStream::OWNER_USER_1);
49 $this->assertFalse(@chmod(vfsStream::url('root/test_directory/test.file'), 0777));
56 public function canNotChangeOwnerWhenDirectoryNotWriteable()
58 $this->root->getChild('test_directory')->chmod(0444);
59 $this->assertFalse(@chown(vfsStream::url('root/test_directory/test.file'), vfsStream::OWNER_USER_2));
66 public function canNotChangeOwnerWhenFileNotOwned()
68 $this->root->getChild('test_directory')->getChild('test.file')->chown(vfsStream::OWNER_USER_1);
69 $this->assertFalse(@chown(vfsStream::url('root/test_directory/test.file'), vfsStream::OWNER_USER_2));
76 public function canNotChangeGroupWhenDirectoryNotWriteable()
78 $this->root->getChild('test_directory')->chmod(0444);
79 $this->assertFalse(@chgrp(vfsStream::url('root/test_directory/test.file'), vfsStream::GROUP_USER_2));
86 public function canNotChangeGroupWhenFileNotOwned()
88 $this->root->getChild('test_directory')->getChild('test.file')->chown(vfsStream::OWNER_USER_1);
89 $this->assertFalse(@chgrp(vfsStream::url('root/test_directory/test.file'), vfsStream::GROUP_USER_2));
95 * @expectedException PHPUnit_Framework_Error
96 * @expectedExceptionMessage Can not create new file in non-writable path root
100 public function touchOnNonWriteableDirectoryTriggersError()
102 $this->root->chmod(0555);
103 touch($this->root->url() . '/touch.txt');
112 public function touchOnNonWriteableDirectoryDoesNotCreateFile()
114 $this->root->chmod(0555);
115 $this->assertFalse(@touch($this->root->url() . '/touch.txt'));
116 $this->assertFalse($this->root->hasChild('touch.txt'));