Completed
Push — master ( 691103...b765dd )
by Daniel
11:12 queued 08:42
created

testMemberProfileDisplays()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 51
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 51
rs 9.411
cc 1
eloc 3
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
class ForumMemberProfileTest 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...
Coding Style introduced by
As per PSR2, the opening brace for this class should be on a new line.
Loading history...
4
	
5
	static $fixture_file = "forum/tests/ForumTest.yml";
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $fixture_file.
Loading history...
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...
6
	static $use_draft_site = true;
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $use_draft_site.
Loading history...
Coding Style introduced by
The visibility should be declared for property $use_draft_site.

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...
7
	
8
	function testRegistrationWithHoneyPot() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
9
		$origHoneypot = ForumHolder::$use_honeypot_on_register;
10
		$origSpamprotection = ForumHolder::$use_spamprotection_on_register;
11
		
12
		ForumHolder::$use_spamprotection_on_register = false;
13
		
14
		ForumHolder::$use_honeypot_on_register = false;
15
		$response = $this->get('ForumMemberProfile/register');
16
		$this->assertNotContains('RegistrationForm_username', $response->getBody(), 'Honeypot is disabled by default');
17
		
18
		ForumHolder::$use_honeypot_on_register = true;
19
		$response = $this->get('ForumMemberProfile/register');
20
		$this->assertContains('RegistrationForm_username', $response->getBody(), 'Honeypot can be enabled');
21
		
22
		// TODO Will fail if Member is decorated with further *required* fields,
23
		// through updateForumFields() or updateForumValidator()
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
24
		$baseData = array(
25
			'Password' => array(
26
				'_Password' => 'text',
27
				'_ConfirmPassword' => 'text'
28
			),
29
			"Nickname" => 'test',
30
			"Email" => '[email protected]', 
31
		);
32
		
33
		$invalidData = array_merge($baseData, array('action_doregister' => 1, 'username' => 'spamtastic'));
34
		$response = $this->post('ForumMemberProfile/RegistrationForm', $invalidData);
35
		$this->assertEquals(403, $response->getStatusCode());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumMemberProfileTest>.

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
		$validData = array_merge($baseData, array('action_doregister' => 1));
38
		$response = $this->post('ForumMemberProfile/RegistrationForm', $validData);
39
		// Weak check (registration might still fail), but good enough to know if the honeypot is working
40
		$this->assertEquals(200, $response->getStatusCode());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumMemberProfileTest>.

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...
41
		
42
		ForumHolder::$use_honeypot_on_register = $origHoneypot;
43
		ForumHolder::$use_spamprotection_on_register = $origSpamprotection;
44
	}
45
46
	function testMemberProfileSuspensionNote() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
47
		SS_Datetime::set_mock_now('2011-10-10');
48
49
		$normalMember = $this->objFromFixture('Member', 'test1');
50
		$this->loginAs($normalMember);
51
		$response = $this->get('ForumMemberProfile/edit/' . $normalMember->ID);
52
53
		$this->assertNotContains(
54
			_t('ForumRole.SUSPENSIONNOTE'),
55
			$response->getBody(),
56
			'Normal profiles don\'t show suspension note'
57
		);
58
59
		$suspendedMember = $this->objFromFixture('Member', 'suspended');
60
		$this->loginAs($suspendedMember);
61
		$response = $this->get('ForumMemberProfile/edit/' . $suspendedMember->ID);
62
		$this->assertContains(
63
			_t('ForumRole.SUSPENSIONNOTE'),
64
			$response->getBody(),
65
			'Suspended profiles show suspension note'
66
		);
67
68
		SS_Datetime::clear_mock_now();
69
	}
70
	
71
	function testMemberProfileDisplays() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
72
		/* Get the profile of a secretive member */
73
		$this->get('ForumMemberProfile/show/' . $this->idFromFixture('Member', 'test1'));
74
		
75
		/* Check that it just contains the bare minimum 
76
		 
77
		Commented out by wrossiter since this was breaking with custom themes. A test like this should not fail
78
		because of a custom theme. Will reenable these tests when we tackle the new Member functionality
79
		
80
		$this->assertExactMatchBySelector("div#UserProfile label", array(
81
			"Nickname:",
82
			"Number of posts:",
83
			"Forum ranking:",
84
			"Avatar:",
85
		));
86
		$this->assertExactMatchBySelector("div#UserProfile p", array(
87
			'test1',
88
			'5',
89
			'n00b',
90
			'',
91
		));
92
93
		/* Get the profile of a public member */
94
		$this->get('ForumMemberProfile/show/' . $this->idFromFixture('Member', 'test2'));
95
96
		/* Check that it just contains everything 
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
97
		
98
		$this->assertExactMatchBySelector("div#UserProfile label", array(
99
			"Nickname:",
100
			'First Name:',
101
			'Surname:',
102
			'Email:',
103
			'Occupation:',
104
			'Country:',
105
			'Number of posts:',
106
			'Forum ranking:',
107
			'Avatar:'
108
		));
109
		$this->assertExactMatchBySelector("div#UserProfile p", array(
110
			'test2',
111
			'Test',
112
			'Two',
113
			'',
114
			'OtherUser',
115
			'Australia',
116
			'8',
117
			'l33t',
118
			'',
119
		));
120
		 */
121
	}
122
}