Skip to content

Commit

Permalink
fix: failing tests & lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thulin committed Jan 17, 2025
1 parent 5bc5a35 commit c116275
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 31 deletions.
11 changes: 5 additions & 6 deletions library/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
use Municipio\Helper\User\User;
use Municipio\Helper\SiteSwitcher\SiteSwitcher;


/**
* Class App
* @package Municipio
Expand Down Expand Up @@ -98,12 +97,12 @@ public function __construct(
$userGroupConfig = new \Municipio\UserGroup\Config\UserGroupConfig($this->wpService);
$userHelperConfig = new \Municipio\Helper\User\Config\UserConfig();
$userHelper = new \Municipio\Helper\User\User(
$this->wpService,
$this->acfService,
$userHelperConfig,
$userGroupConfig,
$this->wpService,
$this->acfService,
$userHelperConfig,
$userGroupConfig,
new \Municipio\Helper\Term\Term($this->wpService, $this->acfService),
new \Municipio\Helper\SiteSwitcher\SiteSwitcher()
new \Municipio\Helper\SiteSwitcher\SiteSwitcher()
);

/**
Expand Down
2 changes: 1 addition & 1 deletion library/Helper/SiteSwitcher/SiteSwitcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ public function runInSite(int $siteId, callable $callable, mixed $callableContex
restore_current_blog();
}
}
}
}
38 changes: 19 additions & 19 deletions library/Helper/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ public function getUserGroup(null|\WP_User|int $user = null): ?WP_Term
}

$userGroup = $this->siteSwitcher->runInSite(
$this->wpService->getMainSiteId(),
function() use ($user) {
$this->wpService->getMainSiteId(),
function () use ($user) {
return $this->wpService->wpGetObjectTerms(
$user->ID,
$user->ID,
$this->userGroupConfig->getUserGroupTaxonomy()
);
}
Expand Down Expand Up @@ -145,18 +145,18 @@ public function getUserGroupUrl(?WP_Term $term = null, null|WP_User|int $user =

// Initialize the URL resolver
$urlResolver = new UserGroupUrl(
$typeOfLink,
$term,
$this->acfService,
$this->wpService,
$this->userConfig,
$typeOfLink,
$term,
$this->acfService,
$this->wpService,
$this->userConfig,
$this->userGroupConfig
);

// Resolve the URL
$resolvedUrl = $this->siteSwitcher->runInSite(
$this->wpService->getMainSiteId(),
function() use ($urlResolver) {
$this->wpService->getMainSiteId(),
function () use ($urlResolver) {
return $urlResolver->get();
}
);
Expand All @@ -173,8 +173,8 @@ public function getUserGroupUrlType(?WP_Term $term = null, null|WP_User|int $use
$termId = $this->userGroupConfig->getUserGroupTaxonomy($user) . '_' . $term->term_id;

$userGroupUrlType = $this->siteSwitcher->runInSite(
$this->wpService->getMainSiteId(),
function() use ($termId) {
$this->wpService->getMainSiteId(),
function () use ($termId) {
return $this->acfService->getField('user_group_type_of_link', $termId) ?: null;
}
);
Expand All @@ -194,11 +194,11 @@ public function getUserPrefersGroupUrl(null|WP_User|int $user = null): ?bool
}

$perfersGroupUrl = $this->siteSwitcher->runInSite(
$this->wpService->getMainSiteId(),
function() use ($user) {
$this->wpService->getMainSiteId(),
function () use ($user) {
return $this->wpService->getUserMeta(
$user->ID,
$this->userConfig->getUserPrefersGroupUrlMetaKey(),
$user->ID,
$this->userConfig->getUserPrefersGroupUrlMetaKey(),
true
);
}
Expand Down Expand Up @@ -248,12 +248,12 @@ public function setUserGroup(string $groupName, null|WP_User|int $user = null):
$taxonomy = $this->userGroupConfig->getUserGroupTaxonomy();

$this->siteSwitcher->runInSite(
$this->wpService->getMainSiteId(),
function() use ($groupName, $taxonomy, $user) {
$this->wpService->getMainSiteId(),
function () use ($groupName, $taxonomy, $user) {
if ($termId = $this->termHelper->createOrGetTermIdFromString($groupName, $taxonomy)) {
$this->wpService->wpSetObjectTerms($user->ID, $termId, $taxonomy, false);
}
}
);
}
}
}
17 changes: 12 additions & 5 deletions library/Helper/User/User.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use AcfService\Implementations\FakeAcfService;
use Municipio\Helper\Term\Contracts\CreateOrGetTermIdFromString;
use Municipio\Helper\User\Config\UserConfigInterface;
use Municipio\Helper\SiteSwitcher\SiteSwitcher;
use Municipio\TestUtils\WpMockFactory;
use Municipio\UserGroup\Config\UserGroupConfigInterface;
use PHPUnit\Framework\TestCase;
Expand All @@ -22,7 +23,8 @@ public function testCanBeInstantiated()
new FakeAcfService(),
$this->createStub(UserConfigInterface::class),
$this->createStub(UserGroupConfigInterface::class),
$this->createStub(CreateOrGetTermIdFromString::class)
$this->createStub(CreateOrGetTermIdFromString::class),
$this->createStub(SiteSwitcher::class)
);

$this->assertInstanceOf(User::class, $user);
Expand All @@ -38,7 +40,8 @@ public function testGetUserReturnsSameUserAsProvidedIfUserOfTypeWPUserIsProvided
new FakeAcfService(),
$this->createStub(UserConfigInterface::class),
$this->createStub(UserGroupConfigInterface::class),
$this->createStub(CreateOrGetTermIdFromString::class)
$this->createStub(CreateOrGetTermIdFromString::class),
$this->createStub(SiteSwitcher::class)
);

$wpUser = WpMockFactory::createWpUser(['ID' => 1]);
Expand All @@ -56,7 +59,8 @@ public function testGetUserReturnsNullIfUserOfTypeWPUserIsProvidedAndIdIs0()
new FakeAcfService(),
$this->createStub(UserConfigInterface::class),
$this->createStub(UserGroupConfigInterface::class),
$this->createStub(CreateOrGetTermIdFromString::class)
$this->createStub(CreateOrGetTermIdFromString::class),
$this->createStub(SiteSwitcher::class)
);

$wpUser = WpMockFactory::createWpUser(['ID' => 0]);
Expand All @@ -76,7 +80,8 @@ public function testGetUserReturnsCurrentUserIfNoUserIsProvidedAndUserIsLoggedIn
new FakeAcfService(),
$this->createStub(UserConfigInterface::class),
$this->createStub(UserGroupConfigInterface::class),
$this->createStub(CreateOrGetTermIdFromString::class)
$this->createStub(CreateOrGetTermIdFromString::class),
$this->createStub(SiteSwitcher::class)
);

$this->assertEquals(123, $user->getUser()->ID);
Expand All @@ -96,7 +101,8 @@ public function testGetUserReturnsUserFromDbIfUserIdIsProvidedAndUserExists()
new FakeAcfService(),
$this->createStub(UserConfigInterface::class),
$this->createStub(UserGroupConfigInterface::class),
$this->createStub(CreateOrGetTermIdFromString::class)
$this->createStub(CreateOrGetTermIdFromString::class),
$this->createStub(SiteSwitcher::class)
);

$this->assertEquals(123, $user->getUser(123)->ID);
Expand All @@ -117,6 +123,7 @@ public function testGetUserReturnsNullIfUserIdIsProvidedAndUserDoesNotExist()
$this->createStub(UserConfigInterface::class),
$this->createStub(UserGroupConfigInterface::class),
$this->createStub(CreateOrGetTermIdFromString::class),
$this->createStub(SiteSwitcher::class)
);

$this->assertNull($user->getUser(123));
Expand Down

0 comments on commit c116275

Please sign in to comment.