You are here

protected function CommerceAjaxAddCartBase::clickLinkAjax in Commerce Ajax Add to Cart 7.2

Ajax follows a link by name.

Test API is similar to clickLink().

@todo This does not perfectly checks that ajax link is working properly. Find a solution to check whether ajax links are working.

If the link is discovered and clicked, the test passes. Fail otherwise.

Parameters

string $label: Text between the anchor tags.

int $index: Link position counting from zero.

Return value

array/boolean Json decode array on success, or FALSE on failure.

1 call to CommerceAjaxAddCartBase::clickLinkAjax()
CommerceAjaxAddCartUI::defaultConfigurationTests in tests/dc_ajax_add_cart_ui.test
Common tests carried out with default configuations of the module.

File

tests/dc_ajax_add_cart_ui.test, line 65
Functional tests for commerce ajax add to cart module.

Class

CommerceAjaxAddCartBase
Abstract class for commerce ajax add to cart testing.

Code

protected function clickLinkAjax($label, $index = 0) {
  $url_before = $this
    ->getUrl();
  $urls = $this
    ->xpath('//a[normalize-space(text())=:label]', array(
    ':label' => $label,
  ));
  if (isset($urls[$index])) {
    $url_target = $this
      ->getAbsoluteUrl($urls[$index]['href']);
    $this
      ->pass(t('Clicked link %label (@url_target) from @url_before', array(
      '%label' => $label,
      '@url_target' => $url_target,
      '@url_before' => $url_before,
    )), 'Browser');
    return $this
      ->drupalGetAJAX($url_target);
  }
  $this
    ->fail(t('Link %label does not exist on @url_before', array(
    '%label' => $label,
    '@url_before' => $url_before,
  )), 'Browser');
  return FALSE;
}