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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • test + document
Pages: [1]

Author Topic: test + document  (Read 1296 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
test + document
January 14, 2011, 08:32:23 am
OK - this is working on mine but not on   

http://api.civicrm.org/v3/

If you look under civicrm_activity_create on http://api.civicrm.org/v3/ you see

Quote
    * return: Newly created Activity object
    * todo: Erik Hommel 16 dec 2010 check if create function processes update correctly when activity_id is passed
    * todo: Erik Hommel 16 dec 2010 introduce version as param
    * todo: Erik Hommel 16 dec 2010 check for mandatory fields with utils function civicrm_verify_mandatory
    * todo: Erik Hommel 16 dec 2010 check permissions with utils function civicrm_api_permission_check
    * example: example not found

On mine example links to the code in the file  * @example example/ActivityCreate.php

But I wrote a quick test in the test suite & it basically checks that the 2 functions in api/v3/example/ActivityCreate.php return the same result.

This seems to me to give quick a good 'visual' onto what the api code is doing (and what is & isn't covered by the test suite) & it's probably easier to do than writing 'normal' tests or putting examples on the wiki - since you just have to add a print_r in your test & copy the results to the 'expected result' function & of course I took the input from     function testActivityCreate( )

Code: [Select]
     /**
     *  Test civicrm_activity_create() using example code
     */
    function testActivityCreateExample( )
    {
      require_once 'api/v3/example/ActivityCreate.php';
      $result = api_testActivityCreate( );
      $expectedResult = api_v3_ActivityCreateExpectedResult();
      $this->assertEquals($result,$expectedResult);
    }
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

Michał Mach

  • Ask me questions
  • ****
  • Posts: 748
  • Karma: 59
    • CiviCRM site
  • CiviCRM version: latest
  • CMS version: Drupal and Joomla latest
  • MySQL version: numerous
  • PHP version: 5.3 and 5.2
Re: test + document
January 17, 2011, 06:38:39 am
Eileen - did a quick fix, take a look at rev 31839.

Thx,
m
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

My absolute favourite: Wordpress Integration!.

Donate Now!

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: test + document
January 17, 2011, 01:46:04 pm
Ok - cool - so the link to the example is there now - I stuck in the inline tag too although I suspect you may have tried it and it may not work?

But the question is now whether it is a good idea - as Xavier pointed out the examples folder should probably go in the test directory

I kind of like it because it is linkable from the phpdoc code, it shows an example that is 'proven' to work by virtue of being a test, it gives quite good visibilty to how the output works - which in this case highlights how many fields aren't being set and encourages people to improve the tests.

I would only recommend using it for the main success tests and as an additional probably to what is there

ie

test_apiv3_activity_create
test_apiv3_activity_get
test_apiv3_activity_delete

Each one would probably need it's own file to keep it clean
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

Michał Mach

  • Ask me questions
  • ****
  • Posts: 748
  • Karma: 59
    • CiviCRM site
  • CiviCRM version: latest
  • CMS version: Drupal and Joomla latest
  • MySQL version: numerous
  • PHP version: 5.3 and 5.2
Re: test + document
January 18, 2011, 04:58:52 am
Quote from: Eileen on January 17, 2011, 01:46:04 pm
Ok - cool - so the link to the example is there now - I stuck in the inline tag too although I suspect you may have tried it and it may not work?

Yup, tried, nope, didn't work. I would say - for examples, good enough for now. If we figure out how to fix inline later on, we can quickly change it.

Quote from: Eileen on January 17, 2011, 01:46:04 pm
But the question is now whether it is a good idea - as Xavier pointed out the examples folder should probably go in the test directory

Yes and no. Tests have their own needs for the quantity of code, so displaying whole test case as an example is a bit non meaningful. Inline example has ability to limit the scope of displayed code to a piece designated by start and end line (given as parametrs to {@example}), but a) it doesn't work for us, b) tests will change and it will put the need to upfate line numbers every time something is modified within test. I would say - do this in api directory, of "fire and forget" basis. Since we're aiming at stability, it should be possible to write examples once. Additional argument - not every example should/needs to be run as test, so it doesn't belong in tests directory. On the other hand, the less code to maintain, the better - so if there is a way to come to terms with all of the above doubts, examples could be stored in tests dir as well.

Thx,
m
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

My absolute favourite: Wordpress Integration!.

Donate Now!

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: test + document
January 18, 2011, 07:01:34 am
Quote from: Michał Mach on January 18, 2011, 04:58:52 am
b) tests will change and it will put the need to upfate line numbers every time something is modified within test. I would say - do this in api directory, of "fire and forget" basis.

Just that we point to the test directory on a regular basis as examples (and with the not so hidden agenda of getting more people involved in the tests).

What about a {@example ContactTest.php} that we put next to the @subpackage and use to generate a

"To know more about how to use these functions, read http://svn.civicrm.org/civicrm/branches/trunk.api/tests/phpunit/api/v3/ContactTest.php"

Or we might even be good enough to be able to automatically do it (href= " http://svn.civicrm.org/civicrm/branches/trunk.api/tests/phpunit/api/v3/" .$entity . "Test.php")



Quote from: Michał Mach on January 18, 2011, 04:58:52 am
Since we're aiming at stability, it should be possible to write examples once.

Piotr, got a new quote for your email signature
... and whatever you smoke, please do bring some when you come to Brussels ;)
-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: test + document
January 18, 2011, 12:09:09 pm
my recommendation is that we have  a folder called 'examples' either in api/v3/examples or test/api/v3/examples

and each operation gets it's own file

ActivityCreate.php
ActivityGet.php

with the functions

test_api_v3_activity_create(){
}

test_api_v3_activity_create_expectedresult(){
}

Then we don't need to muck around with line numbers

The arguments for in the tests dir is it brings people's attention to the test stuff. Alternatively the api dir may be more intuitive & obvious. Either way I can probably create some & move them fairly easily later. I think having a few more in place may suggest the best approach

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: test + document
January 18, 2011, 12:19:55 pm
deal.

Michal, do you think we could generate that automatically from the xml schema?

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

Michał Mach

  • Ask me questions
  • ****
  • Posts: 748
  • Karma: 59
    • CiviCRM site
  • CiviCRM version: latest
  • CMS version: Drupal and Joomla latest
  • MySQL version: numerous
  • PHP version: 5.3 and 5.2
Re: test + document
January 20, 2011, 03:02:13 am
Guys, I really don't follow you, we must be smoking some totally different things. :-)

@Eileen:
How does it differ from actual tests (apart from naming)?

@Xavier:
Generate what? Examples? And what XML schema has to do with API methods (apart from the list of return values)? :-)

Thx,
m
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

My absolute favourite: Wordpress Integration!.

Donate Now!

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: test + document
January 20, 2011, 03:14:16 am
Agree, that's getting confused ;)

I was wondering if the example civicrm_entity_create could be generated automatically from the schema (cause the schema knows all the fields that can be put into entity). This being said, the schema doesn't know what values are correct for each field, so probably a bad idea from me.

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: test + document
January 24, 2011, 01:19:48 am
Michal - only differs from other tests in that it's written in a way designed to be more accessible as documentation (and hopefully to encourage others to submit patches)
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

Michał Mach

  • Ask me questions
  • ****
  • Posts: 748
  • Karma: 59
    • CiviCRM site
  • CiviCRM version: latest
  • CMS version: Drupal and Joomla latest
  • MySQL version: numerous
  • PHP version: 5.3 and 5.2
Re: test + document
January 26, 2011, 06:37:28 am
Eileen,

Than drop test_ from function names. :-) Maybe call it activity_create_example() or similar?

Thx,
m
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

My absolute favourite: Wordpress Integration!.

Donate Now!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • test + document

This forum was archived on 2017-11-26.