Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Croct.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,22 @@ final class Croct implements Plug

private CookieConfiguration $cookieConfiguration;

private bool $debug;

private function __construct(
string $appId,
Session $session,
Evaluator $evaluator,
ContentFetcher $contentFetcher,
CookieConfiguration $cookieConfiguration,
bool $debug,
) {
$this->appId = $appId;
$this->session = $session;
$this->evaluator = $evaluator;
$this->contentFetcher = $contentFetcher;
$this->cookieConfiguration = $cookieConfiguration;
$this->debug = $debug;
}

/**
Expand All @@ -73,6 +77,7 @@ public static function plug(
?IdentityResolver $identity = null,
?string $baseEndpointUrl = null,
int $tokenDuration = self::DEFAULT_TOKEN_DURATION,
bool $debug = false,
?ContentProvider $contentProvider = null,
?RequestContext $context = null,
?HttpClient $httpClient = null,
Expand Down Expand Up @@ -126,6 +131,7 @@ public static function plug(
$contentProvider ?? self::discoverContentProvider(),
),
$cookieConfiguration,
$debug,
);
}

Expand Down Expand Up @@ -250,11 +256,17 @@ public function getUserToken(): Token
*/
public function getPlugOptions(): array
{
return [
$options = [
'appId' => $this->appId,
'disableCidMirroring' => true,
'cookie' => $this->cookieConfiguration->toBrowserCookies(),
];

if ($this->debug) {
$options['debug'] = true;
}

return $options;
}

/**
Expand Down
13 changes: 12 additions & 1 deletion tests/CroctTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ public function testExposesPlugOptions(): void
);
}

#[TestDox('Forwards the debug flag to the browser plug options when enabled.')]
public function testForwardsDebugToPlugOptions(): void
{
$enabled = $this->createCroct(new MockClient(), debug: true);
$disabled = $this->createCroct(new MockClient());

self::assertTrue($enabled->getPlugOptions()['debug'] ?? null);
self::assertArrayNotHasKey('debug', $disabled->getPlugOptions());
}

#[TestDox('Fetches slot content with the resolved session.')]
public function testFetchContentUsesResolvedSession(): void
{
Expand Down Expand Up @@ -380,7 +390,7 @@ public function testEmitsCookiesFromGlobalStorage(): void
self::assertSame(self::CLIENT_ID, $emitted['ct_client_id'] ?? null);
}

private function createCroct(MockClient $client, ?IdentityStore $storage = null): Plug
private function createCroct(MockClient $client, ?IdentityStore $storage = null, bool $debug = false): Plug
{
$factory = new Psr17Factory();
$storage ??= new InMemoryIdentityStore();
Expand All @@ -389,6 +399,7 @@ private function createCroct(MockClient $client, ?IdentityStore $storage = null)
appId: self::APP_ID,
apiKey: ApiKey::of(EcKeyFactory::IDENTIFIER),
storage: $storage,
debug: $debug,
context: new RequestContext(),
httpClient: $client,
requestFactory: $factory,
Expand Down
Loading