This is an introduction to ExtDiamond. To see it in action, you can read the sample tests in Example/tests/*Test.php
A complete API documentation will be soon available. Also, specific widget references are still few and will be more in the next versions.
Glossary – Type of references
Ext Reference – points to any component (window, grid, form, …) – that’s generic
DOM Reference – points to any DOM piece – even not releated to Ext
Variable Reference – points to any JS variable
Widget Reference – points to a specific component (a grid, a form, ..)
Access to some widget
In your tests, extending
ExtDiamond_TestCase you have access to
This method accepts as unique argument the CSS class that can be used to reach the ExtJS rendered component. It returns an
ExtDiamond_Proxy_ExtReference which can be used to access properties (or casted to a more specific reference).
$grid = $this->getComponentByClass('firewall-window');
Even if the main work is done directly on properties/methods of ExtJS, there are functions defined internally in ExtDiamond. Specific functionality of widgets are defined in specific classes. For example, the Grid reference has the
getRow(i)method which returns the i-th row of the grid as DomReference.
$grid = $this->getComponentByClass('firewall-grid'); $grid->getRow(0); // fatal error: call to undefined method getRow()
$grid = $this->getComponentByClass('firewall-grid')->handleAs('Grid'); $grid->getRow(0); // this will work
For example, your grid has an ‘add’ button. You want to be sure that creating a new record, it has phantom (this is simple –
phantom property) and it has a different background to highlight that is not saved. The DOM reference that you can get with
getRow() will let you assert that its
className property contains (for example) ‘phantom-record’.
Accesss to properties
$ref->$name: magically gets a property inside the given reference.
$name can be anything – even private stuff (spy privates, but do not touch). Please note, if the property
$name does not exists in
$ref, an exception is thrown.
getProperties(): gets all properties as array. You will get tons of lines if you
getScalarProperties(): gets only properties with scalar value. This will exclude objects, arrays and functions. This is
$grid = $this->getComponentByClass('firewall-grid'); $recordsCount = $grid->store->totalLength; var_dump($grid->store->getScalarProperties());
You can also call functions on objects. The result may be a scalar value, or a
VarReference if the function’s result is an object or an array. In that case, you will be able to navigate the result properties as above.
$store->getAt(2)->phantom // ^ function call // ^ navigation in function result
Getting the DOM
You need to access the DOM if you want to assert on the markup/styles, simulate events like click or type text in fields via Selenium.
Again, do not put ids in your tests. If you do not have CSS classes, you are not forced to add them. See this example:
$selector = '#' . $formPanel->id; $formDOM = $this->getDomBySelector($selector);
Another way is to use the widget-specific functions (when available).
For example, if you cast a grid with
handleAs('Grid'), you will get access to
getRow(i), which returns a DomReference to the row’s HTML code.
The last way to get a DOM reference is starting from another DOM reference. You can use this to refine the search of your target:
//$cell is a DomReference $acceptBtn = $cell->getRefereceTo('.firewall-accept');
In this way you will find the first element matching that class, only inside that cell.
You may need to access some variables of the browser. You can even access the Ext singleton, or the whole window:
$ext = $this->getVariableByName('Ext'); echo $ext->version;