COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
- Image is preloaded using the image URLs
from srcset attribute and becomes imagesrcset
- sizes="50vw" attribute is moved to the
preload markup and becomes imagesizes="50vw"
- fetchpriority="high" is added to the
preload markup
- Image is excluded from LL feature
24/04/2024
COQUARD Cyrille
GIVEN image with srcset "http://my-image.example/img.png"
WHEN the image is preloaded
THEN image have imagesrcset "http://my-image.example/img.png"
AND no srcset
GIVEN image with sizes "50vw"
WHEN the image is preloaded
THEN image have imagesizes "50vw"
AND no sizes
GIVEN an image
WHEN the image is preloaded
THEN image have fetchpriority "high"
GIVEN an image
WHEN the image is preloaded
THEN image is excluded from lazyload
24/04/2024
COQUARD Cyrille
GIVEN image with srcset "http://my-image.example/img.png"
WHEN the image is preloaded
THEN image have imagesrcset "http://my-image.example/img.png"
AND no srcset
GIVEN image with sizes "50vw"
WHEN the image is preloaded
THEN image have imagesizes "50vw"
AND no sizes
GIVEN an image
WHEN the image is preloaded
THEN image have fetchpriority "high"
GIVEN an image
WHEN the image is preloaded
THEN image is excluded from lazyload
24/04/2024
COQUARD Cyrille
<?php
class Test_Logout extends TestCase {
public function testLogoutShouldNotEdit()
{
do_action(
'grant_admin',
wp_current_user()
);
do_action('logout');
$this->assertSame(
false,
apply_filters(
'user_can_edit',
false
)
);
}
}
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
Need to re-implement a way to interact with the element for each test
Use action and filter to cut your logic into small units
24/04/2024
COQUARD Cyrille
Use action and filter to cut your logic into small units
<?php
class Test_Logout extends TestCase {
public function testLogoutShouldNotEdit()
{
do_action(
'grant_admin',
wp_current_user()
);
do_action('logout');
$this->assertSame(
false,
apply_filters(
'user_can_edit',
false
)
);
}
}
24/04/2024
COQUARD Cyrille
Need control flow to direct the test into a certain state
Mock the filter with a callback function
24/04/2024
COQUARD Cyrille
Mock the filter with a callback function
<?php
class Test_Logout extends TestCase {
public function testLogoutShouldNotEdit()
{
...
}
/**
* @hook my_filter 10
*/
public function my_callback() {
return true;
}
}
24/04/2024
COQUARD Cyrille
The code call an external API and there is no control about it
Use wp_remote_request and mock the filter with a callback function
24/04/2024
COQUARD Cyrille
Use wp_remote_request and mock the filter with a callback function
<?php
class Test_Logout extends TestCase {
public function testLogoutShouldNotEdit()
{
...
}
/**
* @hook pre_http_request 10
*/
public function my_callback($response, $args, $url) {
if (
strpos(
$url,
'https://app.imagify.io' ) === false
) {
return $response;
}
return [
'body' => $message,
'response' => ['code' => 200 ]
];
}
}
24/04/2024
COQUARD Cyrille
The callback to test is linked to an hook with lot of callbacks making lot of noise
Isolate the callback by removing all other callbacks
24/04/2024
COQUARD Cyrille
Isolate the callback by removing all other callbacks
<?php
class Test_Logout extends TestCase {
/**
* @isolate-hook my-event myCallback 15
**/
public function testLogoutShouldNotEdit()
{
// ...
}
}
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
24/04/2024
COQUARD Cyrille
GIVEN no tracking row WHEN job added to Sauron THEN tracking job should be pending AND a job should be created to check result
GIVEN tracking row WHEN job added to Sauron THEN tracking job should be updated to pending AND a job should be created to check result
24/04/2024
COQUARD Cyrille
GIVEN no tracking row WHEN job fails to be added to Sauron THEN tracking job should be failed AND no job should be created to check result
24/04/2024
COQUARD Cyrille
Fail add API:
5xx
4xx
Fail add db
24/04/2024
COQUARD Cyrille
GIVEN no tracking row and no job WHEN job fetched from Sauron THEN tracking job should be failed
GIVEN tracking row and no job WHEN job fetch from Sauron THEN tracking job should be updated to failed
24/04/2024
COQUARD Cyrille
GIVEN no tracking row and job pending WHEN job fetched from Sauron THEN tracking job should be pending and a new job should be created
24/04/2024
COQUARD Cyrille
24/04/2024