Completed
Push — master ( 7de195...5f1ca1 )
by Henry
08:39
created

tests/unit/Controller/CommentTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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)
86
		{
87
			$commentController = $this
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/pull/3687

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
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