Skip to content

Commit

Permalink
Test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoli79 committed Feb 4, 2025
1 parent a754379 commit f09204c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 63 deletions.
82 changes: 44 additions & 38 deletions tests/CPClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,34 +275,40 @@ public function testRevokeTokenBadResponse(): void

public function testGetUser(): void
{
$handler = $this->createMockResponse(200, '{
"data": {
"userIdentity": {
"id": 12345,
"activeContact": {
"id": 263425,
"firstName": "Alice",
"lastName": "Bob",
"email": "[email protected]",
"isWptPaidUser": true,
"isWptAccountVerified": true,
"companyName": null
},
"levelSummary": {
"levelId": 3,
"isWptEnterpriseClient": false
$handler = $this->createMockResponse(
200,
'{
"data": {
"userIdentity": {
"id": 12345,
"activeContact": {
"id": 263425,
"firstName": "Alice",
"lastName": "Bob",
"email": "[email protected]",
"isWptPaidUser": true,
"isWptAccountVerified": true,
"companyName": null
},
"levelSummary": {
"levelId": 3,
"isWptEnterpriseClient": false
}
},
"wptCustomer": {
"remainingRuns": 300,
"monthlyRuns": 3000,
"subscriptionId": "518235",
"planRenewalDate": "2125-12-25",
"status": "ACTIVE",
"vatNumber": null
},
"wptIsPreviewEnabled": {
"enabled": false
}
}
},
"wptCustomer": {
"remainingRuns": 300,
"monthlyRuns": 3000,
"subscriptionId": "518235",
"planRenewalDate": "2125-12-25",
"status": "ACTIVE",
"vatNumber": null
}
}
}');
}'
);
$host = "http://webpagetest.org";
$client = new CPClient($host, array(
'auth_client_options' => [
Expand Down Expand Up @@ -513,18 +519,18 @@ public function testGetWptPlans(): void
}
}');

$host = "http://webpagetest.org";
$client = new CPClient($host, array(
'auth_client_options' => [
'client_id' => '123',
'client_secret' => '345',
'grant_type' => 'these are good to have',
'handler' => $handler
]
));
$host = "http://webpagetest.org";
$client = new CPClient($host, array(
'auth_client_options' => [
'client_id' => '123',
'client_secret' => '345',
'grant_type' => 'these are good to have',
'handler' => $handler
]
));

$plans = $client->getWptPlans();
$this->assertEquals(3, count($plans));
$plans = $client->getWptPlans();
$this->assertEquals(3, count($plans));
}


Expand Down
2 changes: 1 addition & 1 deletion tests/RequestContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public function testSetGetClient(): void
$client = new CPClient($host);
$request = new RequestContext($global_req);
$request->setClient($client);
$this->assertEquals($host, $request->getClient()->host);
$this->assertEquals($host, $request->getClient()->getHost());
}
}
51 changes: 28 additions & 23 deletions www/src/CPClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public function isAuthenticated(): bool
return !!$this->access_token;
}

public function getHost(): ?string
{
return $this->host;
}

public function login(string $code, string $code_verifier, string $redirect_uri): AuthToken
{
if (is_null($this->client_id) || is_null($this->client_secret)) {
Expand Down Expand Up @@ -316,19 +321,19 @@ public function getFullWptPlanSet(): PlanListSet
return new Plan($options);
}, $results->getData()['wptPlan'] ?? []);

$current_plans = array_filter($all_plans, function (Plan $plan) {
/** This is a bit of a hack for now. These are our approved plans for new
* customers to be able to use. We will better handle this from the backend
* */
return strtolower($plan->getId()) == 'ap5' ||
strtolower($plan->getId()) == 'ap6' ||
strtolower($plan->getId()) == 'ap7' ||
strtolower($plan->getId()) == 'ap8' ||
strtolower($plan->getId()) == 'mp5' ||
strtolower($plan->getId()) == 'mp6' ||
strtolower($plan->getId()) == 'mp7' ||
strtolower($plan->getId()) == 'mp8';
});
$current_plans = array_filter($all_plans, function (Plan $plan) {
/** This is a bit of a hack for now. These are our approved plans for new
* customers to be able to use. We will better handle this from the backend
* */
return strtolower($plan->getId()) == 'ap5' ||
strtolower($plan->getId()) == 'ap6' ||
strtolower($plan->getId()) == 'ap7' ||
strtolower($plan->getId()) == 'ap8' ||
strtolower($plan->getId()) == 'mp5' ||
strtolower($plan->getId()) == 'mp6' ||
strtolower($plan->getId()) == 'mp7' ||
strtolower($plan->getId()) == 'mp8';
});
$set = new PlanListSet();
$set->setAllPlans(new PlanList(...$all_plans));
$set->setCurrentPlans(new PlanList(...$current_plans));
Expand Down Expand Up @@ -1070,18 +1075,18 @@ public function updatePlan(string $subscription_id, string $next_plan_handle, bo
public function updatePaymentMethod(string $token, ShippingAddress $address): bool
{
$gql = (new Mutation('wptUpdateSubscriptionPayment'))
->setVariables([
new Variable('paymentToken', 'String', true),
new Variable('shippingAddress', 'ChargifyAddressInputType', true)
])
->setArguments([
'paymentToken' => '$paymentToken',
'shippingAddress' => '$shippingAddress'
]);
->setVariables([
new Variable('paymentToken', 'String', true),
new Variable('shippingAddress', 'ChargifyAddressInputType', true)
])
->setArguments([
'paymentToken' => '$paymentToken',
'shippingAddress' => '$shippingAddress'
]);

$variables = [
'paymentToken' => $token,
'shippingAddress' => $address->toArray()
'paymentToken' => $token,
'shippingAddress' => $address->toArray()
];

$results = $this->graphql_client->runQuery($gql, true, $variables);
Expand Down
2 changes: 1 addition & 1 deletion www/templates/layouts/includes/wpt-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function addTab($tabName, $tabUrl, $addClass = '')
$is_logged_in = Util::getSetting('cp_auth') && (!is_null($request_context)) && (!is_null($request_context->getClient()) && $request_context->getClient()->isAuthenticated());
$user = !is_null($request_context) ? $request_context->getUser() : null;

if ($request_context->isReadOnly()) {
if (isset($request_context) && $request_context->isReadOnly()) {

?>
<wpt-header style='margin-bottom: -1rem;'>
Expand Down

0 comments on commit f09204c

Please sign in to comment.