-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
<?php | ||
|
||
namespace skouat\ppde\tests\controller\admin; | ||
|
||
use phpbb\config\config; | ||
use phpbb\language\language; | ||
use phpbb\request\request; | ||
use phpbb\template\template; | ||
use phpbb\user; | ||
use skouat\ppde\controller\admin\overview_controller; | ||
use skouat\ppde\controller\main_controller; | ||
|
||
class overview_controller_test extends \phpbb_test_case | ||
{ | ||
/** @var \PHPUnit\Framework\MockObject\MockObject */ | ||
protected $auth; | ||
|
||
/** @var \PHPUnit\Framework\MockObject\MockObject */ | ||
protected $config; | ||
|
||
/** @var \PHPUnit\Framework\MockObject\MockObject */ | ||
protected $language; | ||
|
||
/** @var \PHPUnit\Framework\MockObject\MockObject */ | ||
protected $log; | ||
|
||
/** @var \PHPUnit\Framework\MockObject\MockObject */ | ||
protected $ppde_actions; | ||
|
||
/** @var \PHPUnit\Framework\MockObject\MockObject */ | ||
protected $ppde_actions_locale; | ||
|
||
/** @var \PHPUnit\Framework\MockObject\MockObject */ | ||
protected $ppde_controller_main; | ||
|
||
/** @var \PHPUnit\Framework\MockObject\MockObject */ | ||
protected $ppde_controller_transactions; | ||
|
||
/** @var \PHPUnit\Framework\MockObject\MockObject */ | ||
protected $ppde_ext_manager; | ||
|
||
/** @var \PHPUnit\Framework\MockObject\MockObject */ | ||
protected $ppde_ipn_paypal; | ||
|
||
/** @var \PHPUnit\Framework\MockObject\MockObject */ | ||
protected $request; | ||
|
||
/** @var \PHPUnit\Framework\MockObject\MockObject */ | ||
protected $template; | ||
|
||
/** @var \PHPUnit\Framework\MockObject\MockObject */ | ||
protected $user; | ||
|
||
/** @var overview_controller */ | ||
protected $controller; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->auth = $this->getMockBuilder('\phpbb\auth\auth') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->config = $this->getMockBuilder(config::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->language = $this->getMockBuilder(language::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->log = $this->getMockBuilder('\phpbb\log\log') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->ppde_actions = $this->getMockBuilder('\skouat\ppde\actions\core') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->ppde_actions_locale = $this->getMockBuilder('\skouat\ppde\actions\locale_icu') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->ppde_controller_main = $this->getMockBuilder(main_controller::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->ppde_controller_transactions = $this->getMockBuilder('\skouat\ppde\controller\admin\transactions_controller') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->ppde_ext_manager = $this->getMockBuilder('\skouat\ppde\controller\extension_manager') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->ppde_ipn_paypal = $this->getMockBuilder('\skouat\ppde\controller\ipn_paypal') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->request = $this->getMockBuilder(request::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->template = $this->getMockBuilder(template::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->user = $this->getMockBuilder(user::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->controller = new overview_controller( | ||
$this->auth, | ||
$this->config, | ||
$this->language, | ||
$this->log, | ||
$this->ppde_actions, | ||
$this->ppde_actions_locale, | ||
$this->ppde_controller_main, | ||
$this->ppde_controller_transactions, | ||
$this->ppde_ext_manager, | ||
$this->ppde_ipn_paypal, | ||
$this->request, | ||
$this->template, | ||
$this->user, | ||
'adm/', | ||
'phpBB/', | ||
'.php' | ||
); | ||
} | ||
|
||
public function test_display_overview() | ||
{ | ||
$this->ppde_ext_manager->expects($this->once()) | ||
->method('get_ext_meta') | ||
->willReturn(['extra' => ['display-name' => 'Test Extension']]); | ||
|
||
$this->template->expects($this->atLeastOnce()) | ||
->method('assign_vars'); | ||
|
||
$this->controller->display_overview(''); | ||
} | ||
|
||
public function test_get_install_days() | ||
{ | ||
$this->config->expects($this->once()) | ||
->method('offsetGet') | ||
->with('ppde_install_date') | ||
->willReturn(time() - 86400); // 1 day ago | ||
|
||
$reflection = new \ReflectionClass($this->controller); | ||
$method = $reflection->getMethod('get_install_days'); | ||
$method->setAccessible(true); | ||
|
||
$result = $method->invoke($this->controller); | ||
$this->assertEquals(1, $result); | ||
} | ||
|
||
public function test_handle_date_action() | ||
{ | ||
$this->config->expects($this->once()) | ||
->method('set') | ||
->with('ppde_install_date', $this->anything()); | ||
|
||
$this->log->expects($this->once()) | ||
->method('add') | ||
->with('admin', $this->anything(), $this->anything(), 'LOG_PPDE_STAT_RESET_DATE'); | ||
|
||
$reflection = new \ReflectionClass($this->controller); | ||
$method = $reflection->getMethod('handle_date_action'); | ||
$method->setAccessible(true); | ||
|
||
$method->invoke($this->controller); | ||
} | ||
|
||
public function test_handle_esi_action() | ||
{ | ||
$this->config->expects($this->once()) | ||
->method('set') | ||
->with('ppde_first_start', 1); | ||
|
||
$this->log->expects($this->once()) | ||
->method('add') | ||
->with('admin', $this->anything(), $this->anything(), 'LOG_PPDE_STAT_RETEST_ESI'); | ||
|
||
$reflection = new \ReflectionClass($this->controller); | ||
$method = $reflection->getMethod('handle_esi_action'); | ||
$method->setAccessible(true); | ||
|
||
$method->invoke($this->controller); | ||
} | ||
} |