Completed
Push — 2.2 ( 8a877d )
by Damian
09:45 queued 06:58
created

BlogCategoryTest::testCanView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
/**
4
 * @mixin PHPUnit_Framework_TestCase
5
 */
6
class BlogCategoryTest extends FunctionalTest {
0 ignored issues
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...
7
	/**
8
	 * @var string
9
	 */
10
	static $fixture_file = 'blog.yml';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $fixture_file.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
11
12
	/**
13
	 * {@inheritdoc}
14
	 */
15
	public function setUp() {
16
		parent::setUp();
17
18
		SS_Datetime::set_mock_now('2013-10-10 20:00:00');
19
	}
20
21
	/**
22
	 * {@inheritdoc}
23
	 */
24
	public function tearDown() {
25
		SS_Datetime::clear_mock_now();
26
27
		parent::tearDown();
28
	}
29
30
	/**
31
	 * Tests that any blog posts returned from $category->BlogPosts() many_many are published,
32
	 * both by normal 'save & publish' functionality and by publish date.
33
	 */
34 View Code Duplication
	public function testBlogPosts() {
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...
35
		$member = Member::currentUser();
36
37
		if($member) {
38
			$member->logout();
39
		}
40
41
		$this->objFromFixture('BlogPost', 'FirstBlogPost');
42
43
		/**
44
		 * @var BlogCategory $category
45
		 */
46
		$category = $this->objFromFixture('BlogCategory', 'FirstCategory');
47
48
		$this->assertEquals(1, $category->BlogPosts()->count(), 'Category blog post count');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<BlogCategoryTest>.

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...
49
	}
50
51
	public function testCanView() {
52
		$this->useDraftSite();
53
54
		$this->objFromFixture('Member', 'Admin');
55
56
		$editor = $this->objFromFixture('Member', 'Editor');
57
		$category = $this->objFromFixture('BlogCategory', 'SecondCategory');
58
59
		$this->assertFalse($category->canView($editor), 'Editor should not be able to view category.');
0 ignored issues
show
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 56 can also be of type object<DataObject>; however, DataObject::canView() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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

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...
60
	}
61
62
	/**
63
	 * The first blog can be viewed by anybody.
64
	 */
65 View Code Duplication
	public function testCanEdit() {
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...
66
		$this->useDraftSite();
67
68
		$admin = $this->objFromFixture('Member', 'Admin');
69
		$editor = $this->objFromFixture('Member', 'Editor');
70
71
		$category = $this->objFromFixture('BlogCategory', 'FirstCategory');
72
73
		$this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.');
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 68 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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

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...
74
		$this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.');
0 ignored issues
show
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 69 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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

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
		$category = $this->objFromFixture('BlogCategory', 'SecondCategory');
77
78
		$this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.');
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 68 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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

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...
79
		$this->assertFalse($category->canEdit($editor), 'Editor should not be able to edit category.');
0 ignored issues
show
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 69 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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

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...
80
81
		$category = $this->objFromFixture('BlogCategory', 'ThirdCategory');
82
83
		$this->assertTrue($category->canEdit($admin), 'Admin should always be able to edit category.');
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 68 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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

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...
84
		$this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.');
0 ignored issues
show
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 69 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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

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
	}
86
87 View Code Duplication
	public function testCanCreate() {
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...
88
		$this->useDraftSite();
89
90
		$admin = $this->objFromFixture('Member', 'Admin');
91
		$editor = $this->objFromFixture('Member', 'Editor');
92
93
		$category = singleton('BlogCategory');
94
95
		$this->assertTrue($category->canCreate($admin), 'Admin should be able to create category.');
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<BlogCategoryTest>.

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...
96
		$this->assertTrue($category->canCreate($editor), 'Editor should be able to create category.');
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<BlogCategoryTest>.

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...
97
	}
98
99 View Code Duplication
	public function testCanDelete() {
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...
100
		$this->useDraftSite();
101
102
		$admin = $this->objFromFixture('Member', 'Admin');
103
		$editor = $this->objFromFixture('Member', 'Editor');
104
105
		$category = $this->objFromFixture('BlogCategory', 'FirstCategory');
106
107
		$this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.');
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 102 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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

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...
108
		$this->assertTrue($category->canDelete($editor), 'Editor should be able to category category.');
0 ignored issues
show
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 103 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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

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
110
		$category = $this->objFromFixture('BlogCategory', 'SecondCategory');
111
		$this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.');
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 102 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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

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...
112
		$this->assertFalse($category->canDelete($editor), 'Editor should not be able to delete category.');
0 ignored issues
show
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 103 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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

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
114
		$category = $this->objFromFixture('BlogCategory', 'ThirdCategory');
115
		$this->assertTrue($category->canDelete($admin), 'Admin should always be able to delete category.');
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 102 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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

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...
116
		$this->assertTrue($category->canDelete($editor), 'Editor should be able to delete category.');
0 ignored issues
show
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 103 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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

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...
117
	}
118
}
119