From 4e594d64174a47a77ae35648161c5ac004f7b148 Mon Sep 17 00:00:00 2001 From: Claudio-Emmolo Date: Wed, 30 Aug 2023 11:23:44 +0200 Subject: [PATCH] Add and make tests for ebay --- src/ReferralRewriterTag.php | 10 ++++++ tests/EbayRewriterTest.php | 71 +++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 tests/EbayRewriterTest.php diff --git a/src/ReferralRewriterTag.php b/src/ReferralRewriterTag.php index 1181a38..8c9bb07 100755 --- a/src/ReferralRewriterTag.php +++ b/src/ReferralRewriterTag.php @@ -23,6 +23,7 @@ public function rewrite(string $link, ?string $tag, ?string $subtag, ?string $ad return match ($this->retrieveTheDomainType()) { 'amazon' => $this->rewriteAmazonLink(), 'instant-gaming' => $this->rewriteInstantGamingLink(), + 'ebay' => $this->rewriteEbayLink(), default => $this->link, }; } @@ -43,6 +44,15 @@ public function rewriteInstantGamingLink() : string return $this->rewriteLink(tagKey: 'igr', subTagKey: 'igr_extra'); } + /** + * Rewrite ebay link with tag and subtag + */ + public function rewriteEbayLink() : string + { + return $this->rewriteLink(tagKey: 'campid', subTagKey: 'customid'); + } + + /** * Retrieve the domain type */ diff --git a/tests/EbayRewriterTest.php b/tests/EbayRewriterTest.php new file mode 100644 index 0000000..1c8fa7f --- /dev/null +++ b/tests/EbayRewriterTest.php @@ -0,0 +1,71 @@ +toBe('https://www.ebay.it/itm/172031349215?campid=mytag-20'); +}); + +it('can write ebay link with tag and subtag', function () { + $link = 'https://www.ebay.it/itm/172031349215'; + $tag = 'mytag-20'; + $subtag = 'customsub'; + + $rewrittenLink = ReferralRewriterTag::rewrite($link, $tag, $subtag); + expect($rewrittenLink)->toBe('https://www.ebay.it/itm/172031349215?campid=mytag-20&customid=customsub'); +}); + +it('can write ebay link with tag, subtag and additional query', function () { + $link = 'https://www.ebay.it/itm/172031349215'; + $tag = 'mytag-20'; + $subtag = 'customsub'; + $additionalQuery = '&addquery=myogi'; + + $rewrittenLink = ReferralRewriterTag::rewrite($link, $tag, $subtag, $additionalQuery); + expect($rewrittenLink)->toBe('https://www.ebay.it/itm/172031349215?campid=mytag-20&customid=customsub&addquery=myogi'); +}); + +it('can rewrite ebay link with tag', function () { + $link = 'https://www.ebay.it/itm/172031349215?campid=5337692837&customid=11994'; + $tag = 'mytag-20'; + + $rewrittenLink = ReferralRewriterTag::rewrite($link, $tag, null); + expect($rewrittenLink)->toBe('https://www.ebay.it/itm/172031349215?campid=mytag-20&customid=11994'); +}); + +it('can rewrite ebay link with subtag', function () { + $link = 'https://www.ebay.it/itm/172031349215?campid=5337692837&customid=11994'; + $subtag = 'customsub'; + + $rewrittenLink = ReferralRewriterTag::rewrite($link, null, $subtag); + expect($rewrittenLink)->toBe('https://www.ebay.it/itm/172031349215?campid=5337692837&customid=customsub'); +}); + +it('can rewrite ebay link with tag and subtag', function () { + $link = 'https://www.ebay.it/itm/172031349215?campid=5337692837&customid=11994'; + $tag = 'mytag-20'; + $subtag = 'customsub'; + + $rewrittenLink = ReferralRewriterTag::rewrite($link, $tag, $subtag); + expect($rewrittenLink)->toBe('https://www.ebay.it/itm/172031349215?campid=mytag-20&customid=customsub'); +}); + +it('can rewrite full ebay link with tag ans subtag', function () { + $link = 'https://www.ebay.it/itm/172031349215?mkevt=1&mkcid=1&mkrid=724-53478-19255-0&campid=5337692837&customid=11994&toolid=10050'; + $tag = 'mytag-20'; + $subtag = 'customsub'; + + $rewrittenLink = ReferralRewriterTag::rewrite($link, $tag, $subtag); + expect($rewrittenLink)->toBe('https://www.ebay.it/itm/172031349215?mkevt=1&mkcid=1&mkrid=724-53478-19255-0&campid=mytag-20&customid=customsub&toolid=10050'); +}); + +it('can rewrite ebay link without tag and subtag', function () { + $link = 'https://www.ebay.it/itm/172031349215?campid=5337692837&customid=11994'; + + $rewrittenLink = ReferralRewriterTag::rewrite($link, null, null); + expect($rewrittenLink)->toBe('https://www.ebay.it/itm/172031349215?campid=5337692837&customid=11994'); +});