56767ac7b495feb107b5ff10512a2ed2910c2b45
[yaffs-website] / vendor / mikey179 / vfsStream / src / test / php / org / bovigo / vfs / PermissionsTestCase.php
1 <?php
2 /**
3  * This file is part of vfsStream.
4  *
5  * For the full copyright and license information, please view the LICENSE
6  * file that was distributed with this source code.
7  *
8  * @package  org\bovigo\vfs
9  */
10 namespace org\bovigo\vfs;
11 /**
12  * Test for permissions related functionality.
13  *
14  * @group  permissions
15  */
16 class PermissionsTestCase extends \PHPUnit_Framework_TestCase
17 {
18     /**
19      * @type  vfsStreamDirectory
20      */
21     private $root;
22
23     /**
24      * set up test environment
25      */
26     public function setup()
27     {
28         $structure = array('test_directory' => array('test.file' => ''));
29         $this->root = vfsStream::setup('root', null, $structure);
30     }
31
32     /**
33      * @test
34      * @group  issue_52
35      */
36     public function canNotChangePermissionWhenDirectoryNotWriteable()
37     {
38         $this->root->getChild('test_directory')->chmod(0444);
39         $this->assertFalse(@chmod(vfsStream::url('root/test_directory/test.file'), 0777));
40     }
41
42     /**
43      * @test
44      * @group  issue_53
45      */
46     public function canNotChangePermissionWhenFileNotOwned()
47     {
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));
50     }
51
52     /**
53      * @test
54      * @group  issue_52
55      */
56     public function canNotChangeOwnerWhenDirectoryNotWriteable()
57     {
58         $this->root->getChild('test_directory')->chmod(0444);
59         $this->assertFalse(@chown(vfsStream::url('root/test_directory/test.file'), vfsStream::OWNER_USER_2));
60     }
61
62     /**
63      * @test
64      * @group  issue_53
65      */
66     public function canNotChangeOwnerWhenFileNotOwned()
67     {
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));
70     }
71
72     /**
73      * @test
74      * @group  issue_52
75      */
76     public function canNotChangeGroupWhenDirectoryNotWriteable()
77     {
78         $this->root->getChild('test_directory')->chmod(0444);
79         $this->assertFalse(@chgrp(vfsStream::url('root/test_directory/test.file'), vfsStream::GROUP_USER_2));
80     }
81
82     /**
83      * @test
84      * @group  issue_53
85      */
86     public function canNotChangeGroupWhenFileNotOwned()
87     {
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));
90     }
91
92     /**
93      * @test
94      * @group  issue_107
95      * @expectedException  PHPUnit_Framework_Error
96      * @expectedExceptionMessage  Can not create new file in non-writable path root
97      * @requires PHP 5.4
98      * @since  1.5.0
99      */
100     public function touchOnNonWriteableDirectoryTriggersError()
101     {
102         $this->root->chmod(0555);
103         touch($this->root->url() . '/touch.txt');
104     }
105
106     /**
107      * @test
108      * @group  issue_107
109      * @requires PHP 5.4
110      * @since  1.5.0
111      */
112     public function touchOnNonWriteableDirectoryDoesNotCreateFile()
113     {
114         $this->root->chmod(0555);
115         $this->assertFalse(@touch($this->root->url() . '/touch.txt'));
116         $this->assertFalse($this->root->hasChild('touch.txt'));
117     }
118 }