diff --git a/src/Entities/Account.php b/src/Entities/Account.php index 0c2dfbd..1c81e6e 100644 --- a/src/Entities/Account.php +++ b/src/Entities/Account.php @@ -116,12 +116,12 @@ class Account extends ArrayCollection public function getAccessRights(): ArrayCollection { - return $this->get(AccountEndpoint::ACCESS_RIGHTS); + return new ArrayCollection($this->get(AccountEndpoint::ACCESS_RIGHTS)); } public function getSenders(): ArrayCollection { - return $this->get(AccountEndpoint::SENDERS); + return new ArrayCollection($this->get(AccountEndpoint::SENDERS)); } public function getGmailPreview(): string @@ -131,17 +131,17 @@ class Account extends ArrayCollection public function getLimits(): ArrayCollection { - return $this->get(AccountEndpoint::LIMITS); + return new ArrayCollection($this->get(AccountEndpoint::LIMITS)); } public function getPreferences(): ArrayCollection { - return $this->get(AccountEndpoint::PREFERENCES); + return new ArrayCollection($this->get(AccountEndpoint::PREFERENCES)); } public function getSettings(): ArrayCollection { - return $this->get(AccountEndpoint::SETTINGS); + return new ArrayCollection($this->get(AccountEndpoint::SETTINGS)); } public function canShowOtherAccountInfo(): bool @@ -156,7 +156,7 @@ class Account extends ArrayCollection public function getSupport(): ArrayCollection { - return $this->get(AccountEndpoint::SUPPORT); + return new ArrayCollection($this->get(AccountEndpoint::SUPPORT)); } public function getLanguage(): string @@ -166,22 +166,22 @@ class Account extends ArrayCollection public function getSegments(): ArrayCollection { - return $this->get(AccountEndpoint::SEGMENTS); + return new ArrayCollection($this->get(AccountEndpoint::SEGMENTS)); } public function getCustomerData(): ArrayCollection { - return $this->get(AccountEndpoint::CUSTOMER_DATA); + return new ArrayCollection($this->get(AccountEndpoint::CUSTOMER_DATA)); } public function getSubscriptionInfo(): ArrayCollection { - return $this->get(AccountEndpoint::SUBSCRIPTION_INFO); + return new ArrayCollection($this->get(AccountEndpoint::SUBSCRIPTION_INFO)); } public function getActivePayments(): ArrayCollection { - return $this->get(AccountEndpoint::ACTIVE_PAYMENTS); + return new ArrayCollection($this->get(AccountEndpoint::ACTIVE_PAYMENTS)); } /** diff --git a/tests/unit/Entities/AccountTest.php b/tests/unit/Entities/AccountTest.php index 0692c52..9321e7a 100644 --- a/tests/unit/Entities/AccountTest.php +++ b/tests/unit/Entities/AccountTest.php @@ -18,6 +18,9 @@ namespace D3\KlicktippPhpClient\tests\unit\Entities; use D3\KlicktippPhpClient\Entities\Account; use D3\KlicktippPhpClient\Resources\Account as AccountEndpoint; use D3\KlicktippPhpClient\tests\TestCase; +use Doctrine\Common\Collections\ArrayCollection; +use Generator; +use PHPUnit\Framework\MockObject\Rule\InvokedCount; use ReflectionException; /** @@ -60,7 +63,7 @@ class AccountTest extends TestCase ], AccountEndpoint::SENDERS => [ "email" => [ - "myemail@mydomain.com" => "myemail@mydomain.com (ohne DKIM Signatur – eingeschränkte Zustellbarkeit)", + "myemail@mydomain.com" => "myemail@mydomain.com (ohne DKIM Signatur � eingeschr�nkte Zustellbarkeit)", ], "reply_email" => [ "myemail@mydomain.com" => "myemail@mydomain.com", @@ -184,4 +187,211 @@ class AccountTest extends TestCase $this->getValue($sut, 'endpoint') ); } + + /** + * @test + * @throws ReflectionException + * @covers \D3\KlicktippPhpClient\Entities\Account::getId + * @covers \D3\KlicktippPhpClient\Entities\Account::getStatus + * @covers \D3\KlicktippPhpClient\Entities\Account::getTier + * @covers \D3\KlicktippPhpClient\Entities\Account::getUsergroup + * @covers \D3\KlicktippPhpClient\Entities\Account::getEmail + * @covers \D3\KlicktippPhpClient\Entities\Account::getFirstname + * @covers \D3\KlicktippPhpClient\Entities\Account::getLastname + * @covers \D3\KlicktippPhpClient\Entities\Account::getCompany + * @covers \D3\KlicktippPhpClient\Entities\Account::getWebsite + * @covers \D3\KlicktippPhpClient\Entities\Account::getStreet + * @covers \D3\KlicktippPhpClient\Entities\Account::getCity + * @covers \D3\KlicktippPhpClient\Entities\Account::getState + * @covers \D3\KlicktippPhpClient\Entities\Account::getZIP + * @covers \D3\KlicktippPhpClient\Entities\Account::getCountry + * @covers \D3\KlicktippPhpClient\Entities\Account::getPhone + * @covers \D3\KlicktippPhpClient\Entities\Account::getFax + * @covers \D3\KlicktippPhpClient\Entities\Account::getAffiliateId + * @covers \D3\KlicktippPhpClient\Entities\Account::getAccessRights + * @covers \D3\KlicktippPhpClient\Entities\Account::getSenders + * @covers \D3\KlicktippPhpClient\Entities\Account::getGmailPreview + * @covers \D3\KlicktippPhpClient\Entities\Account::getLimits + * @covers \D3\KlicktippPhpClient\Entities\Account::getPreferences + * @covers \D3\KlicktippPhpClient\Entities\Account::getSettings + * @covers \D3\KlicktippPhpClient\Entities\Account::canShowOtherAccountInfo + * @covers \D3\KlicktippPhpClient\Entities\Account::canShowSupportInfo + * @covers \D3\KlicktippPhpClient\Entities\Account::getSupport + * @covers \D3\KlicktippPhpClient\Entities\Account::getLanguage + * @covers \D3\KlicktippPhpClient\Entities\Account::getSegments + * @covers \D3\KlicktippPhpClient\Entities\Account::getCustomerData + * @covers \D3\KlicktippPhpClient\Entities\Account::getSubscriptionInfo + * @covers \D3\KlicktippPhpClient\Entities\Account::getActivePayments + * @dataProvider getDataProvider + */ + public function testGet(string $testMethod, $exepcted): void + { + $this->assertEquals( + $exepcted, + $this->callMethod( + $this->entity, + $testMethod, + ) + ); + } + + public static function getDataProvider(): Generator + { + yield ['getId', '1094633']; + yield ['getStatus', "1"]; + yield ['getTier', 10000]; + yield ['getUsergroup', "16"]; + yield ['getEmail', "myemail@mydomain.com"]; + yield ['getFirstname', "John"]; + yield ['getLastname', "Doe"]; + yield ['getCompany', "ShopCompany"]; + yield ['getWebsite', "https://mywebsite.com"]; + yield ['getStreet', "Unter den Linden 20"]; + yield ['getCity', "Berlin"]; + yield ['getState', ""]; + yield ['getZIP', "01100"]; + yield ['getCountry', "DE"]; + yield ['getPhone', ""]; + yield ['getFax', ""]; + yield ['getAffiliateId', "197030"]; + yield ['getAccessRights', new ArrayCollection([ + "administer klicktipp" => false, + "access facebook audience" => false, + "access translation translater" => false, + "access translation admin" => false, + "use whitelabel domain" => false, + "access email editor" => true, + "access user segments" => false, + "access feature limiter" => true, + ])]; + yield ['getSenders', new ArrayCollection([ + "email" => [ + "myemail@mydomain.com" => "myemail@mydomain.com (ohne DKIM Signatur � eingeschr�nkte Zustellbarkeit)", + ], + "reply_email" => [ + "myemail@mydomain.com" => "myemail@mydomain.com", + ], + "sms" => [], + "defaultEmail" => "myemail@mydomain.com", + "defaultReplyEmail" => "myemail@mydomain.com", + "domains" => [], + "providers" => [], + "previewEmails" => [], + ])]; + yield ['getGmailPreview', "gmail-inspector@klick-tipp.team"]; + yield ['getLimits', new ArrayCollection([ + "automation" => "10", + "statistics" => "5", + ])]; + yield ['getPreferences', new ArrayCollection([ + "colors" => [ + "start" => "yellow-dark", + "decision" => "violet-dark", + "goal" => "", + "goto" => "violet-dark", + "wait" => "", + "start automation" => "yellow-dark", + "stop automation" => "pink-dark", + "exit" => "pink-dark", + "restart" => "pink-dark", + "email" => "blue-dark", + "sms" => "blue-dark", + "notify by email" => "blue-dark", + "notify by sms" => "blue-dark", + "outbound" => "blue-dark", + "facebook audience add" => "blue-dark", + "tagging" => "green-dark", + "untagging" => "pink-dark", + "unsubscribe" => "pink-dark", + "setfield" => "green-dark", + "detect name" => "green-dark", + "detect gender" => "green-dark", + "fullcontact" => "green-dark", + ], + ])]; + yield ['getSettings', new ArrayCollection([ + "PlainTextContentByUser" => 0, + ])]; + yield ['canShowOtherAccountInfo', false]; + yield ['canShowSupportInfo', false]; + yield ['getSupport', new ArrayCollection([ + "username" => "klicktipp_account_username", + "switchAccountsLink" => [ + "href" => "https://app.klicktipp.com/user/me/subaccount/switch", + "title" => "Unterkonto wechseln", + ], + ])]; + yield ['getLanguage', "de"]; + yield ['getSegments', new ArrayCollection([])]; + yield ['getCustomerData', new ArrayCollection([ + "isActive" => true, + "email" => "myemail@mydomain.com", + "firstName" => "John", + "lastName" => "Doe", + "zipcode" => "01100", + "city" => "Berlin", + "street" => "Unter den Linden 20", + "country" => "DE", + "company" => "ShopCompany", + "product" => "KlickTipp Deluxe 10.000", + "order_id" => "", + "weight" => "1010", + "tier" => "10000", + "period" => 67, + "digistore_affiliate_name" => "", + "tracking_pixels" => "", + "apikeys" => false, + "subscriber_key" => "3xtlh8zavzz04zdc45", + "addOns" => [], + ])]; + yield ['getSubscriptionInfo', new ArrayCollection([ + "category" => "Account Platinum", + "tier" => "10000", + "term" => "monatlich", + "period" => 67, + "productID" => "107", + "title" => "KlickTipp Deluxe 10.000", + "weight" => "1010", + "orderID" => "", + "machineCategory" => "klick-tipp-account-platinum", + "emailAddress" => "myemail@mydomain.com", + "groupId" => "16", + "aMemberId" => "179045", + ])]; + yield ['getActivePayments', new ArrayCollection()]; + } + + /** + * @test + * @throws ReflectionException + * @covers \D3\KlicktippPhpClient\Entities\Account::persist + * @dataProvider persistDataProvider + */ + public function testPersist( + bool $endpointSet, + InvokedCount $endpointInvocation, + ?bool $expectedReturn + ): void { + $endpointMock = $this->getMockBuilder(AccountEndpoint::class) + ->disableOriginalConstructor() + ->onlyMethods(['update']) + ->getMock(); + $endpointMock->expects($endpointInvocation)->method('update')->willReturn(true); + + $sut = new Account([AccountEndpoint::UID => 'foo'], $endpointSet ? $endpointMock : null); + + $this->assertSame( + $expectedReturn, + $this->callMethod( + $sut, + 'persist' + ) + ); + } + + public static function persistDataProvider(): Generator + { + yield 'has endpoint' => [true, self::once(), true]; + yield 'has no endpoint' => [false, self::never(), null]; + } } diff --git a/tests/unit/Entities/SubscriberTest.php b/tests/unit/Entities/SubscriberTest.php index 0ef958d..7adbe57 100644 --- a/tests/unit/Entities/SubscriberTest.php +++ b/tests/unit/Entities/SubscriberTest.php @@ -246,6 +246,7 @@ class SubscriberTest extends TestCase yield 'null' => [null, null]; yield 'valid date' => ['2024-12-24', new DateTime('2024-12-24')]; yield 'valid date time' => ['28.12.2024 22:52:09', new DateTime('2024-12-28 22:52:09')]; + yield 'invalid date time' => ['half-life 3 release date', null]; yield 'invalid' => ['', null]; }