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

BlogPostTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
class BlogPostTest extends SapphireTest {
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...
4
	
5
	/**
6
	 * @var string
7
	 */
8
	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...
9
10
	/**
11
	 * {@inheritdoc}
12
	 */
13
	public function setUp() {
14
		parent::setUp();
15
	}
16
17
	/**
18
	 * {@inheritdoc}
19
	 */
20
	public function tearDown() {
21
		SS_Datetime::clear_mock_now();
22
		parent::tearDown();
23
	}
24
25
	/**
26
	 * @dataProvider canViewProvider
27
	 */
28
	public function testCanView($date, $user, $page, $canView) {
29
		$userRecord = $this->objFromFixture('Member', $user);
30
		$pageRecord = $this->objFromFixture('BlogPost', $page);
31
		SS_Datetime::set_mock_now($date);
32
		$this->assertEquals($canView, $pageRecord->canView($userRecord));
0 ignored issues
show
Bug introduced by
It seems like $userRecord defined by $this->objFromFixture('Member', $user) on line 29 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 assertEquals() does not seem to exist on object<BlogPostTest>.

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
	}
34
	
35
	public function canViewProvider() {
36
		$someFutureDate = '2013-10-10 20:00:00';
37
		$somePastDate = '2009-10-10 20:00:00';
38
		return array(
39
			// Check this post given the date has passed
40
			array($someFutureDate, 'Editor', 'PostA', true),
41
			array($someFutureDate, 'Contributor', 'PostA', true),
42
			array($someFutureDate, 'BlogEditor', 'PostA', true),
43
			array($someFutureDate, 'Writer', 'PostA', true),
44
			
45
			// Check unpublished pages
46
			array($somePastDate, 'Editor', 'PostA', true),
47
			array($somePastDate, 'Contributor', 'PostA', true),
48
			array($somePastDate, 'BlogEditor', 'PostA', true),
49
			array($somePastDate, 'Writer', 'PostA', true),
50
			
51
			// Test a page that was authored by another user
52
			
53
			// Check this post given the date has passed
54
			array($someFutureDate, 'Editor', 'FirstBlogPost', true),
55
			array($someFutureDate, 'Contributor', 'FirstBlogPost', true),
56
			array($someFutureDate, 'BlogEditor', 'FirstBlogPost', true),
57
			array($someFutureDate, 'Writer', 'FirstBlogPost', true),
58
			
59
			// Check future pages - non-editors shouldn't be able to see this
60
			array($somePastDate, 'Editor', 'FirstBlogPost', true),
61
			array($somePastDate, 'Contributor', 'FirstBlogPost', false),
62
			array($somePastDate, 'BlogEditor', 'FirstBlogPost', false),
63
			array($somePastDate, 'Writer', 'FirstBlogPost', false),
64
		);
65
	}
66
67
	public function testCandidateAuthors() {
68
		$blogpost = $this->objFromFixture('BlogPost', 'PostC');
69
70
		$this->assertEquals(7, $blogpost->getCandidateAuthors()->count());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<BlogPostTest>.

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...
71
72
		//Set the group to draw Members from
73
		Config::inst()->update('BlogPost', 'restrict_authors_to_group','BlogUsers');
74
75
		$this->assertEquals(3, $blogpost->getCandidateAuthors()->count());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<BlogPostTest>.

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...
76
77
78
	}
79
}
80