Jump to content

tpr

Members
  • Posts

    2,321
  • Joined

  • Last visited

  • Days Won

    44

Everything posted by tpr

  1. A small thing in your Js: it would be better to check the "type" of the input instead the icon. So instead of this: var passwordField = $this.next('.FieldtypePassword')[0]; if ($icon.hasClass('fa-eye-slash')) { passwordField.setAttribute('type','text') $icon.removeClass('fa-eye-slash'); } else { passwordField.setAttribute('type','password') $icon.addClass('fa-eye-slash'); } something like this (untested): var $passwordField = $this.next('.FieldtypePassword'); if ($passwordField.attr('type') === 'password') { $passwordField.attr('type', 'text'); $icon.removeClass('fa-eye-slash'); } else { $passwordField.attr('type', 'password'); $icon.addClass('fa-eye-slash'); } I also rewrote the passwordField to a jQuery object if that's what is used in the entire file.
  2. A few usability tweaks and tips for the CKEditor "Styles" dropdown, which is by default not that user-friendly: As you can see it's small and if you add custom items to it they may look awkward as they may inherit styles from their targets (a 3rem bottom margin in the screenshot above). These are relatively easy to fix but you have to load your custom CSS files to two places (eg. with AdminOnSteroids): PW admin and CKEditor. After loading the CSS/Js assets (see code below) the dropdown looks nicer and more usable: The screencap contains other features that you can achieve with the snippets below. Code CSS - CKEditor (contains demo styles too) CSS - admin JavaScript - CKEditor custom styles P.s. in case you wonder whether the half-margin, no-margin stuff and font-sizes from 12px to 48px were real-life examples - yes, client request ?
  3. To avoid the notice "Trying to get property 'type' of non-object" and possible issues later it's better to check wether the field is really a Field: $f = $fields->get('myfield'); if ($f instanceof Field && $f->type instanceof FieldtypeLanguageInterface) { // do something }
  4. I've updated the first post with info on how to run tests from the browser, so there's no need to have command line access to the server.
  5. Thanks, fixed in v197. There are other places where there's no need to add but thankfully we have $page->trashable().
  6. You need to target a specific page, in this case the Home: $pages->get(1)->httpUrl This will get the page on the language the user is browsing the site, which is what you need I guess.
  7. When using setUp and tearDown methods it's good to keep in mind that Tester runs tests in parallel threads. That is, if you except that a Page you create in the setUp method will be deleted in tearDown before the next test method begins, you may be wrong. For example I've created and saved a new Page with the same title in setUp and deleted it in tearDown. I randomly got a ProcessWire error saying it could not generate a unique name for the page, and that was because the other tests have been started before the page could be deleted in the tearDown method. The actual thread number can be retrieved, so appending it to the title solved the issue (or by adding a random suffix): $p->title = 'Test ' . getenv(\Tester\Environment::THREAD); Alternatively you can reduce the number of threads to 1 with the "-j 1" switch (runtime will increase a lot).
  8. Honestly I haven't went that far yet but the closest I found are the setUp and tearDown methods (see the docs). Of course this creates holes in the autoincrement ids but I don't think that matters much. Method calls order ------------------ setUp() testOne() tearDown() setUp() testTwo() tearDown()
  9. 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.
  10. 1.9.5 is uploaded. I've disabled the FileCompiler because on Win localhost it was very slow, so if you have issues try to refresh the module cache. Changelog: - fix inline pagelist items if "Always show pagelist actions" was checked (reported by ottogal) - Delete and Trash action (non-superusers): skip confirmation if ctrl key is pressed - new Skip Trash? checkbox on page edit Delete tab (SuperUsers only, requested by Robin S) - fix NavItems causing JS error on "Find Files to Translate" page Search box - hotkey save: do not add blocking overlay until html5 required attribute requirements are not resolved (reported by Robin S, #95) - asmSelect searchbox: allow wider dropdown - AdminThemeUikit, percentage-based widths ON: move AsmSelect placeholder and maxlimit fields after Required field to avoid layout issues - add namespace and FileCompiler=0 to bypass PW's FileCompiler (slow compile on Win localhost, may need modules refresh)
  11. That's a great idea, thanks for the reminder, I'll add soon.
  12. @adrian Thanks, I've fixed these. The uikit field with issue is solved by adding the fields (max limit and asm placeholder) after the Required field. @ottogal I wasn't able to find a CSS-only solution to the sticky menu + jump link issue you mentioned. Surely there's one but I've spent too much time on it without success so I let it go instead. I could add JS but that doesn't appeal to me. There's a new productivity tweak for the Delete and Trash pagelist actions: if ctrl key is pressed you can skip the confirmation step. I found it very handy to quickly get rid of test pages. (on the Trash action I mean the one added by AOS that is available for non-superusers). I'll release the update soon.
  13. Version 1.3.7 is uploaded. Big thanks to @matjazp, this update is largely based on his excellent work. Changelog skip unnecessary redirect on modal save (by matjazp) new "page-add" action to add child (requested/contributed by matjazp) use monospace font in module settings field styleOverrides (by matjazp) new setting: disable loading FEEL CSS (requested by matjazp) remove system templates from module settings JavaScript callback updates and documentation several minor tweaks
  14. Hi, (1) I could reproduce, thanks. For a quick fix use this, or wait for a new version: html.pListShowActions .content .PageList .PageListItem { width: 100%; } (2) I'm aware of this, will try to fix with some CSS. I recommend using Reno or Uikit theme, most AOS features are targeted/tested in them.
  15. Version 1.9.4 is available: new: extra columns on Fields setup page showing description, notes, id and inputfield class (Misc) skip autosizing textareas having "noAutosize" classname (requested by bernhard) add cache busting string to assetPaths (requested by Robin S) check if $_SERVER['HTTP_REFERER'] exists before redirect (reported by Robin S) fix 1px title field misalignment caused by casechanger (reported by Robin S)
  16. I guess the LanguageSupport module won't make a site multilanguage (but I could be wrong). I would try installing it without adding any extra languages and see if PagePaths module still works as expected.
  17. @bernhard It does seem to work - or do you mean you are not able to add the .noAutosize classes? @Robin S Just added the cache bust strings to assetpaths, thanks for the suggestion. Will be available in v1.9.4. Here is a preview of the Fields page with additional data like inputfield classes, description, notes and IDs. It seems impossible to add column headers to the extra columns but i think it's quite obvious even without them.
  18. I came to the same conclusion when using the Page Protector module, uninstalling the SessionLoginThrottle module: I think it's a bug, non-superusers getting 500 error.
  19. tpr

    Nexoc Notebooks

    Isn't it possible to get half pixels using translate too with percentage values?
  20. In ListerPro (commercial) you can add bookmarks so you can directly open one page as the root tree (as I know, I don't have ListerPro). You can achieve something similar with AdminOnSteroids module's NavItems tweak too.
  21. In v1.9.3 I switched to the $datetime api var in pagelist markup and introduced %modifiedUser% and %createdUser% tokens. As a result it is possible to display relative date like this: I never thought about this but it came from a request and seems like a nice addition. In fact I only knew that a relative date function exists in PW but not that it's also an api var. I was even happier when I learned that I need only slightly change the code to support both relative and the existing date formats with $datetime->date(). Full changelog: pagelist markup: switch to $datetime api var (allows relative datetime strings too) pagelist markup: add %createdUser% and %modifiedUser% tokens pagelistUnselect: fix Uikit theme spacing issue (reported by Robin S) CKEditor plugin Link Files Menu: apply fix from Robin S from his original module (ajax response not working for non-superusers)
  22. I don't really agree with the article. Perhaps that was true back then but nowadays people are used to it (or perhaps I'm too much of a designer :)). According to that logic the eg. the search icon (magnifying glass) could be on a ban list.
  23. I also use something like @horst but only with without eot, svg and ttf (plus with a stylus or scss mixin), see https://stackoverflow.com/questions/36105194/are-eot-ttf-and-svg-still-necessary-in-the-font-face-declaration
  24. This may come handy ? https://google-webfonts-helper.herokuapp.com/fonts
×
×
  • Create New...