Skip to content

Commit

Permalink
refactor: apply code standards
Browse files Browse the repository at this point in the history
  • Loading branch information
thorbrink committed Oct 22, 2024
1 parent 8c188e8 commit 4fc2ed3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
*/
class AllowPostsFromOtherSitesToKeepTheirPermalinks implements Hookable
{
const FILTER_PRIORITY = 10;
const FILTER_NAME = 'post_link';
const FILTER_ARGUMENTS = 2;
const FILTER_FUNCTION = 'getPermalinkFromOtherSite';
public const FILTER_PRIORITY = 10;
public const FILTER_NAME = 'post_link';
public const FILTER_ARGUMENTS = 2;
public const FILTER_FUNCTION = 'getPermalinkFromOtherSite';

/**
* Constructor.
Expand Down Expand Up @@ -63,9 +63,9 @@ public function getPermalinkFromOtherSite(string $permalink, WP_Post $post): str
}

$filteredPermalink = $this->getOtherSitesPostLink($otherSitesId, $post);

$this->wpService->addFilter(self::FILTER_NAME, [$this, self::FILTER_FUNCTION], self::FILTER_PRIORITY, self::FILTER_ARGUMENTS);

return $filteredPermalink;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Municipio\TestUtils\WpMockFactory;
use PHPUnit\Framework\TestCase;
use WpService\Implementations\FakeWpService;
use Municipio\PostFilters\AllowPostsFromOtherSitesToKeepTheirPermalinks as SUT;

class AllowPostsFromOtherSitesToKeepTheirPermalinksTest extends TestCase
{
Expand All @@ -14,11 +15,11 @@ class AllowPostsFromOtherSitesToKeepTheirPermalinksTest extends TestCase
public function testGetPermalinkFromOtherSiteAttachesFilterToPostLink()
{
$wpService = new FakeWpService(['addFilter' => true]);
$filter = new AllowPostsFromOtherSitesToKeepTheirPermalinks($wpService);
$filter = new SUT($wpService);

$filter->addHooks();

$this->assertEquals('post_link', $wpService->methodCalls['addFilter'][0][0]);
$this->assertEquals(SUT::FILTER_NAME, $wpService->methodCalls['addFilter'][0][0]);
}

/**
Expand All @@ -27,7 +28,7 @@ public function testGetPermalinkFromOtherSiteAttachesFilterToPostLink()
public function testGetPermalinkFromOtherSiteReturnsPermalinkIfSiteIsNotMultisite()
{
$wpService = new FakeWpService(['isMultisite' => false, 'removeFilter' => true]);
$filter = new AllowPostsFromOtherSitesToKeepTheirPermalinks($wpService);
$filter = new SUT($wpService);

$this->assertEquals('permalink', $filter->getPermalinkFromOtherSite('permalink', WpMockFactory::createWpPost()));
}
Expand All @@ -41,10 +42,10 @@ public function testGetPermalinkFromOtherSiteReturnsPermalinkIfSiteIsSameAsCurre
'isMultisite' => true,
'getCurrentBlogId' => 1,
'getBlogIdFromUrl' => 1,
'removeFilter' => true,
'addFilter' => true,
'removeFilter' => true,
'addFilter' => true,
]);
$filter = new AllowPostsFromOtherSitesToKeepTheirPermalinks($wpService);
$filter = new SUT($wpService);

$post = WpMockFactory::createWpPost(['guid' => 'http://example.com/path']);
$this->assertEquals('permalink', $filter->getPermalinkFromOtherSite('permalink', $post));
Expand All @@ -66,7 +67,7 @@ public function testGetPermalinkFromOtherSiteReturnsPermalinkFromOtherSite()
'removeFilter' => true,
'addFilter' => true,
]);
$filter = new AllowPostsFromOtherSitesToKeepTheirPermalinks($wpService);
$filter = new SUT($wpService);

$post = WpMockFactory::createWpPost(['ID' => 1, 'guid' => $url]);
$this->assertEquals($url, $filter->getPermalinkFromOtherSite('permalink', $post));
Expand All @@ -88,7 +89,7 @@ public function testGetPermalinkFromOtherSiteAllowsSwitchingToDifferentTypesOfUr
'removeFilter' => true,
'addFilter' => true,
]);
$filter = new AllowPostsFromOtherSitesToKeepTheirPermalinks($wpService);
$filter = new SUT($wpService);

$post = WpMockFactory::createWpPost(['ID' => 1, 'guid' => $url]);
$filter->getPermalinkFromOtherSite('permalink', $post);
Expand Down

0 comments on commit 4fc2ed3

Please sign in to comment.