Leaderboard
Popular Content
Showing content with the highest reputation on 06/10/2018 in all areas
-
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.11 points
-
Are you sure? I'd expect it to always return the object. It's just that the object implements __toString with it's name, so it's casted to a string if needed. @PWaddict With == it's doing the same thing, because __toString returns the name of the template, but if you'd use === they would no longer have the same result.3 points
-
Hi Folks, I'm new to this forum, and only recently discovered PW. I'm coming from recently giving October and Craft and WordPress serious goes, but have been very curious to try a flat file approach. I must say for what it is worth, I spent hours and days bouncing around the web trying to find and then compare CMSs generally, and flat file CMSs specifically. PW didn't show up at first at all...which is unfortunate, as this seems like a great CMS and I look forward to giving it a go and following this forum. Most of the buzz seemed to be around Grav and Kirby. As a newbie who just discovered PW, I will point out that one of the things I look at when considering a CMS is what kind of pulse it has in the social media/forums realm. For example, I was surprised to see that you all don't have a Slack channel...or if you do, I can't find it, and it is not listed on the main PW page. That is a great way to find out what is going on within any given community, and addition to forums like this of course. You do have Twitter listed, which is great. I am also surprised that you don't have an introductions section in this forum for newbies. Maybe it's not that critical, but as a new member to a community it is nice to have. You of course can announce your arrival elsewhere in the forum like am I doing here. And yes, first impressions upon landing on the CMS front page makes a big difference. For example, I recently landed on the Razor CMS page and immediately cringed and couldn't get away from it fast enough. I forget now who it was after looking at so many CMSs, but another CMS front page immediately struck me as being corporate 1995 and also made me cringe and I had to leave stat. I know looks aren't everything, but considering what we do, well they kinda are lol. In any case, I thought I would at my 2.5 cents as a newbie who has very recently stumbled upon your community, and ran across this discussion. Cheers2 points
-
1 point
-
1 point
-
1 point
-
Yep I agree. Initially I was reluctant to start using Slack and slow to adopt it. Last year I had to use it permanently as part of a contracting gig I was doing and it's a really nice messaging App. I don't see it replacing the forums at all and actually it doesn't work as a forum replacement. Slack is great for immediate conversational type comms. The forums are great for searchable and persistent content that gets archived (and indexed by Google). It's just another useful medium.1 point
-
@matt.bryant Welcome to PW world. All great and topical points. On the subject of Slack. I would love to see an official Processwire Slack channel. Interesting - I thought there was one but can't find it now. I think that's a great idea though. Maybe it's something @Pete might consider?1 point
-
Hi Bernhard, What I am trying to make, is just another field-type. ? The idea is, to give an area to the "editor-user", where he can freely choose and place the content blocks he needs (from the ones you offer him). CSS (SASS) is mostly done by the admin (you or me). There is a part which the bs4grid field handles. This is the main "row" and all the container "cols" which are moveable and resizable. The content HTML of these is simply added via templates which you can add or remove. Such a template PHP looks like (grid_card.php) <?php namespace ProcessWire; echo '<div class="card">'; if ($page->title) echo '<div class="card-header">'.$page->title.'</div>'; if ($page->image && ($page->card_img_types=="1" || $page->card_img_types=="3")) echo '<img class="card-img-top" src="'.$page->image->url.'" alt="'.$page->image->description.'">'; if ($page->image && $page->card_img_types=="3") echo '<div class="card-img-overlay">'; if ($page->body) echo '<div class="card-body">'.$page->body.'</div>'; if ($page->image && $page->card_img_types=="3") echo '</div>'; if ($page->image && $page->card_img_types=="2") echo '<img class="card-img-bottom" src="'.$page->image->url.'" alt="'.$page->image->description.'">'; if ($page->footer) echo '<div class="card-footer">'.$page->footer.'</div>'; echo '</div>'; ?> I personally have no intention to make it "all purpose". I will be happy when it works for Bootstrap 4. That said, I'm not very familiar with other CSS Frameworks. A big difference to the new CSS Grid is certainly, that the column definitions of BS are part of the HTML (class attributes, sort of inline) where the CSS Grid has to be defined in the style part outside the HTML. No sure if you were interested in this kind of information. I'm still playing with it, there is not much theory behind.1 point
-
I've done such a task by using my RockGrid field and connecting it via JS to a Page Reference field. You have a nice UI for filtering and listing items (books in your case) with different columns and you can just select + add them to your reference field. If you are happy with your autocomplete field, great. If not you can contact me ?1 point
-
I'm still working on the latest version of ProcessWire (version 3.0.106) and don't have it quite ready to push to GitHub today, so we'll save that for next week. But I do have a fairly major FormBuilder release ready, and am placing it for download in the FormBuilder support board today. In this post, I'll cover what's new in this version of FormBuilder. After that, there is a how-to guide for using hooks in FormBuilder, though some might also find it also generally useful for any hooks in ProcessWire. Lastly, there's a FormBuilder hooks reference, which has been asked for a few times lately, so figured that was a good way to round out this FormBuilder blog post. Thanks for reading! https://processwire.com/blog/posts/formbuilder-v34/1 point
-
InputfieldSelectizeMultiple or ajax version – the ajax version was designed for this purpose you describe; non-ajax version has only been tested to work on maybe 500-600 select items1 point
-
I'm so glad I wanted to share that with you today. Since November 2017, all of the company's infrastructure is built on ProcessWire. Whether it is the showcase website or the millions of transactions recorded in the database as pages or all the custom modules to interact with the company's data. Just to say that I feel lucky to work all the day with what I love, and when I remember that I was demoralized thinking I had to learn Wordpress or I don't know what, because before ProcessWire I never worked with a CMS and it was becoming vital. Then I stumbled on ProcessWire (hooray!). And now, a new step for me appeared yesterday. I have a trainee for a month. And my task is to teach him how to work with ProcessWire! This make me really proud ! Have a nice day everyone and again, thanks to this community and this software! ?1 point
-
Thanks for sharing your video @Jonathan Lahijani! In case your interested, I added your technique to my "Techniques for flexible page layouts in Processwire" document https://docs.google.com/document/d/1peY-FUpevKgy87cKOxIVz8jwcv2-3c61zbiJr3QKO6c/edit?usp=sharing1 point
-
Hi folks, I published "Simple file downloads with ProcessWire tutorial" today which explains how to make a simple download function with ProcessWire (tested with version 3.0+). Basically this is based on my post here in the forums1 point