You have to create a custom WP template for that file to use display itself. Otherwise it is a stand alone file trying to be executed without permission or hooks.
in this case you would need to add the file php code directly through WP and create a Page.
You can also open the "page.php" in your selected theme directory save it as "test.php" in that same directory and paste the entire content of your "test.php" PHP code inside the division of your new "test.php" file.
Something like this:
<main id="main" class="site-main" role="main">
<?php
//Your PHP Code Here!
?>
</main>
This just shows the basic Division. You will need. If you need the entire other site content to display along with the test.php you will need to create a content-test.php file under the "templates-parts" directory in your theme.
Again, same thing except your gonna open "content-page.php" this time and save it as "content-test.php" under the "templates-parts" directory and past the test.php code inside the where you would like this to show.
Back to the new "test.php" and replace the following line:
get_template_part( 'template-parts/content', 'page' );
with:
get_template_part( 'template-parts/content', 'test' );
The down side to this method is that when WP updates, it may or may not leave that file in tact vs. the first option which calls the php file as a post or page.
Hope that helps!
$wpdb
for.functions.php
using a filter. Then you make the call toadmin-ajax.php
and WordPress passes it along. There's a plugin-based example in the Codex but it works the exact same way for themes.