adrian

Tracy Debugger

Recommended Posts

Maybe it has been asked before, but when I have TracyDebugger disabled I get this error in the console of my developer tools:

Quote

Uncaught TypeError: Cannot read property 'DebugPanel' of undefined at window.onload

Could this be avoided by a try-catch block? It is not too important, but it would be great to not have this error.

And I cannot mention enough how great your module is. It helped me a lot of times. ;)

  • Like 1

Share this post


Link to post
Share on other sites

Hi @AndZyk - this was actually just fixed yesterday. Please update and let me know if you still have any problems.

  • Thanks 1

Share this post


Link to post
Share on other sites
17 hours ago, adrian said:

So for me, there really is no noticeable difference in load times. But we have seen discrepancies like this before. I remember when kongondo had really slow load times with the three objects in this panel, but it didn't affect you at all. Could you maybe determine which one of these three is causing the main slowdown? If it's "Config Data", then I would suggest just disabling that and using the Console panel and doing: d($config) whenever you want that info.

I had the time to do some testing, here it comes (my MAMP Pro):

  • API variables: 0.3ms
  • Core Classes: 0.4ms
  • Config Data: 270ms
  • Version List: 14ms
  • API variables + Core Classes + Admin Link + Doc Links: 0.9ms

The result of d($config) is:
Frontend:
syntax error, unexpected end of file
File: .../site/assets/cache/TracyDebugger/consoleCode.php:2
1: <?php if(!defined("PROCESSWIRE")) die("no direct access"); $page = $pages->get(1);
2: d($config)

Admin:
Same as above + 500: Internal Server Error: See the browser dev console for the actual error

Why? It used to work.

BTW, links in this Info panel do not not use _blank, why? I keep forgetting it which is kinda annoying after while. Is it just me? :) 

  • Like 1

Share this post


Link to post
Share on other sites
6 hours ago, szabesz said:

The result of d($config) is:
Frontend:
syntax error, unexpected end of file

You're missing the line ending semicolon ;)

d($config);

So it looks like "Config Data" is the culprit on your setup. I don't really know why it's so slow for you, and I don't really know how to improve it. Anyone else seeing that? If others chime in with a similar experience, I'll see what I can do, but I think for the moment it's probably best to just disable that and use d($config); as needed.

 

6 hours ago, szabesz said:

BTW, links in this Info panel do not not use _blank, why? I keep forgetting it which is kinda annoying after while. Is it just me?

I used to be all about _blank links, but these days I actually find them annoying because they give you no choice. A normal link lets you choose - I have three-finger / midd-click setup for open in new tab. If you are finding it that annoying though, I'd be happy to add a config setting to make all those PW Info panel icon links optionally open in a new tab - just let me know.

  • Like 1

Share this post


Link to post
Share on other sites
19 minutes ago, adrian said:

You're missing the line ending semicolon

Double bother :-X I need to think, think, think harder next time :) This is the first time I see these errors, probably I got intimidated...

19 minutes ago, adrian said:

If you are finding it that annoying though, I'd be happy to add a config setting to make all those PW Info panel icon links optionally open in a new tab - just let me know.

Yes please!

19 minutes ago, adrian said:

and use d($config);

The problem with this that I get the result in a not too tall box with lots of scrolling an clicking and the presentation of it is not as "good" as the one with the panel.

What if there was a way to put custom settings onto the Panel Selector? Meaning module settings could be enabled/disabled for the Panel Selector, those one happens to switch on/of often. Currently I have no idea how the UI could be implemented for this, so this is just a blurry thought at this time.

Edited by szabesz
typo
  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, szabesz said:

Yes please!

Ok, I'll take care of that shortly - just keep in mind that I won't be adding "_blank" to the Login/Logout, Clear Session & Cookies, and Modules Refresh links, because these are actions that are designed to reload the same page once they complete, but I think all the others will be ok with an option for "_blank".

 

2 hours ago, szabesz said:

The problem with this that I get the result in a not too tall box with lots of scrolling an clicking and the presentation of it is not as "good" as the one with the panel.

What if there was a way to put custom settings onto the Panel Selector? Meaning module settings could be enabled/disabled for the Panel Selector, those one happens to switch on/of often. Currently I have no idea how the UI could be implemented for this, so this is just a blurry thought at this time.

Honestly I think this is starting to sound a little too complex. i have already added the Enable/Disable Strict Mode option, but I think I think it could get out of control if we're not careful. I'd really like to know why $config is so slow for you - how long does the Console panel response take when doing d($config); ? Just wondering if it's rendering $config itself that's the problem, or something about the way it is done in the PW Info panel that could be improved.

  • Like 1

Share this post


Link to post
Share on other sites

A quick update.

Thanks to lots of help from @szabesz we have fixed the issue with the Config Data section in PW Info panel from being slow.

The latest version also:

1) Fixes a ERR_BLOCKED_BY_XSS_AUDITOR browser error if there are <script> tags in your template file and you are using the Template Editor panel to test code changes.

2) Adds a new option for opening links from the PW Info panel in a new browser tab (off by default) - this was requested by @szabesz above.

3) Revamped the init() and ready() code so that much less code is processed when Tracy is completely or temporarily disabled. It also improves efficiency for various conditional checks.

4) Several other minor tweaks / fixes.

Please let me know if you come across any problems with this new version.

 

  • Like 4

Share this post


Link to post
Share on other sites

@adrian This morning I quickly crafted my own version of the "TracyEnableButton" in order to see if a smaller version can be made. The idea is that – in such small sizes the icons are used – using only lines should be enough to get very similar results. Of course, when an icon like this is enlarged its line only characteristics become prominent but I do not think it is an issue in our case. So here it comes:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 54.48 57.24"><defs><style>.a{fill:none;stroke:#CD1818;stroke-miterlimit:10;stroke-width:8px;}</style></defs><title>turn-off</title><path class="a" d="M24,10.17a23.24,23.24,0,1,0,16,0" transform="translate(-4.76 -2)"/><line class="a" x1="27.24" x2="27.24" y2="21"/></svg>

Only 323 characters versus 1101 (current icon). What do you think? Is it usable, and if so worth the effort? I could produce all the others if you think it is a good idea.

  • Like 1

Share this post


Link to post
Share on other sites
6 hours ago, szabesz said:

@adrian This morning I quickly crafted my own version of the "TracyEnableButton" in order to see if a smaller version can be made. The idea is that – in such small sizes the icons are used – using only lines should be enough to get very similar results. Of course, when an icon like this is enlarged its line only characteristics become prominent but I do not think it is an issue in our case. So here it comes:


<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 54.48 57.24"><defs><style>.a{fill:none;stroke:#CD1818;stroke-miterlimit:10;stroke-width:8px;}</style></defs><title>turn-off</title><path class="a" d="M24,10.17a23.24,23.24,0,1,0,16,0" transform="translate(-4.76 -2)"/><line class="a" x1="27.24" x2="27.24" y2="21"/></svg>

Only 323 characters versus 1101 (current icon). What do you think? Is it usable, and if so worth the effort? I could produce all the others if you think it is a good idea.

I like where you are headed with this and I think the new version looks nice. The only thing I wonder is whether it is worth re-crafting all the icons vs just running them through SVGO (which I should really have already done). I just used the online GUI for this test.

I just tried and it reduced it to 501 characters:

<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 44.8 44.8">
  <g fill="#CD1818">
    <path d="M22.4 21.2c2 0 4-1.8 4-4V4c0-2-2-3.8-4-3.8s-4 1.7-4 3.8v13.5c0 2 2 4 4 4z"/>
    <path d="M30.7 3.3c-.5-.2-1 0-1.4.2-.5.3-.7.7-.7 1.3v5c0 .6.3 1.2.7 1.4 4.2 2.4 7 7 7 12 0 7.7-6.2 14-14 14-7.6 0-13.8-6.3-13.8-14 0-5 3-9.6 7-12 .4-.2.7-.8.7-1.3V4.4c0-.6-.2-1-.7-1.3C15 3 14.5 3 14 3 6.6 6.6 1 14 1 23c0 12.3 9.7 22 21.6 22 12 0 21.6-9.6 21.6-21.6 0-9-5.4-16.6-13.3-20z"/>
  </g>
</svg>

So there is definitely significant room for improvement with these icons. It's just a question of whether it's worth going the "line only" route, or just using SVGO to optimize the existing ones. Honestly I think most of the icons could do with some work - many of them are pretty ugly :) If you feel like taking this on, it would definitely be appreciated.

Anyone else have any thoughts?

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, adrian said:

It's just a question of whether it's worth going the "line only" route, or just using SVGO to optimize the existing ones.

Line-only versions are harder to do right because of its nature and limitations but I was thinking about going crazy with optimization regarding how much is injected into the page.

1 hour ago, adrian said:

worth re-crafting all the icons vs just running them through SVGO

By removing the probably not needed <title>turn-off</title> from my version (it was just exported too, as the name of the file was "turn-off") we have only 300 characters. Probably this is not the one where we can gain a lot but more complex ones like logos and such.

1 hour ago, adrian said:

If you feel like taking this on, it would definitely be appreciated.

I would be happy to do it. It is probably not worth forcing us to use line-only svg when more complex icons are needed but some of then (like this turn on/off icon called EnableButton) looks doable. Others might just need SVGO treatment :) 

I focused on EnableButton because I would like to see less in the source code of a frontend page when Tracy is disabled. So something like this (removing some line breaks) would be nice too:

<style>div#TracyEnableButton{bottom:10px!important;right:10px!important;z-index:99999!important;position:fixed!important;width:16px!important;height:16px!important;margin:0px!important;padding:0px!important;cursor:pointer!important;}div#TracyEnableButtonsvg{width:16px!important;height:16px!important;}</style>

I often use the Chrome extension called Quick source viewer which displays the actual rendered output in a different way then the inspector. For the styles I get the line breaks but if you could remove them we would get a more compact version injected.

Edited by szabesz
fix: So something like this (removing some line breaks) would be nice too:
  • Like 1

Share this post


Link to post
Share on other sites

All sounds great @szabesz The other possibility here is to use FontAwesome icons as much as possible. I recently added it for loading the icons for the new "Custom Links" section in the PW Info panel.  Although it is only loaded if you have defined some custom links. Because you guys can add a link to any page (admin Process or frontend) on the site, this was the only way to show the appropriate icon automatically. Not sure if this is a better or worse approach in terms of resources. Obviously Fontawesome isn't super lightweight, but it's also not embedding the SVG directly into the panels, so maybe more efficient?

14 minutes ago, szabesz said:

I focused on EnableButton because I would like to see less in the source code of a frontend page when Tracy is disabled. So I this removing some line break would be nice too:

Sounds like a good idea - I'll sort that out.

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, adrian said:

Obviously Fontawesome isn't super lightweight, but it's also not embedding the SVG directly into the panels, so maybe more efficient?

That reminds me of this tool I've somewhat forgotten about: http://fontello.com/
More efficient? Hard to tell... Maybe a custom set?

1 hour ago, adrian said:

Sounds like a good idea - I'll sort that out.

Thanks in advance! 

Share this post


Link to post
Share on other sites

I was about to suggest fontello but ten icons weighted about 10 kbyte, so 1 per char which seems heavier than svgs. Of course more or other chars can be perhaps less heavy.

Another option could be using unicode characters as icons but I'm not sure there are enough of them and browsers may display them differently. That would be super light though.

  • Like 1

Share this post


Link to post
Share on other sites
6 minutes ago, tpr said:

browsers may display them differently

Do you have any idea where it can be looked up? I mean, where we can check what is probably(?) supported by most modern OSes/browsers these days? It would be interesting to know. I guess the "cross-platform" typefaces are more or less the same as they have ever been but those font files seem to keep growing by added characters as the OSes evolve.

Share this post


Link to post
Share on other sites

I like the idea of unicode icons, but I am also not convinced that browser support is that consistent. I have seen screenshots of the Tracy console for example where the history back/forward icons don't look good. Also, I agree that there aren't enough options for our needs.

Something like a fontello custom set might be ok, but in general I have always thought that plain SVG icons were lighter, so I think I'd prefer to go with those I think. I wonder how much this really matters - is it over-optimization to be worrying about this?

Share this post


Link to post
Share on other sites

Hi @adrian,

I struck a problem trying to use bd() inside $sanitizer->pageNameUTF8().

If I add a bd() call to pageNameUTF8() like this...

public function pageNameUTF8($value) {
    bd($value, 'value');
    //...

...and then trigger the method like this...

$test = $sanitizer->pageNameUTF8('foo');

...then everything is fine so far and works as expected.

But as soon as I add the following to /site/config.php

$config->pageNameCharset = 'UTF8';

...then I get an error:

Quote

Fatal error: Uncaught Error: Call to undefined function ProcessWire\bd() in D:\Websites\__www\1testing\wire\core\Sanitizer.php:456

Any idea why this happens?

Share this post


Link to post
Share on other sites
37 minutes ago, Robin S said:

Any idea why this happens?

I think it's simply a matter of the order of things.

Without the pageNameCharset being set in config, the first call to the pageNameUTF8() sanitizer method is after init(), but when you set it, it must call that sanitizer method before Tracy has loaded. I did ask Ryan a long while back about the possibility of being able to load Tracy earlier - he said he might be amenable, but nothing ever came of it.

I just did some experiments loading the Tracy core files in the root index.php and with that setup, your bd() call still works, even with: $config->pageNameCharset = 'UTF8';

I'd like to revisit this idea with Ryan - I have come across bd() undefined many times when trying to use them in the PW core files - it would be great to have Tracy loaded before anything else.

I wonder if a request for this might be more powerful initiated by someone other than myself?

  • Like 1

Share this post


Link to post
Share on other sites

@adrian Hi,
I scanned the "docs" and could not find this tip of yours:
https://github.com/processwire/processwire-issues/issues/429#issuecomment-342976462
sounds like an important one.

Could you please consider adding it? Also, AJAX instructions are mostly in the Getting Started section which is fine but probably a dedicated "Debugging AJAX" or maybe "Working with AJAX" section with links to other related tips found on the page and additional tips like the one above would be nice to have.

Edited by szabesz
header name idea fix
  • Like 3

Share this post


Link to post
Share on other sites

Hey @szabesz - I really need to start the docs again from scratch. I have butchered that blog post so badly with new additions and most of the screenshots are really old. I'd really like to start a Github wiki for docs - @tpr has inspired me with the amazing job he has done on the docs for his modules using the wiki. The problem of course is time. I am already spending way too much time on module development and support and not enough time on paid client work - not meant to be an excuse, just a reality. And there are lots of others here putting in just as much time! 

I'd love to dedicate more time to PW module development, but of course that would mean paid modules - what to do ?

Maybe the Tracy docs could be a team effort - anyone interested? The problem is that there is no easy way to enable PRs on Gitbub wikis, although this might work: http://www.growingwiththeweb.com/2016/07/enabling-pull-requests-on-github-wikis.html

Any thoughts?

 

  • Like 3

Share this post


Link to post
Share on other sites
13 minutes ago, adrian said:

anyone interested?

+1 :)

13 minutes ago, adrian said:

The problem is that there is no easy way to enable PRs on Gitbub wikis, although this might work

I'm not fond of unsupported "hacky" solutions but it is just me :) Maybe a dedicated tool instead? I just googled a bit: https://www.penflip.com/

There could be alternatives, of course.

  • Like 1

Share this post


Link to post
Share on other sites

i don't know how the guys from uikit are doing it but they have nice docs and it seems that everybody can post suggestions (there is an edit button on all pages): https://getuikit.com/docs/icon

it's unbelievable how much you contributed to the community so far - a donation button would be the least imho. i've already asked you for that some time ago ;)

  • Like 3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By dreerr
      TemplateEnginePug (formally TemplateEngineJade)
       
      This module adds Pug templates to the TemplateEngineFactory. It uses https://github.com/pug-php/pug to render templates.
      doctype html html(lang='en') head meta(http-equiv='content-type', content='text/html; charset=utf-8') title= $page->title link(rel='stylesheet', type='text/css', href=$config->urls->templates . 'styles/main.css') body include header.pug h1= $page->title if $page->editable() p: a(href=$page->editURL) Edit Project on GitHub: github.com/dreerr/TemplateEnginePug
      Project in modules directory: modules.processwire.com/modules/template-engine-pug/
       
      For common problems/features/questions about the Factory, use the TemplateEngineFactory thread.
       
    • By tpr
      ProcessNetteTester
      Run Nette Tester tests within ProcessWire admin.
      (continued from here)

      Features
      AJAX interface for running Nette Tester tests, in bulk or manually display counter, error message and execution time in a table run all tests at once or launch single tests show formatted test error messages and report PHP syntax errors stop on first failed test (optional) hide passed tests (optional) display failed/total instead passed/total (optional) re-run failed tests only (optional) auto scroll (optional) include or exclude tests based on query parameters start/stop all tests with the spacebar reset one test or all tests (ctrl+click) https://modules.processwire.com/modules/process-nette-tester/
      https://github.com/rolandtoth/ProcessNetteTester
    • By bernhard
      Some of you might have followed the development of this module here: https://processwire.com/talk/topic/15524-previewdiscussion-rockdatatables/ . It is the successor of "RockDataTables" and requires RockFinder to get the data for the grid easily and efficiently. It uses the open source part of agGrid for grid rendering.
       
      WHY?
      ProcessWire is awesome for creating all kinds of custom backend applications, but where it is not so awesome in my opinion is when it comes to listing this data. Of course we have the built in page lister and we have ListerPro, but none of that solutions is capable of properly displaying large amounts of data, for example lists of revenues, aggregations, quick and easy sorts by the user, instant filter and those kind of features. RockGrid to the rescue 😉 
       
      Features/Highlights:
      100k+ rows Instant (client side) filter, search, sort (different sort based on data type, eg "lower/greater than" for numbers, "contains" for strings) extendable via plugins (available plugins at the moment: fullscreen, csv export, reload, batch-processing of data, column sum/statistics, row selection) all the agGrid features (cell renderers, cell styling, pagination, column grouping etc) vanilla javascript, backend and frontend support (though not all plugins are working on the frontend yet and I don't plan to support it as long as I don't need it myself)  
      Limitations:
      While there is an option to retrieve data via AJAX the actual processing of the grid (displaying, filtering, sorting) is done on the client side, meaning that you can get into troubles when handling really large datasets of several thousands of rows. agGrid should be one of the most performant grid options in the world (see the official example page with a 100k row example) and does a lot to prevent problems (such as virtual row rendering), but you should always have this limitation in mind as this is a major difference to the available lister options that do not have this limitation.
      Currently it only supports AdminThemeUikit and I don't plan to support any other admin theme.
       
      Download: https://gitlab.com/baumrock/RockGrid
      Installation: https://gitlab.com/baumrock/RockGrid/wikis/Installation
      Quikckstart: https://gitlab.com/baumrock/RockGrid/wikis/quickstart
      Further instructions: https://gitlab.com/baumrock/RockGrid/wikis/quickstart#further-instructions
       
      Module status: alpha, License: MIT
      Note that every installation and uninstallation sends an anonymous google analytics event to my google analytics account. If you don't want that feel free to remove the appropriate lines of code before installation/uninstallation.
       
      Contribute:
      You can contribute to the development of this and other modules or just say thank you by
      testing, reporting issues and making PRs at gitlab liking this post buying me a drink: paypal.me/baumrock/5 liking my facebook page: facebook.com/baumrock hiring me for pw work: baumrock.com  
      Support: Please note that this module might not be as easy and plug&play as many other modules. It needs a good understanding of agGrid (and JavaScript in general) and it likely needs some looks into the code to get all the options. Please understand that I can not provide free support for every request here in the forum. I try to answer all questions that might also help others or that might improve the module but for individual requests I offer paid support for 60€ per hour.
       
      Changelog
      180711 bugfix (naming issue) 180630 alpha realease  
      Use Cases / Examples:
      Colored grid cells, Icons, Links etc. The Grid also has a "batcher" feature built in that helps communicating with the server via AJAX and managing resource intensive tasks in batches:

      Filters, PW panel links and instant reload on panel close:

      You can combine the grid with a chart library like I did with the (outdated) RockDataTables module:

    • By tpr
      Update 2018-07-09: ProcessNetteTester module is available in the Modules Directory and on GitHub.

      This is a short tutorial on how to use Nette Tester with ProcessWire.
      As you will see it's very easy to setup and use and it's perfect for testing your code's functionality. With bootstrapping ProcessWire it's also possible to check the rendered markup of pages using the API, checking page properties, etc. It's also a great tool for module developers for writing better code. 
      While there will be nothing extraordinary here that you couldn't find in Tester's docs this can serve as a good starting point.
      Prerequisites: PHP 5.6+
      01 Download Tester
      Go to https://github.com/nette/tester/releases and download the latest release (currently 2.0.2). Download from the link reading "Source code (zip)". You can use composer also if you wish.
      02 Extract Tester files
      Create a new directory in your site root called "tester". Extract the zip downloaded here, so it should look like this:
      /site /tester/src /tester/tools /tester/appveyor.yml /tester/composer.json /tester/contributing.md /tester/license.md /tester/readme.md /wire ... 03 Create directory for test files
      Add a new directory in "/tester" called "tests". Tester recognizes "*.Test.php" and "*.phpt" files in the tests directory, recursively. 
      04 Create your first test
      In the "tests" directory create a new "MyTest.php" file.
      The first test is a very simple one that bootstraps ProcessWire and checks if the Home page name is "Home". This is not the smartest test but will show you the basics.
      Add this to "/tester/tests/MyTest.php":
      <?php namespace ProcessWire; use \Tester\Assert; use \Tester\DomQuery; use \Tester\TestCase; use \Tester\Environment; require __DIR__ . '/../src/bootstrap.php'; // load Tester require __DIR__ . '/../../index.php'; // bootstrap ProcessWire Environment::setup(); class MyTest extends TestCase {     // first test (step 04)     public function testHomeTitle()     {         $expected = 'Home'; // we expect the page title to be "Home"         $actual = wire('pages')->get(1)->title; // check what's the actual title Assert::equal($expected, $actual); // check whether they are equal     }     // second test will go here (step 06)     // third test will go here (step 07) } // run testing methods (new MyTest())->run(); I've added comment placeholders for the second and third tests that we will insert later.
      05 Run Tester
      Tester can be run either from the command line or from the browser. The command line output is more verbose and colored while in the browser it's plain text only (see later).
      Running from the command line
      Navigate to the "/tester" directory in your console and execute this:
      php src/tester.php -C tests This will start "/tester/src/tester.php" and runs test files from the "/tester/tests" directory. The "-C" switch tells Tester to use the system-wide php ini file, that is required here because when bootstrapping ProcessWire you may run into errors (no php.ini file is used by default). You may load another ini file with the "-c <path>" (check the docs).
      If the title of your Home page is "Home" you should see this:

      If it's for example "Cats and Dogs", you should see this:

      Running from the browser
      First we need to create a new PHP file in ProcessWire's root, let's call it "testrunner.php". This is because ProcessWire doesn't allow to run PHP files from its "site" directory.
      The following code runs two test classes and produces a legible output. IRL you should probably iterate through directories to get test files (eg. with glob()), and of course it's better not allow tests go out to production.
      <?php ini_set('html_errors', false); header('Content-type: text/plain'); echo 'Starting tests.' . PHP_EOL; echo '--------------------------' . PHP_EOL; $file = __DIR__ . '/PATH_TO/FirstTest.php'; echo basename($file) . ' '; require $file; echo '[OK]' . PHP_EOL; $file = __DIR__ . '/PATH_TO/SecondTest.php'; echo basename($file) . ' '; require $file; echo '[OK]' . PHP_EOL; echo '--------------------------' . PHP_EOL; echo 'Tests finished.'; exit; Navigate to "DOMAIN/testrunner.php" in your browser to execute the file. If every test succeeds you should get this:

      If there are failed tests the execution stops and you can read the error message. If there were more tests (eg. ThirdTest), those won't be displayed under the failed test.

      06 DOM test
      This test will check if a page with "basic-page" template has a "h1" element. We will create the page on the fly with ProcessWire's API. To keep things simple we will add the new test as a new method to our MyTest class.
      Add this block to the MyTest class:
      public function testBasicPageHeadline() {     $p = new Page();     $p->template = 'basic-page';     $html = $p->render();     $dom = DomQuery::fromHtml($html);     Assert::true($dom->has('h1')); } This will most likely be true but of course you can check for something more specific, for example "div#main". Note that we have used the DomQuery helper here (check the "use" statement on the top of the file).
      07 Custom function test
      You will probably want to make sure your custom functions/methods will work as they should so let's write a test that demonstrates this.
      I don't want to complicate things so I'll check if the built-in "pageName" sanitizer works as expected. Add this to the myTest class:
      public function testPageNameSanitizer() {     $expected = 'hello-world';     $actual = wire('sanitizer')->pageName('Hello world!', true);     Assert::equal($expected, $actual); } This should also be true. Try to change the expected value if you are eager to see a failure message.
       
      08 Next steps
      You can add more methods to the MyTest class or create new files in the "tests" directory. Check out the range of available Assertions and other features in the docs and see how they could help you writing more fail-safe code.
      Once you make a habit of writing tests you'll see how it can assist making your code more bulletproof and stable. Remember: test early, test often 🙂
      If you find out something useful or cool with Tester make sure to share.
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Download & Docs: https://gitlab.com/baumrock/RockPdf
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread: