Menu

Having every bit of information defined at every aspect of application makes system actually finished.
Piotr Masełkowski, Maslosoft Founder

Codeception Acceptance: Check if element is visible

There are cases, there User Interface state might depend on various factors. Or in our tests there might be case where button can be toggled or might get activated by remote action.

The first solution one might think of is to conditionally invoke action on element. Depending whether it is visible or not.

Hide tooltips on dropdowns in twitter's bootstrap 3

Tooltip left over dropdown
Tooltip left visible over
dropdown

When using tooltips on buttons which have dropdown menus, the tooltip might not disappear as we would like to, leaving it visible. This might even block user action. To avoid this issue, tooltip need to be hidden when dropdown is shown. But it turned out that it is not enough, as it might pop up again. Also when dropdown is closed by another click, tooltips still might be left visible.

In summary 

It turned out that tooltip must be hidden on events:

  1. Dropdown shown
  2. Dropdown hidden
  3. Mouse entering dropdown menu

Panoramio and digart termination

panoramio-logo.png
Panoramio Logo

The Panoramio was a world known photo sharing service allowing people to upload photos and place them on map. It was sold to Google. Then google decided to close it, effectively destroying community gathered around Panoramio. For the sake of integrating it with google maps.

Another, maybe not so known Polish service digart is going to be shut down this month. It is also photo and graphic sharing service with community, which was sold to large Polish portal Onet. Again all of the people (yes people, not users!) creating community are left with option to just download their photos, having all their contributions vanished.

Original authors of those websites are upset with decision of new owners. It seems that many web applications are being abandoned by big players, for which relatively small community is meaningless. There are many more cases like this. The only solution might be that web applications should be paid, thus allowing original authors to keep them indefinitely. As long as community is willing to keep their assets on application. So that owners would not be forced to sell their creation along with people.

Introducing polite PHP in error handler

Due to issues of handling exception in __toString PHP's method, the error handler can be invoked in such methods to catch exception and display nice stack trace. However using error handling in __toString methods need special care, thus very polite syntax have been introduced.

Example code to handle exceptions

public function __toString()
{
    try
    {
        // Do some stuff throwing exception
        return 'my result';
    }
    catch (Exception $exception)
    {
        ErrorHandler::please()->takeCareOf($this, $exception);
    }
}

This is actual working code in components project:)

Mangan Unique Validator with extra criteria

When developing web applications human or robot input validation is crucial for data integrity. It is possible to set database constraints to keep data consistent - and it should be done - however to display informative message we use validators. These analyze situation and try to display useful information. The unique validator for instance prevents inserting duplicated elements into database.

Use case for extra criteria parameter

The case I stumbled upon was to validate domain added by anyone from around the internet and allow to validate this domain. The point is that anyone can add any domain, and it is perfectly fine. However only one domain having same host can be verified. This use case is supported by Mangan Unique Validator. It allows to set additional criteria, which will be merged with uniqueness checking parameters.

The parameters for property criteria is same as for Criteria class constructor. Which is rather deep array, but can be written in many lines.

Example criteria parameters on unique validator annotation

/**
 * @UniqueValidator(
* 'criteria' => [
* 'conditions' => [
* 'verified' => ['==' => true]
* ]
* ],
* 'message' => @Label('Domain {value} is already verified by another account')
* ) */ public $host = ''; public $verified = false;

Trashing domain

Additional criteria with verified attribute check is sufficient to prevent multiple hosts to be verified. When one of visitor verifies domain, the others have message displayed informing that the domain is verified by someone else. The first thing to do is to move domain to trash, as it is no longer usable. But the Unique Validator will prevent this, because the domain is already verified.

There is additional feature of Mangan, called scenarios. These allow different behaviors depending on what is going to happen with model. In our case we want to allow trashing domain even if it fails uniqueness constraint. Adding trash scenario to except property solves this issue.

Example of using except to allow trashing

/**
 * @UniqueValidator(
 *     'except' => ['trash'],
* 'criteria' => [
* 'conditions' => [
* 'verified' => ['==' => true]
* ]
* ],
* 'message' => @Label('Domain {value} is already verified by another account')
* ) */ public $host = ''; public $verified = false;

To avoid using magic string the constant TrashInterface::ScenarioTrash can be used.