Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tests for files UserConfig service #50050

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bromiesTM
Copy link

  • Resolves: #

Summary

  • Added tests for files user config service
  • Bugfix to prevent unexpected behaviour due to loose type comparisons when validating configuration values + Tests

TODO

  • ...

Checklist

Not ok: in_array("foo", [true, false]); // returns true
ok: in_array("foo", [true, false], true); // returns false

Signed-off-by: Misha M.-Kupriyanov <[email protected]>
@bromiesTM bromiesTM force-pushed the kh/dev/files-userconfig-tests branch from cf27019 to 49d10ed Compare January 6, 2025 10:47
@artonge artonge requested a review from ArtificialOwl January 6, 2025 12:27
Comment on lines +24 to +40
/**
* @var string
*/
private $userUID;

private $userMock;

/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
private $configMock;

/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
private $userSessionMock;

/**
* @var UserConfig|\PHPUnit\Framework\MockObject\MockObject
*/
private $userConfigService;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* @var string
*/
private $userUID;
private $userMock;
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
private $configMock;
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
private $userSessionMock;
/**
* @var UserConfig|\PHPUnit\Framework\MockObject\MockObject
*/
private $userConfigService;
private string $userUID;
private IUser&MockObject $userMock;
private IConfig&MockObject $configMock;
private IUserSession&MockObject $userSessionMock;
private UserConfig $userConfig;

->withAnyParameters()
->willReturn($this->userMock);

$this->userConfigService = $this->getUserConfigService(['addActivity']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->userConfigService = $this->getUserConfigService(['addActivity']);
$this->userConfig = new UserConfig($this->configMock, $this->userSessionMock);

Comment on lines +46 to +50
$this->userUID = static::getUniqueID('user_id-');
\OC::$server->getUserManager()->createUser($this->userUID, 'test');
\OC_User::setUserId($this->userUID);
\OC_Util::setupFS($this->userUID);
$this->userMock = $this->getUserMock($this->userUID);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is all this needed? 🤔

Looks ugly and calls obsolete methods.

Comment on lines +103 to +104
$userConfig = new UserConfig($this->configMock, $this->userSessionMock);
$userConfig->setConfig('crop_image_previews', true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$userConfig = new UserConfig($this->configMock, $this->userSessionMock);
$userConfig->setConfig('crop_image_previews', true);
$this->userConfig->setConfig('crop_image_previews', true);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And same for the other ones

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants