{"id":5389,"date":"2023-06-26T09:23:03","date_gmt":"2023-06-26T14:23:03","guid":{"rendered":"https:\/\/wpengine.com\/builders\/?p=5389"},"modified":"2023-07-20T09:11:57","modified_gmt":"2023-07-20T14:11:57","slug":"wpgraphql-testcase-guide","status":"publish","type":"post","link":"https:\/\/wpengine.com\/builders\/wpgraphql-testcase-guide\/","title":{"rendered":"WPGraphQL TestCase Guide"},"content":{"rendered":"\n<p>WPGraphQL TestCase is a library of tools for testing WPGraphQL APIs along with its additional extensions.&nbsp; With this library, developers can write test cases that simulate different scenarios and interactions with their plugin. By arranging the test environment, acting on the plugin&#8217;s functionality, and asserting the expected outcomes, developers can validate that their code works as intended.<\/p>\n\n\n\n<p>Special thanks to <a href=\"https:\/\/github.com\/kidunot89\">Geoff Taylor<\/a> for creating the library!<\/p>\n\n\n\n<p>In this article, I will discuss its implementation and usage when developing custom extensions within WPGraphQL.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Getting Started<\/h2>\n\n\n\n<p>The prerequisites you need are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A WP install. I used <a href=\"https:\/\/wpengine.com\/local\/\">Local<\/a> for this one<\/li>\n\n\n\n<li>Composer&nbsp;<\/li>\n\n\n\n<li>Docker (To follow this specific tutorial) to run tests locally and in environments like GitHub Actions or Circle CI<\/li>\n<\/ul>\n\n\n\n<p><strong>Note<\/strong>: If you do choose to clone down my repo, do not forget to change all the instances from my WPGraphQL plugin name to yours.&nbsp; The only files that I will be walking through are the extension I am writing in this tutorial to test with the TestCase library file helper.&nbsp; I am not going to go over the boilerplate.<\/p>\n\n\n\n<p>Step 1: Spin up a WordPress install on any platform you are using for hosting.<\/p>\n\n\n\n<p>Step 2: Get a docker container running.&nbsp; This will allow you to run the WPGraphQL test within the TestCase library and your local machine.&nbsp; In my walkthrough, Docker is running and contains the <code>PHP<\/code> files from WordPress. If you need a guide to do this, <a href=\"https:\/\/wpengine.com\/resources\/containers-clusters-wordpress\/\">please reference it here<\/a>.<\/p>\n\n\n\n<p>Step 3: Install the Composer dependency manager for <code>PHP<\/code>. The composer <a href=\"https:\/\/getcomposer.org\/doc\/00-intro.md#installation-linux-unix-macos\">installation guide can be found here<\/a>.<\/p>\n\n\n\n<p>Step 4:&nbsp; Install WPGraphQL TestCase via the<a href=\"https:\/\/github.com\/wp-graphql\/wp-graphql-testcase\"> GitHub repository instructions<\/a> or you can clone down the <a href=\"https:\/\/github.com\/Fran-A-Dev\/wpgraphql-testcase\">boilerplate repository<\/a> I made and go from there.<\/p>\n\n\n\n<p>Once the steps to scaffold are complete, we now can write and test our code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Custom WPGraphQL Extension<\/strong><\/h2>\n\n\n\n<p>The file for my plugin lives in <code>\/plugins\/wpgraphql-testcase.php<\/code>.<\/p>\n\n\n\n<p>The test directory is where we contain and store our test files with WPGraphQL TestCase.<\/p>\n\n\n\n<p>The first extension we want to write is a dummy extension to ensure the test library is working and we fail something on purpose and then correct it to pass.&nbsp; This is <code>php<\/code> code that executes a function to return a string of <code>\"Hello World\" <\/code>every time there is a query for <code>franField<\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-code-table shcb-line-numbers\"><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\">\/**<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\">* Plugin Name: WPGraphQL Test Case<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\">* Description: Test Plugin for a custom field in WPGraphQL to test with TestCase lib<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\">* Version: 0.1.0<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\">* Author: Fran Agulto<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\">* License: GPLv2 or later<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\">* License URI: http:\/\/www.developers.wpengine.com<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\">*\/<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\">add_action(<span class=\"hljs-string\">'graphql_register_types'<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span><span class=\"hljs-params\">()<\/span><\/span>{<\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\">   register_graphql_field(<span class=\"hljs-string\">'RootQuery'<\/span>, <span class=\"hljs-string\">'franField'<\/span>,&#91;<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\">       <span class=\"hljs-string\">'type'<\/span>=&gt; <span class=\"hljs-string\">'String'<\/span>,<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\">       <span class=\"hljs-string\">'resolve'<\/span>=&gt; <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span><span class=\"hljs-params\">()<\/span> <\/span>{<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\"><span class=\"hljs-function\">           <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-string\">'Stoked!!! Hello Stoked World!'<\/span>;<\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\"><span class=\"hljs-function\">       }<\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\"><span class=\"hljs-function\">   ]);<\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\"><span class=\"hljs-function\">});<\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\"><span class=\"hljs-function\"><\/span><\/span><\/span>\n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\"><strong>WPGraphQL TestCase Library<\/strong><\/h2>\n\n\n\n<p>Now that we have a dummy extension written, let\u2019s write out a test for it using WPGraphQL TestCase.<\/p>\n\n\n\n<p>At the root of the project, go to <code>test\/fran-field-test.php<\/code>.&nbsp; This file is where we will utilize the WPGraphQL TestCase library and its helper functions to test the extension we just wrote.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-code-table shcb-line-numbers\"><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">FranFieldTest<\/span> <span class=\"hljs-keyword\">extends<\/span> \\<span class=\"hljs-title\">Tests<\/span>\\<span class=\"hljs-title\">WPGraphQL<\/span>\\<span class=\"hljs-title\">TestCase<\/span>\\<span class=\"hljs-title\">WPGraphQLTestCase<\/span> <\/span>{<\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\">  <\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\">   <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">setUp<\/span><span class=\"hljs-params\">()<\/span>: <span class=\"hljs-title\">void<\/span> <\/span>{<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\">       <span class=\"hljs-keyword\">parent<\/span>::setUp();<\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\">   }<\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\">   <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">tearDown<\/span><span class=\"hljs-params\">()<\/span>: <span class=\"hljs-title\">void<\/span> <\/span>{<\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\">     <span class=\"hljs-keyword\">parent<\/span>::tearDown();<\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\">   }<\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\">   <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">testFranFields<\/span><span class=\"hljs-params\">()<\/span><\/span>{<\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\">    $title=<span class=\"hljs-string\">'Fran test post'<\/span>;<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\">    $post_id = <span class=\"hljs-keyword\">$this<\/span>-&gt;factory()-&gt;post-&gt;create(&#91;<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\">      <span class=\"hljs-string\">'Post_title'<\/span>=&gt;$title<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\">    ]);<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\">    $query = <span class=\"hljs-string\">'<\/span><\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-string\">    {<\/span><\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-string\">      recentPosts {<\/span><\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-string\">        nodes {<\/span><\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-string\">          __typename<\/span><\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-string\">          databaseId<\/span><\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-string\">          title<\/span><\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-string\">        }<\/span><\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-string\">      } <\/span><\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-string\">    }<\/span><\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-string\">    '<\/span>;<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\">    <span class=\"hljs-keyword\">$this<\/span>-&gt;graphql(&#91;<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\">      <span class=\"hljs-string\">'Query'<\/span>=&gt;$query<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\">    ])<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\">  ;<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\">    <span class=\"hljs-comment\">\/\/assertQuerySuccessful is a function that comes from WPGraphQL Test Case library<\/span><\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\">    <span class=\"hljs-comment\">\/\/expectedNode is a function from the library too that runs when you expect a certain node<\/span><\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\">    <span class=\"hljs-keyword\">self<\/span>::assertQuerySuccessful($actual, &#91;<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\">      <span class=\"hljs-keyword\">$this<\/span>-&gt;expectedField( <span class=\"hljs-string\">'__typename'<\/span>. <span class=\"hljs-string\">'Post'<\/span> ),<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\">      <span class=\"hljs-keyword\">$this<\/span>-&gt;expectedField( <span class=\"hljs-string\">'databaseId'<\/span>, $post_id ),<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\">      <span class=\"hljs-keyword\">$this<\/span>-&gt;expectedField( <span class=\"hljs-string\">'title'<\/span>, $title ),<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\">    ]);<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\">    <\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\">   }<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-class\"><span class=\"hljs-function\"><span class=\"hljs-function\"><span class=\"hljs-function\">}<\/span><\/span><\/span><\/span><\/span>\n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The first thing we need to do is declare a class and extend it to the WPGraphQL TestCase library which is what is happening at line one at the top of the file.<\/p>\n\n\n\n<p>Next, we open up an object and add the boilerplate functions for the test file to execute its library helpers.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-code-table shcb-line-numbers\"><span class='shcb-loc'><span>{\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>  \n<\/span><\/span><span class='shcb-loc'><span>   <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">setUp<\/span><span class=\"hljs-params\">()<\/span>: <span class=\"hljs-title\">void<\/span> <\/span>{\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>       <span class=\"hljs-keyword\">parent<\/span>::setUp();\n<\/span><\/span><span class='shcb-loc'><span>   }\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>   <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">tearDown<\/span><span class=\"hljs-params\">()<\/span>: <span class=\"hljs-title\">void<\/span> <\/span>{\n<\/span><\/span><span class='shcb-loc'><span>     <span class=\"hljs-keyword\">parent<\/span>::tearDown();\n<\/span><\/span><span class='shcb-loc'><span>   }\n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Arrange Our Conditions <\/h3>\n\n\n\n<p>The first step that is used for testing is arranging our conditions here which allows us to now write our customized test.&nbsp; On the next lines, we have a function called <code>testFranFields<\/code>.&nbsp; The <code>test<\/code> syntax is what makes a function named, run as a test.&nbsp;&nbsp;<\/p>\n\n\n\n<p>Following that, we have a variable that is the <code>title<\/code> which is<code> Fran test post<\/code>.&nbsp;&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Act-On The Function<\/h3>\n\n\n\n<p>What we need to do next is act on this with what is called a test <code>factory <\/code>which creates an actual post in WordPress for us with the <code>title<\/code> we chose.<\/p>\n\n\n\n<p>Once we have this factory creating the post, we now can make the GraphQL query which is a variable, we want against our WPGraphQL schema with the extended node that is <code>recentPosts<\/code> with its fields.&nbsp; The fields we are asking for are <code>databaseID, __typename, and title<\/code>. It is here that we want to assert that <code>Fran Test Post<\/code> is returned because it is equal to the most recent post and included in the response.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Assert <\/h3>\n\n\n\n<p>We execute the query on line 30, taking <code>$this<\/code> function as a variable in order to execute the GraphQL query.&nbsp; The last steps are to assert what we expect to happen.&nbsp; In order to do this, we use the <code>assertQuerySuccesful <\/code>function which is a helper from the WPGraphQL TestCase library.&nbsp; This allows us to check the query and ensure there are no errors. In this instance, we are passing in our GraphQL query as it executes.<\/p>\n\n\n\n<p>Next, we use the <code>expectedNode<\/code> function which is coming from WPGraphQL TestCase to declare what expected node we want to return.&nbsp; We pass in the path to assert it which is our <code>recentPosts<\/code>.<\/p>\n\n\n\n<p>Then in an array, we input and define what <code>node<\/code> should be and what <code>fields<\/code> it has.&nbsp; In this array, we have the <code>fields<\/code> we asked for in our query.<\/p>\n\n\n\n<p>This test is now built out.&nbsp; Let\u2019s run it and see what happens.&nbsp; In my terminal, I run <code>composer run-test<\/code>.<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/SeJXOdeVvV-6anNKxzyKru-NrikoIUI1cL_NFMisbNX1GlIN-RjlZ2LwIGYChEJloX8zE52PxGBQL9wPixmh9cuCH5gFxsEvqnSSySaHk3o6Dx-hSBmiDtBvjS2caOMNUftEyo1Dee01lDW6AZp2Kak\" width=\"624\" height=\"224\"><\/p>\n\n\n\n<p>This test failed because the functionality that I am testing is being tested against the wrong extension within my <code>php<\/code> file for WPGraphQL. Let\u2019s write an extension that will create a passing test.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Passing Test  For WPGraphQL Extension<\/strong><\/h2>\n\n\n\n<p>The current file at the root of my project&nbsp; that is making the test fail is this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-code-table shcb-line-numbers\"><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\">\/**<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\"> * Plugin Name: WPGraphQL Scratch Test <\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\"> * <\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\"> * <\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\"> *\/<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"> add_action(<span class=\"hljs-string\">'graphql_register_types'<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span><span class=\"hljs-params\">()<\/span><\/span>{<\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\">    register_graphql_field(<span class=\"hljs-string\">'RootQuery'<\/span>, <span class=\"hljs-string\">'franField'<\/span>,&#91;<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\">        <span class=\"hljs-string\">'type'<\/span>=&gt; <span class=\"hljs-string\">'String'<\/span>,<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\">        <span class=\"hljs-string\">'resolve'<\/span>=&gt; <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span><span class=\"hljs-params\">()<\/span> <\/span>{<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\"><span class=\"hljs-function\">            <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-string\">'Stoked!!! Hello Stoked World!'<\/span>;<\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\"><span class=\"hljs-function\">        }<\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\"><span class=\"hljs-function\">    ]);<\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\"><span class=\"hljs-function\"> });<\/span><\/span><\/span>\n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This is a function that returns a string of <code>\u201cStoked, Hello World\u201d<\/code> when <code>franField<\/code> type is queried.<\/p>\n\n\n\n<p>This does not match the function that we wrote in our TestCase file.&nbsp; Let\u2019s re-write the code to this extension so it passes.<\/p>\n\n\n\n<p>Here is the code block for the passing file:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-code-table shcb-line-numbers\"><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\">\/**<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\"> * Plugin Name: WPGraphQL Test Case<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\"> * Description: Test Plugin for a custom field in WPGraphQL to test with TestCase lib<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\"> * Version: 0.1.0<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\"> * Author: Fran Agulto<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\"> * License: GPLv2 or later<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\"> * License URI: http:\/\/www.developers.wpengine.com<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-comment\"> *\/<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"> add_action(<span class=\"hljs-string\">'graphql_register_types'<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span><span class=\"hljs-params\">()<\/span><\/span>{<\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\">        register_graphql_connection(&#91;<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\">            <span class=\"hljs-string\">'fromType'<\/span>=&gt;<span class=\"hljs-string\">'RootQuery'<\/span>,<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\">            <span class=\"hljs-string\">'toType'<\/span>=&gt;<span class=\"hljs-string\">'Post'<\/span>,<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\">            <span class=\"hljs-string\">'fromFieldName'<\/span>=&gt;<span class=\"hljs-string\">'recentPosts'<\/span>,<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\">            <span class=\"hljs-string\">'resolve'<\/span>=&gt;<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span><span class=\"hljs-params\">($source, $args, $context, $info )<\/span><\/span>{<\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\"><span class=\"hljs-function\">                $resolver = <span class=\"hljs-keyword\">new<\/span> \\WPGraphQL\\Data\\Connection\\PostObjectConnectionResolver($source, $args, $context, $info);<\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\"><span class=\"hljs-function\">                <span class=\"hljs-keyword\">return<\/span> $resolver-&gt;get_connection();<\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\"><span class=\"hljs-function\">            },<\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\"><span class=\"hljs-function\"><\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\"><span class=\"hljs-function\">        ]);<\/span><\/span><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"php\"><span class=\"hljs-function\"><span class=\"hljs-function\"> });<\/span><\/span><\/span>\n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Let&#8217;s break down this code block.<\/p>\n\n\n\n<p>Starting off, we use <code>add_action<\/code> to execute adding a type to the GraphQL schema.<\/p>\n\n\n\n<p>We have the function within our object called <code>register_graphql_connection <\/code>coming from WPGraphQL.&nbsp; This function is called and accepts an array that contains the types which will be queryable.&nbsp;<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-code-table shcb-line-numbers\"><span class='shcb-loc'><span>add_action(<span class=\"hljs-string\">'graphql_register_types'<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span><span class=\"hljs-params\">()<\/span><\/span>{\n<\/span><\/span><span class='shcb-loc'><span>       register_graphql_connection(&#91;\n<\/span><\/span><span class='shcb-loc'><span>           <span class=\"hljs-string\">'fromType'<\/span>=&gt;<span class=\"hljs-string\">'RootQuery'<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>           <span class=\"hljs-string\">'toType'<\/span>=&gt;<span class=\"hljs-string\">'Post'<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>           <span class=\"hljs-string\">'fromFieldName'<\/span>=&gt;<span class=\"hljs-string\">'recentPosts'<\/span>,\n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this case, we want a <code>Post<\/code> type to have a field name called <code>recentPosts <\/code>which will allow me to query for recent posts.&nbsp; This allows the connection to exist in the WPGraphQL schema.<\/p>\n\n\n\n<p>Once we have the connection existing, we want the data back.&nbsp; We use the <code>resolve<\/code> function to get the data back from our connection.&nbsp; Inside the parentheses, in GraphQL, <a href=\"https:\/\/graphql.org\/learn\/execution\/#root-fields-resolvers\">resolvers<\/a> get 4 arguments:&nbsp; <code>source, args, context, and info.<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Source<\/code>: The previous object, which is for a field on the root Query type is often not used.<\/li>\n\n\n\n<li><code>Args<\/code>: The arguments provided to the field in the GraphQL query.<\/li>\n\n\n\n<li><code>Context<\/code>: A value that is provided to every resolver and holds important contextual information like the currently logged-in user, or access to a database.<\/li>\n\n\n\n<li><code>Info<\/code>: A value that holds field-specific information relevant to the current query as well as the schema details, also refer to <a href=\"https:\/\/graphql.org\/graphql-js\/type\/#graphqlobjecttype\">type GraphQLResolveInfo for more details<\/a>.<\/li>\n<\/ul>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-code-table shcb-line-numbers\"><span class='shcb-loc'><span> <span class=\"hljs-string\">'resolve'<\/span>=&gt;<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span><span class=\"hljs-params\">($source, $args, $context, $info )<\/span><\/span>{\n<\/span><\/span><span class='shcb-loc'><span>               $resolver = <span class=\"hljs-keyword\">new<\/span> \\WPGraphQL\\Data\\Connection\\PostObjectConnectionResolver($source, $args, $context, $info);\n<\/span><\/span><span class='shcb-loc'><span>               <span class=\"hljs-keyword\">return<\/span> $resolver-&gt;get_connection();\n<\/span><\/span><span class='shcb-loc'><span>           },\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>       ]);\n<\/span><\/span><span class='shcb-loc'><span>});\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Within the function body of the <code>resolver<\/code>, we have a variable that is a new <code>resolver<\/code> that will return our new connection\u2019s data which is <code>recentPosts<\/code>.<\/p>\n\n\n\n<p>Heading now over to GraphIQL IDE in WP Admin, let&#8217;s manually test this ourselves by querying for <code>recentPosts<\/code>.&nbsp; In order to do that, don\u2019t forget to download the zip file of the extension you created for WPGraphQL and upload it to the plugins page within the WP-Admin.&nbsp;<\/p>\n\n\n\n<p>Now in GraphIQL IDE, this is what our query looks like with the response:<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/r3SfvtKOdHvCVCgDSy45I_Z--CbgcSUNrLTY23x1wqy4i6-A-HHAhMxUG0SNelEQ88aQMFLs2hD2QS7t81EqLvnfpuTbG-0yj6obs1pPi4McLBhvcfRn1dGX7S7n7BWjT8Lyk96atw4F0N-Q185AT-s\" width=\"624\" height=\"351\"><\/p>\n\n\n\n<p>This is finished and let\u2019s test this and see if it passes.&nbsp; I run <code>composer run-test <\/code>in my terminal to run the test library.<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/jCd4J2DglHae5yowyBx1VFFpPrQrQqJfdfjkjqAty8UqvmqBbsTDadAjHWzoi26N3vta5hcr2FQV48RSJe-pHC40H7e9fRtRu7tsQ7E9tZK3HVJS45xCDUyIFY-ZiZq6gGzuFoaxuq_kyEYLPTv1Npc\" width=\"624\" height=\"368\"><\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"99\" src=\"https:\/\/lh5.googleusercontent.com\/MCWjHvSGRJpcACRr-rdWhZpdORi6cpUOih9fYO9Xjxt2UNGSdr1Am89qj73VwlSvCCY-tldyZ_OIrkcLmbl6NO17NlcRcSGYFehLpVfmYualCUkxwJccoTbPoHBB98cT7WpIt0OKEUwFIIH6Z0-3FEo\"><\/p>\n\n\n\n<p>Stoked! It ran the test and executed exactly what we were testing for against the schema and extension we wrote.&nbsp; We passed!!!&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>The WPGraphQL TestCase library gives developers a better way to develop and test extensions in WPGraphQL to ensure proper functionality in features.<\/p>\n\n\n\n<p>I hope you have a better understanding of how to work with testing and the TestCase library.&nbsp; As always, super stoked to hear your feedback and any questions you might have on headless WordPress.&nbsp; Hit us up in the <a href=\"https:\/\/developers.wpengine.com\/discord\">Headless WordPress Discord <\/a>or the <a href=\"http:\/\/wp-graphql.slack.com\">WPGraphQL Slack<\/a> workspace!  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>WPGraphQL TestCase is a library of tools for testing WPGraphQL APIs along with its additional extensions.&nbsp; With this library, developers can write test cases that simulate different scenarios and interactions [&hellip;]<\/p>\n","protected":false},"author":20,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_EventAllDay":false,"_EventTimezone":"","_EventStartDate":"","_EventEndDate":"","_EventStartDateUTC":"","_EventEndDateUTC":"","_EventShowMap":false,"_EventShowMapLink":false,"_EventURL":"","_EventCost":"","_EventCostDescription":"","_EventCurrencySymbol":"","_EventCurrencyCode":"","_EventCurrencyPosition":"","_EventDateTimeSeparator":"","_EventTimeRangeSeparator":"","_EventOrganizerID":[],"_EventVenueID":[],"_OrganizerEmail":"","_OrganizerPhone":"","_OrganizerWebsite":"","_VenueAddress":"","_VenueCity":"","_VenueCountry":"","_VenueProvince":"","_VenueState":"","_VenueZip":"","_VenuePhone":"","_VenueURL":"","_VenueStateProvince":"","_VenueLat":"","_VenueLng":"","_VenueShowMap":false,"_VenueShowMapLink":false,"footnotes":""},"categories":[23],"tags":[26],"class_list":["post-5389","post","type-post","status-publish","format-standard","hentry","category-headless","tag-wpgraphql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>WPGraphQL TestCase Guide - Builders<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wpengine.com\/builders\/wpgraphql-testcase-guide\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WPGraphQL TestCase Guide - Builders\" \/>\n<meta property=\"og:description\" content=\"WPGraphQL TestCase is a library of tools for testing WPGraphQL APIs along with its additional extensions.&nbsp; With this library, developers can write test cases that simulate different scenarios and interactions [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wpengine.com\/builders\/wpgraphql-testcase-guide\/\" \/>\n<meta property=\"og:site_name\" content=\"Builders\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-26T14:23:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-20T14:11:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/lh5.googleusercontent.com\/SeJXOdeVvV-6anNKxzyKru-NrikoIUI1cL_NFMisbNX1GlIN-RjlZ2LwIGYChEJloX8zE52PxGBQL9wPixmh9cuCH5gFxsEvqnSSySaHk3o6Dx-hSBmiDtBvjS2caOMNUftEyo1Dee01lDW6AZp2Kak\" \/>\n<meta name=\"author\" content=\"Francis Agulto\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@wpebuilders\" \/>\n<meta name=\"twitter:site\" content=\"@wpebuilders\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Francis Agulto\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/wpgraphql-testcase-guide\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/wpgraphql-testcase-guide\\\/\"},\"author\":{\"name\":\"Francis Agulto\",\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/#\\\/schema\\\/person\\\/bcdcb4ac0b215c34b6b30e440a24dc54\"},\"headline\":\"WPGraphQL TestCase Guide\",\"datePublished\":\"2023-06-26T14:23:03+00:00\",\"dateModified\":\"2023-07-20T14:11:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/wpgraphql-testcase-guide\\\/\"},\"wordCount\":1306,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/wpgraphql-testcase-guide\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/lh5.googleusercontent.com\\\/SeJXOdeVvV-6anNKxzyKru-NrikoIUI1cL_NFMisbNX1GlIN-RjlZ2LwIGYChEJloX8zE52PxGBQL9wPixmh9cuCH5gFxsEvqnSSySaHk3o6Dx-hSBmiDtBvjS2caOMNUftEyo1Dee01lDW6AZp2Kak\",\"keywords\":[\"WPGraphQL\"],\"articleSection\":[\"Headless\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/wpengine.com\\\/builders\\\/wpgraphql-testcase-guide\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/wpgraphql-testcase-guide\\\/\",\"url\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/wpgraphql-testcase-guide\\\/\",\"name\":\"WPGraphQL TestCase Guide - Builders\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/wpgraphql-testcase-guide\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/wpgraphql-testcase-guide\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/lh5.googleusercontent.com\\\/SeJXOdeVvV-6anNKxzyKru-NrikoIUI1cL_NFMisbNX1GlIN-RjlZ2LwIGYChEJloX8zE52PxGBQL9wPixmh9cuCH5gFxsEvqnSSySaHk3o6Dx-hSBmiDtBvjS2caOMNUftEyo1Dee01lDW6AZp2Kak\",\"datePublished\":\"2023-06-26T14:23:03+00:00\",\"dateModified\":\"2023-07-20T14:11:57+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/wpgraphql-testcase-guide\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/wpengine.com\\\/builders\\\/wpgraphql-testcase-guide\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/wpgraphql-testcase-guide\\\/#primaryimage\",\"url\":\"https:\\\/\\\/lh5.googleusercontent.com\\\/SeJXOdeVvV-6anNKxzyKru-NrikoIUI1cL_NFMisbNX1GlIN-RjlZ2LwIGYChEJloX8zE52PxGBQL9wPixmh9cuCH5gFxsEvqnSSySaHk3o6Dx-hSBmiDtBvjS2caOMNUftEyo1Dee01lDW6AZp2Kak\",\"contentUrl\":\"https:\\\/\\\/lh5.googleusercontent.com\\\/SeJXOdeVvV-6anNKxzyKru-NrikoIUI1cL_NFMisbNX1GlIN-RjlZ2LwIGYChEJloX8zE52PxGBQL9wPixmh9cuCH5gFxsEvqnSSySaHk3o6Dx-hSBmiDtBvjS2caOMNUftEyo1Dee01lDW6AZp2Kak\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/wpgraphql-testcase-guide\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WPGraphQL TestCase Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/#website\",\"url\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/\",\"name\":\"Builders\",\"description\":\"Reimagining the way we build with WordPress.\",\"publisher\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/#organization\",\"name\":\"WP Engine\",\"url\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/WP-Engine-Horizontal@2x.png\",\"contentUrl\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/WP-Engine-Horizontal@2x.png\",\"width\":348,\"height\":68,\"caption\":\"WP Engine\"},\"image\":{\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/wpebuilders\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCh1WuL54XFb9ZI6m6goFv1g\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/#\\\/schema\\\/person\\\/bcdcb4ac0b215c34b6b30e440a24dc54\",\"name\":\"Francis Agulto\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0c8a05c76944fc987d57296c96dc368055844527088c0aa44297edbfa8b82546?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0c8a05c76944fc987d57296c96dc368055844527088c0aa44297edbfa8b82546?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0c8a05c76944fc987d57296c96dc368055844527088c0aa44297edbfa8b82546?s=96&d=mm&r=g\",\"caption\":\"Francis Agulto\"},\"description\":\"Fran Agulto is a Developer Advocate at WP Engine. He is a lover of all things headless WordPress, Rock Climbing, and overall being stoked for people that love what they do and share that stoke with others! Follow me on Twitter for cool stoked headless WP!\",\"url\":\"https:\\\/\\\/wpengine.com\\\/builders\\\/author\\\/francis-agultowpengine-com-2-2-2-2-2-2-2-2-2-2-2-3\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WPGraphQL TestCase Guide - Builders","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wpengine.com\/builders\/wpgraphql-testcase-guide\/","og_locale":"en_US","og_type":"article","og_title":"WPGraphQL TestCase Guide - Builders","og_description":"WPGraphQL TestCase is a library of tools for testing WPGraphQL APIs along with its additional extensions.&nbsp; With this library, developers can write test cases that simulate different scenarios and interactions [&hellip;]","og_url":"https:\/\/wpengine.com\/builders\/wpgraphql-testcase-guide\/","og_site_name":"Builders","article_published_time":"2023-06-26T14:23:03+00:00","article_modified_time":"2023-07-20T14:11:57+00:00","og_image":[{"url":"https:\/\/lh5.googleusercontent.com\/SeJXOdeVvV-6anNKxzyKru-NrikoIUI1cL_NFMisbNX1GlIN-RjlZ2LwIGYChEJloX8zE52PxGBQL9wPixmh9cuCH5gFxsEvqnSSySaHk3o6Dx-hSBmiDtBvjS2caOMNUftEyo1Dee01lDW6AZp2Kak","type":"","width":"","height":""}],"author":"Francis Agulto","twitter_card":"summary_large_image","twitter_creator":"@wpebuilders","twitter_site":"@wpebuilders","twitter_misc":{"Written by":"Francis Agulto","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/wpengine.com\/builders\/wpgraphql-testcase-guide\/#article","isPartOf":{"@id":"https:\/\/wpengine.com\/builders\/wpgraphql-testcase-guide\/"},"author":{"name":"Francis Agulto","@id":"https:\/\/wpengine.com\/builders\/#\/schema\/person\/bcdcb4ac0b215c34b6b30e440a24dc54"},"headline":"WPGraphQL TestCase Guide","datePublished":"2023-06-26T14:23:03+00:00","dateModified":"2023-07-20T14:11:57+00:00","mainEntityOfPage":{"@id":"https:\/\/wpengine.com\/builders\/wpgraphql-testcase-guide\/"},"wordCount":1306,"commentCount":0,"publisher":{"@id":"https:\/\/wpengine.com\/builders\/#organization"},"image":{"@id":"https:\/\/wpengine.com\/builders\/wpgraphql-testcase-guide\/#primaryimage"},"thumbnailUrl":"https:\/\/lh5.googleusercontent.com\/SeJXOdeVvV-6anNKxzyKru-NrikoIUI1cL_NFMisbNX1GlIN-RjlZ2LwIGYChEJloX8zE52PxGBQL9wPixmh9cuCH5gFxsEvqnSSySaHk3o6Dx-hSBmiDtBvjS2caOMNUftEyo1Dee01lDW6AZp2Kak","keywords":["WPGraphQL"],"articleSection":["Headless"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/wpengine.com\/builders\/wpgraphql-testcase-guide\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/wpengine.com\/builders\/wpgraphql-testcase-guide\/","url":"https:\/\/wpengine.com\/builders\/wpgraphql-testcase-guide\/","name":"WPGraphQL TestCase Guide - Builders","isPartOf":{"@id":"https:\/\/wpengine.com\/builders\/#website"},"primaryImageOfPage":{"@id":"https:\/\/wpengine.com\/builders\/wpgraphql-testcase-guide\/#primaryimage"},"image":{"@id":"https:\/\/wpengine.com\/builders\/wpgraphql-testcase-guide\/#primaryimage"},"thumbnailUrl":"https:\/\/lh5.googleusercontent.com\/SeJXOdeVvV-6anNKxzyKru-NrikoIUI1cL_NFMisbNX1GlIN-RjlZ2LwIGYChEJloX8zE52PxGBQL9wPixmh9cuCH5gFxsEvqnSSySaHk3o6Dx-hSBmiDtBvjS2caOMNUftEyo1Dee01lDW6AZp2Kak","datePublished":"2023-06-26T14:23:03+00:00","dateModified":"2023-07-20T14:11:57+00:00","breadcrumb":{"@id":"https:\/\/wpengine.com\/builders\/wpgraphql-testcase-guide\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wpengine.com\/builders\/wpgraphql-testcase-guide\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wpengine.com\/builders\/wpgraphql-testcase-guide\/#primaryimage","url":"https:\/\/lh5.googleusercontent.com\/SeJXOdeVvV-6anNKxzyKru-NrikoIUI1cL_NFMisbNX1GlIN-RjlZ2LwIGYChEJloX8zE52PxGBQL9wPixmh9cuCH5gFxsEvqnSSySaHk3o6Dx-hSBmiDtBvjS2caOMNUftEyo1Dee01lDW6AZp2Kak","contentUrl":"https:\/\/lh5.googleusercontent.com\/SeJXOdeVvV-6anNKxzyKru-NrikoIUI1cL_NFMisbNX1GlIN-RjlZ2LwIGYChEJloX8zE52PxGBQL9wPixmh9cuCH5gFxsEvqnSSySaHk3o6Dx-hSBmiDtBvjS2caOMNUftEyo1Dee01lDW6AZp2Kak"},{"@type":"BreadcrumbList","@id":"https:\/\/wpengine.com\/builders\/wpgraphql-testcase-guide\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wpengine.com\/builders\/"},{"@type":"ListItem","position":2,"name":"WPGraphQL TestCase Guide"}]},{"@type":"WebSite","@id":"https:\/\/wpengine.com\/builders\/#website","url":"https:\/\/wpengine.com\/builders\/","name":"Builders","description":"Reimagining the way we build with WordPress.","publisher":{"@id":"https:\/\/wpengine.com\/builders\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wpengine.com\/builders\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/wpengine.com\/builders\/#organization","name":"WP Engine","url":"https:\/\/wpengine.com\/builders\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wpengine.com\/builders\/#\/schema\/logo\/image\/","url":"https:\/\/wpengine.com\/builders\/wp-content\/uploads\/2024\/05\/WP-Engine-Horizontal@2x.png","contentUrl":"https:\/\/wpengine.com\/builders\/wp-content\/uploads\/2024\/05\/WP-Engine-Horizontal@2x.png","width":348,"height":68,"caption":"WP Engine"},"image":{"@id":"https:\/\/wpengine.com\/builders\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/wpebuilders","https:\/\/www.youtube.com\/channel\/UCh1WuL54XFb9ZI6m6goFv1g"]},{"@type":"Person","@id":"https:\/\/wpengine.com\/builders\/#\/schema\/person\/bcdcb4ac0b215c34b6b30e440a24dc54","name":"Francis Agulto","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/0c8a05c76944fc987d57296c96dc368055844527088c0aa44297edbfa8b82546?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0c8a05c76944fc987d57296c96dc368055844527088c0aa44297edbfa8b82546?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0c8a05c76944fc987d57296c96dc368055844527088c0aa44297edbfa8b82546?s=96&d=mm&r=g","caption":"Francis Agulto"},"description":"Fran Agulto is a Developer Advocate at WP Engine. He is a lover of all things headless WordPress, Rock Climbing, and overall being stoked for people that love what they do and share that stoke with others! Follow me on Twitter for cool stoked headless WP!","url":"https:\/\/wpengine.com\/builders\/author\/francis-agultowpengine-com-2-2-2-2-2-2-2-2-2-2-2-3\/"}]}},"_links":{"self":[{"href":"https:\/\/wpengine.com\/builders\/wp-json\/wp\/v2\/posts\/5389","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpengine.com\/builders\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpengine.com\/builders\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpengine.com\/builders\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/wpengine.com\/builders\/wp-json\/wp\/v2\/comments?post=5389"}],"version-history":[{"count":0,"href":"https:\/\/wpengine.com\/builders\/wp-json\/wp\/v2\/posts\/5389\/revisions"}],"wp:attachment":[{"href":"https:\/\/wpengine.com\/builders\/wp-json\/wp\/v2\/media?parent=5389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpengine.com\/builders\/wp-json\/wp\/v2\/categories?post=5389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpengine.com\/builders\/wp-json\/wp\/v2\/tags?post=5389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}