SimpleTest can't read json easily

Created on 1 March 2009, over 15 years ago
Updated 16 January 2024, 5 months ago

While writing some patches for taxonomy_autocomplete, I found myself unable to easily write SimpleTest cases to test it, since it changes the browser header and outputs JSON.

I tried to test by buffering the output of the function, but had problems because json_decode didn't always successfully convert the result to a non-null object, even when the JSON result appeared valid.

This would be easier to test if the code in the taxonomy_autocomplete function broken out into a helper function that would return an array. This way, the helper function could be tested without dealing with JSON, and the taxonomy_autocomplete function could just serve as the callback to serve JSON to the browser.

The code would look something like this:

<?php
function taxonomy_autocomplete($vid, $string='') {
  $matches = _taxonomy_autocomplete($vid, $string);
  drupal_json($matches);
}

function _taxonomy_autocomplete($vid, $string='') {
  // insert code from old taxonomy_autocomplete, but return the array of matches instead of outputting JSON.
}
?>

Does anyone have any comments or suggestions on this?

πŸ“Œ Task
Status

Closed: outdated

Version

9.5

Component
TaxonomyΒ  β†’

Last updated about 1 hour ago

  • Maintained by
  • πŸ‡ΊπŸ‡ΈUnited States @xjm
  • πŸ‡¬πŸ‡§United Kingdom @catch
Created by

πŸ‡ΊπŸ‡ΈUnited States soghad

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡³πŸ‡ΏNew Zealand quietone New Zealand

    More information was asked in this issue 10 years ago. That has not been supplied, there has been no further discussion and much has changed since this issue was opened. I am closing at outdated.

Production build 0.69.0 2024