Chris@0: assertTourTips();
Chris@0: *
Chris@0: * // Advanced example. The following would be used for multipage or
Chris@0: * // targeting a specific subset of tips.
Chris@0: * $tips = array();
Chris@0: * $tips[] = array('data-id' => 'foo');
Chris@0: * $tips[] = array('data-id' => 'bar');
Chris@0: * $tips[] = array('data-class' => 'baz');
Chris@0: * $this->assertTourTips($tips);
Chris@0: * @endcode
Chris@0: */
Chris@0: public function assertTourTips($tips = []) {
Chris@0: // Get the rendered tips and their data-id and data-class attributes.
Chris@0: if (empty($tips)) {
Chris@0: // Tips are rendered as
elements inside .
Chris@0: $rendered_tips = $this->xpath('//ol[@id = "tour"]//li[starts-with(@class, "tip")]');
Chris@0: foreach ($rendered_tips as $rendered_tip) {
Chris@0: $attributes = (array) $rendered_tip->attributes();
Chris@0: $tips[] = $attributes['@attributes'];
Chris@0: }
Chris@0: }
Chris@0:
Chris@0: // If the tips are still empty we need to fail.
Chris@0: if (empty($tips)) {
Chris@0: $this->fail('Could not find tour tips on the current page.');
Chris@0: }
Chris@0: else {
Chris@0: // Check for corresponding page elements.
Chris@0: $total = 0;
Chris@0: $modals = 0;
Chris@0: foreach ($tips as $tip) {
Chris@0: if (!empty($tip['data-id'])) {
Chris@14: $elements = $this->xpath('//*[@id="' . $tip['data-id'] . '"]');
Chris@0: $this->assertTrue(!empty($elements) && count($elements) === 1, format_string('Found corresponding page element for tour tip with id #%data-id', ['%data-id' => $tip['data-id']]));
Chris@0: }
Chris@0: elseif (!empty($tip['data-class'])) {
Chris@14: $elements = $this->xpath('//*[contain(@class, "' . $tip['data-id'] . '")]');
Chris@0: $this->assertFalse(empty($elements), format_string('Found corresponding page element for tour tip with class .%data-class', ['%data-class' => $tip['data-class']]));
Chris@0: }
Chris@0: else {
Chris@0: // It's a modal.
Chris@0: $modals++;
Chris@0: }
Chris@0: $total++;
Chris@0: }
Chris@0: $this->pass(format_string('Total %total Tips tested of which %modals modal(s).', ['%total' => $total, '%modals' => $modals]));
Chris@0: }
Chris@0: }
Chris@0:
Chris@0: }