Skip to content

Commit

Permalink
fix test, code and style
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Brahmer <[email protected]>
  • Loading branch information
Grotax committed Oct 14, 2024
1 parent 52209e3 commit ff1479b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 57 deletions.
61 changes: 14 additions & 47 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCP\IRequest;
use OCP\IAppConfig;
use OCP\Util;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\AppFramework\Http\TemplateResponse;
Expand All @@ -34,53 +35,18 @@ class PageController extends Controller
{
use JSONHttpErrorTrait;

/**
* @var IAppConfig
*/
private $settings;

/**
* @var IL10N
*/
private $l10n;

/**
* @var IURLGenerator
*/
private $urlGenerator;

/**
* @var RecommendedSites
*/
private $recommendedSites;

/**
* @var StatusService
*/
private $statusService;

/*
* @var IInitialState
*/
private $initialState;

public function __construct(
IRequest $request,
IAppConfig $settings,
IURLGenerator $urlGenerator,
IL10N $l10n,
RecommendedSites $recommendedSites,
StatusService $statusService,
IInitialState $initialState,
?IUserSession $userSession
?IUserSession $userSession,
private IAppConfig $settings,
private IConfig $config,
private IURLGenerator $urlGenerator,
private IL10N $l10n,
private RecommendedSites $recommendedSites,
private StatusService $statusService,
private IInitialState $initialState
) {
parent::__construct($request, $userSession);
$this->settings = $settings;
$this->urlGenerator = $urlGenerator;
$this->l10n = $l10n;
$this->recommendedSites = $recommendedSites;
$this->statusService = $statusService;
$this->initialState = $initialState;
}


Expand Down Expand Up @@ -116,13 +82,14 @@ public function index(): TemplateResponse
'oldestFirst',
'showAll'
];

foreach ($usersettings as $setting) {
$this->initialState->provideInitialState($setting, $this->settings->getUserValue(
$this->initialState->provideInitialState($setting, $this->config->getUserValue(
$this->getUserId(),
$this->appName,
$setting,
'0')
);
$setting,
'0'
));
}

$csp = new ContentSecurityPolicy();
Expand Down
20 changes: 11 additions & 9 deletions lib/Listeners/UserSettingsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@
use OCP\EventDispatcher\IEventListener;

/** @template-implements IEventListener<BeforePreferenceSetEvent|BeforePreferenceDeletedEvent> */
class UserSettingsListener implements IEventListener {
class UserSettingsListener implements IEventListener
{

public function handle(Event $event): void {
if (!($event instanceof BeforePreferenceSetEvent || $event instanceof BeforePreferenceDeletedEvent)) {
return;
}
public function handle(Event $event): void
{
if (!($event instanceof BeforePreferenceSetEvent || $event instanceof BeforePreferenceDeletedEvent)) {
return;
}

if ($event->getAppId() !== 'news') {
if ($event->getAppId() !== 'news') {
return;
}
}

$event->setValid(true);
}
$event->setValid(true);
}
}
12 changes: 11 additions & 1 deletion tests/Unit/Controller/PageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
use OCP\AppFramework\Services\IInitialState;
use PHPUnit\Framework\TestCase;

class PageControllerTest extends TestCase
Expand Down Expand Up @@ -86,6 +87,11 @@ class PageControllerTest extends TestCase
*/
private $userSession;

/**
* @var \PHPUnit\Framework\MockObject\MockObject|IInitialState
*/
private $initalState;

Check warning on line 93 in tests/Unit/Controller/PageControllerTest.php

View workflow job for this annotation

GitHub Actions / typos

"inital" should be "initial".

/**
* Gets run before each test
*/
Expand Down Expand Up @@ -131,6 +137,9 @@ public function setUp(): void
$this->userSession->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
$this->initalState = $this->getMockBuilder(IInitialState::class)

Check warning on line 140 in tests/Unit/Controller/PageControllerTest.php

View workflow job for this annotation

GitHub Actions / typos

"inital" should be "initial".
->disableOriginalConstructor()
->getMock();
$this->controller = new PageController(
$this->request,
$this->userSession,
Expand All @@ -139,7 +148,8 @@ public function setUp(): void
$this->urlGenerator,
$this->l10n,
$this->recommended,
$this->status
$this->status,
$this->initalState

Check warning on line 152 in tests/Unit/Controller/PageControllerTest.php

View workflow job for this annotation

GitHub Actions / typos

"inital" should be "initial".
);
}

Expand Down

0 comments on commit ff1479b

Please sign in to comment.