CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • Unit Testing (Moderator: Michał Mach) »
  • array input function
Pages: [1]

Author Topic: array input function  (Read 2743 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
array input function
February 24, 2011, 05:49:40 pm
At the moment most api tests test that if the input is not an array the error message e.g

    function testGetParamsNotArrayContribution()
    {
        $params = 'string';                           
        $contribution =& civicrm_contribution_get($params);
        $this->assertEquals( $contribution['is_error'], 1 );
        $this->assertEquals( $contribution['error_message'], 'Input variable `params` is not an array' );
    }


This seems like a lot of duplicated code having it in every test and where there are missing test classes / cases it isn't tested.

It would make sense to have a test that runs through every api file & tests each create, get, delete function for this but that would break the structure.

Or alternatively, could each test call the same function which tests create, get, delete (or probably any function that doesn't start with _) for this. That would still miss those with no class but get those missing the specific test.

If both of those ideas break the ethos of testing we could at least define the error string in CiviUnitTestCase rather than in each test case?
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: array input function
February 24, 2011, 08:39:34 pm

I think using file traversal and automating the test code for non-array parameters is definitely a step on the right direction.

So basically we can write a super test params not array function which:

1. Loads all the api files
2. foreach function that matches the api signature (civicrm_*_[create|update...]) calls it with a non-array and checks the string

we can use the below php function to get all api related functions:

http://us2.php.net/manual/en/function.get-defined-functions.php

wanna take a shot at handling this?

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: array input function
February 25, 2011, 12:43:57 am
Hi,

Nice one. Would make sense to extend later to verify that _delete _modify generates errors if it hasn't param['id'].

As for the signature, the more I think about it, the more it should be civicrm_api3_ or something not the same as the api v2 indeed.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: array input function
February 25, 2011, 12:47:22 am
X - I had a quick go @ re-factoring the functions with zend studio - seems like an option for renaming them. How cool are you feeling about sed?

I'm just not sure about checking the change into trunk now that we're alpha
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: array input function
February 25, 2011, 12:52:16 am
Better be too late that even more too late IMO.

Let's check on IRC what civicore think about it.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: array input function
February 25, 2011, 03:23:14 am
I renamed them on my local -patch here

http://pastebin.com/MBfZcJX8

They are working as far as I can test them but I think api/v3/AllTests has been disabled so I can only pick off individual ones & I haven't got selenium tests to run the main AllTests so have run some of apiv3 & am running api v2 now
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: array input function
February 27, 2011, 01:09:02 pm
OK - check

http://svn.civicrm.org/civicrm/branches/trunk.api/tests/phpunit/api/v3/APIStandardsTest.php

At the moment it fails on

1) api_v3_APIStandardsTest::testParamsNotArray
civicrm_api3_case_create does not return correct error when a non-array is submi
tted in line 92
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-Input variable `params` is not an array
+Invalid or missing input parameters. Must provide an associative array.

Which is because 'civicrm_api3_verify_mandatory hasn't been added into the Case api as yet

Ideally ALL api functions that don't start with _ would have to meet the api standards (which might mean renaming some functions that are internal with the _)
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • Unit Testing (Moderator: Michał Mach) »
  • array input function

This forum was archived on 2017-11-26.