Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rivimey created an issue. See original summary.

rivimey’s picture

Title: Improve test coverage and function docs » Improve test coverage and function docs: context
rivimey’s picture

FileSize
12.38 KB

A first round: testing the ctools_context_id and ctools_context_next_id functions.
Plus some minor changes in context.inc to bring it into the php 5 era ('var').

Note: there are known exception failures here caused by the tests intentionally not including 'id', 'name' or both expected keys. I expect a change to the context.inc code is needed to fix these.

rivimey’s picture

Included some more tests and a new test class, for the miscellaneous functions in the ctools.module file.

The patch ctools-test_coverage-2829295-7x1x-4.patch is against now-current ctools HEAD, and includes patch 49 of #2827100: Improve test coverage and function docs, which is a prerequisite of this patch.
The 'interdiff' patch is the work covered in this issue, -- it is an interdiff back to patch 49.

In the new code I have added 2 new functions to the main codebase, ctools_classes_reset() and ctools_get_classes, to wrap the use of drupal_static and the function name shared by ctools_process(), ctools_classes_add() and ctools_classes_remove(). I am not expecting it to cause any difficulties....

Creating suitable tests for the ctools_process() code itself is a WIP.

rivimey’s picture

Status: Active » Needs review
rivimey’s picture

Assigned: rivimey » Unassigned

Status: Needs review » Needs work

The last submitted patch, 4: ctools-test_coverage-2829295-7x1x-4.patch, failed testing.

rivimey’s picture

Status: Needs work » Needs review
FileSize
27.44 KB
rivimey’s picture

darrenwh’s picture

Status: Needs review » Needs work
  1. +++ b/includes/context.inc
    @@ -270,6 +270,11 @@ function ctools_context_filter($contexts, $required) {
    +/**
    

    This could do with some comments

  2. +++ b/includes/context.inc
    @@ -270,6 +270,11 @@ function ctools_context_filter($contexts, $required) {
    + * @param $contexts
    

    What type of parameters are these? int, array bool etc? Ps include in comment.

  3. +++ b/includes/context.inc
    @@ -311,6 +316,13 @@ function ctools_context_selector($contexts, $required, $default) {
    +/**
    

    This could do with some comments

  4. +++ b/includes/context.inc
    @@ -311,6 +316,13 @@ function ctools_context_selector($contexts, $required, $default) {
    + * @param $required
    

    What type of parameters are these? int, array bool etc? Ps include in comment.

  5. +++ b/includes/context.inc
    @@ -703,11 +715,15 @@ function ctools_context_keyword_substitute($string, $keywords, $contexts, $conve
    +  // If not set or 'falsy'.
    

    Perhaps FALSE? Instead of falsy ;-)

  6. +++ b/tests/ctools.test
    @@ -0,0 +1,235 @@
    +
    

    Needs @file tag

rivimey’s picture

Hi Darren, thanks for the check. Another rabbithole... I hope I've addressed your comments and done a bunch more as well.

Would much appreciate any checking on the validity of the comments I've made, especially around ctools_context_select() which confused me for a bit. I have had to leave some doc comments sparser than I'd like because I just don't know enough of what is happening :(

Added an interdiff too :)

rivimey’s picture

Status: Needs work » Needs review
darrenwh’s picture

Status: Needs review » Needs work

A few observations:

  1. +++ b/ctools.api.php
    @@ -229,6 +232,28 @@ function hook_ctools_entity_context_alter(&$plugin, &$entity, $plugin_id) {
    + *   The current context plugin object. If this implemented a 'convert' function,
    

    Sorry mega trivial, but goes over 80 char limit

  2. +++ b/ctools.module
    @@ -528,6 +553,8 @@ function ctools_class_add($classes, $hook = 'html') {
    +    // TODO: consider using explode(' ', $classes);
    +    // TODO: consider checking that $classes is a string before adding.
    

    Should be @todo

  3. +++ b/includes/context.inc
    @@ -28,27 +28,27 @@
    +
    

    This needs a docblock.

  4. +++ b/includes/context.inc
    @@ -28,27 +28,27 @@
    +  public function is_type($type) {
    

    Please add a docblock

  5. +++ b/includes/context.inc
    @@ -58,30 +58,30 @@ class ctools_context {
    +  public function get_argument() {
    

    Dock block and others below

  6. +++ b/includes/context.inc
    @@ -270,6 +272,21 @@ function ctools_context_filter($contexts, $required) {
    + * @return array
    

    May be worth adding comment covering whats returned in this array?

  7. +++ b/includes/context.inc
    @@ -398,7 +446,8 @@ function ctools_context_converter_selector($contexts, $required, $default) {
    +      $result[] = _ctools_context_converter_selector($contexts, $r, $dv, $count++);
    

    Could $r be refactored to be more descriptive?

  8. +++ b/includes/context.inc
    @@ -547,17 +622,29 @@ function ctools_context_convert_context($context, $converter, $converter_options
    +      // TODO: What's the diff btw following and "empty($r)" ?
    

    Us @todo instead of //TODO

  9. +++ b/includes/context.inc
    @@ -703,11 +820,15 @@ function ctools_context_keyword_substitute($string, $keywords, $contexts, $conve
    +  // TODO: is '' the appropriate default value?
    

    @todo

  10. +++ b/includes/context.inc
    @@ -715,10 +836,13 @@ function ctools_context_id($context, $type = 'context') {
      *   A list of context descriptor objects, i.e, arguments, relationships, contexts, etc.
    

    Humm? Not covered by your patch, this line runs over 80 char limit

  11. +++ b/includes/context.inc
    @@ -729,9 +853,10 @@ function ctools_context_next_id($objects, $name) {
    +      // TODO: When obj has no 'id', should we increment local id? $id = $id + 1;
    

    @todo

  12. +++ b/includes/context.inc
    @@ -823,6 +948,10 @@ function ctools_context_get_context_from_argument($argument, $arg, $empty = FALS
    + * @return array
    

    Please add comments for return value and @param if possible

rivimey’s picture

Status: Needs work » Needs review
FileSize
18.51 KB
65.43 KB

Thanks, Darren. Been doing a bit more today, hope these changes are enough :-)

Some very small code changes, mostly more docs as requested.

Mostly the changes are to move initialisations into the constructor, which is clearer, and recommended, and occasionally required.

stella’s picture

Status: Needs review » Needs work

Looks good, just a few small changes:

  1. +++ b/includes/context.inc
    @@ -397,8 +592,11 @@ function ctools_context_converter_selector($contexts, $required, $default) {
    +    foreach ($required as $id => $dependency) {
    +      $dv = isset($default[$id]) ? $default[$id] : '';
    +      $result[] = _ctools_context_converter_selector(
    +        $contexts, $dependency, $dv, $count++
    +      );
    

    It'd be good to rename the $dv variable to something easily understandable.

  2. +++ b/includes/context.inc
    @@ -547,22 +793,35 @@ function ctools_context_convert_context($context, $converter, $converter_options
    +      // @todo What's the difference between the following and "empty($r)" ?
    

    $r variable has now been renamed to $item, so it'd be good to update the comment to match.

gaurav.kapoor’s picture

Status: Needs work » Needs review
FileSize
65.44 KB
rivimey’s picture

FileSize
26.08 KB
81.88 KB

Thanks, Gaurav.

Done a but more now; getting there.

I would appreciate anyone reviewing the meaning of the function docs, not (just) DCS issues :-)

darrenwh’s picture

Status: Needs review » Needs work

Few! this is a long patch :-/ Notes below

  1. +++ b/includes/context.inc
    @@ -28,28 +27,104 @@
    +   * @var
    

    This is missing a variable type and desription?

  2. +++ b/includes/context.inc
    @@ -28,28 +27,104 @@
    +   * @var
    

    Missing var type and description

  3. +++ b/includes/context.inc
    @@ -28,28 +27,104 @@
    +    /* Other vars are NULL. */
    

    This should use inline commented syntax //

  4. +++ b/includes/context.inc
    @@ -58,30 +133,63 @@ class ctools_context {
    +   * @return null
    

    Missing method description.

  5. +++ b/includes/context.inc
    @@ -91,35 +199,56 @@ class ctools_context {
    +   * Keyword strings associated with the context.
    

    needs a couple of spaces before Keyword

  6. +++ b/includes/context.inc
    @@ -167,7 +325,28 @@ class ctools_context_required {
    +   * context list, there is a good chance that what happened is our context
    

    Perhaps: is the context

  7. +++ b/includes/context.inc
    @@ -177,11 +356,12 @@ class ctools_context_required {
    +    // context list, there is a good chance that what happened is our context
    

    perhaps: is the context

  8. +++ b/includes/context.inc
    @@ -203,24 +383,70 @@ class ctools_context_required {
    +   *   The matching ctools_context, or False if no such context was found.
    

    Perhaps lowercase or full caps for false?

  9. +++ b/includes/context.inc
    @@ -1126,9 +1550,13 @@ function ctools_context_get_context_from_context($context, $type = 'context', $a
    + *   If True, placeholders are acceptable.
    

    Perhaps if TRUE

  10. +++ b/plugins/contexts/token.inc
    @@ -46,7 +46,9 @@ function ctools_context_token_convert_list() {
    + * @see ctools_context_convert_context().
    

    Missing parameter types and comments

rivimey’s picture

FileSize
3.36 KB
83.23 KB

Hi Darren, thanks for your notes.

Regarding (1), (2), I do not know any more than is there.. I can infer some things (such as 'array' etc) but this one will have to be an exercise for the reader!

For similar reasons my effort with (4) is somewhat circular.

Re (8) I prefer using True / False in English, to be clear I'm talking about logical true rather than an English hand-wavy true.

I've addressed the rest... all good?

rivimey’s picture

Status: Needs work » Needs review
darrenwh’s picture

Status: Needs review » Reviewed & tested by the community

Looks good

japerry’s picture

Status: Reviewed & tested by the community » Fixed

Whew, long indeed! Committed.

  • japerry committed f66c0ce on 7.x-1.x authored by rivimey
    Issue #2829295 by rivimey, darrenwh: Improve test coverage and function...
klausi’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

MegaChriz’s picture

This broke the Feeds tests on PHP 5.3 because the short array syntax is used. Opened #2942581: ctools.test breaks Feeds tests on PHP 5.3 because of short array syntax.