CommentTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 98
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 20 1
A tearDown() 0 4 1
A testProcess() 0 44 2
1
<?php
2
namespace Redaxscript\Tests\Controller;
3
4
use Redaxscript\Controller;
5
use Redaxscript\Db;
6
use Redaxscript\Tests\TestCaseAbstract;
7
8
/**
9
 * CommentTest
10
 *
11
 * @since 3.0.0
12
 *
13
 * @package Redaxscript
14
 * @category Tests
15
 * @author Henry Ruhs
16
 * @author Balázs Szilágyi
17
 *
18
 * @covers Redaxscript\Controller\Comment
19
 * @covers Redaxscript\Controller\ControllerAbstract
20
 *
21
 * @requires OS Linux
22
 */
23
24
class CommentTest extends TestCaseAbstract
25
{
26
	/**
27
	 * setUp
28
	 *
29
	 * @since 3.1.0
30
	 */
31
32
	public function setUp() : void
33
	{
34
		parent::setUp();
35
		$optionArray = $this->getOptionArray();
36
		$installer = $this->installerFactory();
37
		$installer->init();
38
		$installer->rawCreate();
39
		$installer->insertSettings($optionArray);
40
		Db::forTablePrefix('articles')
41
			->create()
42
			->set(
43
			[
44
				'title' => 'Article One',
45
				'alias' => 'article-one'
46
47
			])
48
			->save();
49
		$setting = $this->settingFactory();
50
		$setting->set('captcha', 1);
51
	}
52
53
	/**
54
	 * tearDown
55
	 *
56
	 * @since 3.1.0
57
	 */
58
59
	public function tearDown() : void
60
	{
61
		$this->dropDatabase();
62
	}
63
64
	/**
65
	 * testProcess
66
	 *
67
	 * @since 3.0.0
68
	 *
69
	 * @param array $postArray
70
	 * @param array $settingArray
71
	 * @param string $method
72
	 * @param string $expect
73
	 *
74
	 * @dataProvider providerAutoloader
75
	 */
76
77
	public function testProcess(array $postArray = [], array $settingArray = [], string $method = null, string $expect = null) : void
78
	{
79
		/* setup */
80
81
		$this->_request->set('post', $postArray);
82
		$setting = $this->settingFactory();
83
		$setting->set('notification', $settingArray['notification']);
84
		$setting->set('moderation', $settingArray['moderation']);
85
		if ($method)
0 ignored issues
show
Bug Best Practice introduced by
The expression $method of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
86
		{
87
			$commentController = $this
88
				->getMockBuilder('Redaxscript\Controller\Comment')
89
				->setConstructorArgs(
90
				[
91
					$this->_registry,
92
					$this->_request,
93
					$this->_language,
94
					$this->_config
95
				])
96
				->setMethods(
97
				[
98
					$method
99
				])
100
				->getMock();
101
102
			/* override */
103
104
			$commentController
105
				->expects($this->any())
106
				->method($method);
107
		}
108
		else
109
		{
110
			$commentController = new Controller\Comment($this->_registry, $this->_request, $this->_language, $this->_config);
111
		}
112
113
		/* actual */
114
115
		$actual = $commentController->process();
116
117
		/* compare */
118
119
		$this->assertEquals($expect, $actual);
120
	}
121
}
122