Completed
Pull Request — master (#513)
by Helpful
04:05
created

DNProjectTest::testHasDiskQuota()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
4
class DNProjectTest extends DeploynautTest {
1 ignored issue
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
5
6
	protected static $fixture_file = 'DNProjectTest.yml';
7
8
	/**
9
	 * @var DNProject
10
	 */
11
	protected $project = null;
12
13
	public function setUp() {
14
		parent::setUp();
15
16
		$this->project = DNProject::create();
17
		$this->project->Name = 'testproject';
18
	}
19
20
	/**
21
	 *
22
	 */
23 View Code Duplication
	public function testOnBeforeWriteShouldNotCreateCapFolder() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
		$this->assertTrue(file_exists($this->envPath));
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
25
		$this->assertFalse(file_exists($this->envPath.'/testproject'));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
26
		$this->project->onBeforeWrite();
27
		$this->assertFalse(file_exists($this->envPath.'/testproject'), 'Folder should not have been created');
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
28
	}
29
30 View Code Duplication
	public function testOnBeforeWriteShouldCreateCapFolder() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
		$this->assertTrue(file_exists($this->envPath));
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
		$this->assertFalse(file_exists($this->envPath.'/testproject'));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
		$this->project->CreateEnvFolder = true;
0 ignored issues
show
Documentation introduced by
The property CreateEnvFolder does not exist on object<DNProject>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
34
		$this->project->onBeforeWrite();
35
		$this->assertTrue(file_exists($this->envPath.'/testproject'), 'Folder should have been created');
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
36
	}
37
38
	public function testSetCreateProjectFolderFieldNoFolderExists() {
39
		$fields = new FieldList();
40
		$fields->push(new TextField('Name'));
41
		$this->project->setCreateProjectFolderField($fields);
42
		$this->assertInstanceOf('LabelField', $fields->fieldByName('CreateEnvFolderNotice'));
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
		$this->assertInstanceOf('CheckboxField', $fields->fieldByName('CreateEnvFolder'));
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
	}
45
46
	public function testSetCreateProjectFolderFieldFolderExists() {
47
		$this->assertFalse(
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
48
			file_exists($this->envPath.'/'.$this->project->Name),
49
			'project folder shouldnt exist prior to save'
50
		);
51
		$this->project->CreateEnvFolder = true;
0 ignored issues
show
Documentation introduced by
The property CreateEnvFolder does not exist on object<DNProject>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
52
		$this->project->onBeforeWrite();
53
		$fields = new FieldList();
54
		$fields->push(new TextField('Name'));
55
		$this->project->setCreateProjectFolderField($fields);
56
		$this->assertNull($fields->fieldByName('CreateEnvFolderNotice'));
0 ignored issues
show
Bug introduced by
The method assertNull() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
		$this->assertNull($fields->fieldByName('CreateEnvFolder'));
0 ignored issues
show
Bug introduced by
The method assertNull() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58
	}
59
60
	public function testExceededDiskQuota() {
61
		$project = $this->getMock('DNProject', array('getUsedQuotaMB'));
0 ignored issues
show
Bug introduced by
The method getMock() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
62
		$project->expects($this->any())->method('getUsedQuotaMB')->will($this->returnValue(5));
0 ignored issues
show
Bug introduced by
The method any() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method returnValue() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
		$project->DiskQuotaMB = 1;
64
		$this->assertTrue($project->HasExceededDiskQuota());
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
		$project->DiskQuotaMB = 100;
66
		$this->assertFalse($project->HasExceededDiskQuota());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
	}
68
69
	public function testHasDiskQuota() {
70
		Config::inst()->update('DNProject', 'defaults', array('DiskQuotaMB' => 0));
71
		$this->assertFalse($this->project->HasDiskQuota());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
72
73
		Config::inst()->update('DNProject', 'defaults', array('DiskQuotaMB' => 2048));
74
		$this->assertTrue($this->project->HasDiskQuota());
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
75
76
		$this->project->DiskQuotaMB = 2;
77
		$this->assertTrue($this->project->HasDiskQuota());
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
78
	}
79
80
	public function testAllowed() {
81
		$project = $this->objFromFixture('DNProject', 'firstProject');
82
		$viewer = $this->objFromFixture('Member', 'viewer');
83
84
		$this->assertTrue(
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
85
			$project->allowed('FOO_PERMISSION', $viewer),
86
			'Member that is in the group that has the code, and is in project\'s Viewers, is allowed'
87
		);
88
		$this->assertTrue(
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
89
			$project->allowed('BAR_PERMISSION', $viewer),
90
			'Member that has a role that has the code, and is in project\'s Viewers, is allowed'
91
		);
92
93
		$other = $this->objFromFixture('DNProject', 'otherproject');
94
		$this->assertFalse(
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
95
			$other->allowed('FOO_PERMISSION', $viewer),
96
			'Member that is in the group that has a code, but that is not in project\'s Viewers, is disallowed'
97
		);
98
		$this->assertFalse(
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
99
			$other->allowed('BAR_PERMISSION', $viewer),
100
			'Member that has a role that has the code, but that is not in project\'s Viewers, is disallowed'
101
		);
102
	}
103
104
	public function testAllowedAny() {
105
		$project = $this->objFromFixture('DNProject', 'firstProject');
106
		$viewer = $this->objFromFixture('Member', 'viewer');
107
108
		$this->assertTrue(
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
109
			$project->allowedAny(array('FOO_PERMISSION', 'NONEXISTENT_PERMISSION'), $viewer),
110
			'Member that is in the group that has the code, and is in project\'s Viewers, is allowed'
111
		);
112
		$this->assertTrue(
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
113
			$project->allowedAny(array('BAR_PERMISSION', 'NONEXISTENT_PERMISSION'), $viewer),
114
			'Member that has a role that has the code, and is in project\'s Viewers, is allowed'
115
		);
116
117
	}
118
119
	public function testWhoIsAllowed() {
120
		$project = $this->objFromFixture('DNProject', 'firstProject');
121
		$this->assertCount(0, $project->whoIsAllowed('NONEXISTENT_PERMISSION'));
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
122
		$this->assertDOSEquals(array(
123
			array('Email' =>'[email protected]')
124
		), $project->whoIsAllowed('FOO_PERMISSION'));
125
		$this->assertDOSEquals(array(
126
			array('Email' =>'[email protected]')
127
		), $project->whoIsAllowed('BAR_PERMISSION'));
128
129
		$other = $this->objFromFixture('DNProject', 'otherproject');
130
		$this->assertCount(0, $other->whoIsAllowed('FOO_PERMISSION'));
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
131
		$this->assertCount(0, $other->whoIsAllowed('BAR_PERMISSION'));
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
132
	}
133
134
	public function testWhoIsAllowedAny() {
135
		$project = $this->objFromFixture('DNProject', 'firstProject');
136
		$this->assertCount(0, $project->whoIsAllowedAny(array('NONEXISTENT_PERMISSION', 'NONEXISTENT_PERMISSION_2')));
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
137
		$this->assertDOSEquals(array(
138
			array('Email' =>'[email protected]')
139
		), $project->whoIsAllowedAny(array('FOO_PERMISSION', 'NONEXISTENT_PERMISSION')));
140
		$this->assertDOSEquals(array(
141
			array('Email' =>'[email protected]')
142
		), $project->whoIsAllowedAny(array('BAR_PERMISSION', 'NONEXISTENT_PERMISSION')));
143
	}
144
145
	/**
146
	 *
147
	 */
148 View Code Duplication
	public function testFooGroupIsAllowedToFooPermission() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
149
		$firstProject = $this->objFromFixture('DNProject', 'firstProject');
150
		$firstGroup = $this->objFromFixture('Group', 'firstWithCodeFoo');
151
		$isAllowed = $firstProject->groupAllowed('FOO_PERMISSION', $firstGroup);
152
		$this->assertTrue($isAllowed, 'Expected that foo group is allowed to foo perm');
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
153
	}
154
155 View Code Duplication
	public function testFooGroupIsNotAllowedToBarPermission() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
156
		$project = $this->objFromFixture('DNProject', 'firstProject');
157
		$fooGroup = $this->objFromFixture('Group', 'firstWithCodeFoo');
158
		$isAllowed = $project->groupAllowed('BAR_PERMISSION', $fooGroup);
159
		$this->assertFalse($isAllowed, 'Expected that foo group should not have access to bar perm');
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
160
	}
161
162 View Code Duplication
	public function testBarGroupIsAllowedToBarPermission() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
163
		$firstProject = $this->objFromFixture('DNProject', 'firstProject');
164
		$secondGroup = $this->objFromFixture('Group', 'secondWithRoleBar');
165
		$isAllowed = $firstProject->groupAllowed('BAR_PERMISSION', $secondGroup);
166
		$this->assertTrue($isAllowed, 'Group should have "bar" PermissionRoleCode');
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
167
	}
168
169 View Code Duplication
	public function testSecondGroupIsNotAllowedToFirstProject() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
170
		$firstProject = $this->objFromFixture('DNProject', 'firstProject');
171
		$thirdGroup = $this->objFromFixture('Group', 'thirdWithCodeFoo');
172
		$isAllowed = $firstProject->groupAllowed('FOO_PERMISSION', $thirdGroup);
173
		$this->assertFalse($isAllowed, 'Expected that non project group should be denied');
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
174
	}
175
176 View Code Duplication
	public function testNonViewerGroupAllowedIsFalse() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
177
		$otherProject = $this->objFromFixture('DNProject', 'otherproject');
178
		$firstGroup = $this->objFromFixture('Group', 'firstWithCodeFoo');
179
		$isAllowed = $otherProject->groupAllowed('FOO_PERMISSION', $firstGroup);
180
		$this->assertFalse($isAllowed, 'Expected that non project group should be denied');
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DNProjectTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
181
	}
182
}
183