User: sits    
  Date: 08/08/11 15:32:39

  Modified:    lib/Codestriker/Http UrlBuilder.pm Method.pm
  Added:       t/Http/Method add-topic.t
               lib/Codestriker/Http/Method AddTopicMethod.pm
  Log:
  Created AddTopic method for when a topic is added to a project.
  
  
  
  Index: add-topic.t
  ===================================================================
  RCS file: add-topic.t
  diff -N add-topic.t
  --- /dev/null 1 Jan 1970 00:00:00 -0000
  +++ add-topic.t       11 Aug 2008 22:32:38 -0000      1.1
  @@ -0,0 +1,37 @@
  +# Tests for the AddTopic method.
  +
  +use strict;
  +use Test::More tests => 3;
  +
  +use lib '../../../lib';
  +use Test::MockObject;
  +use Codestriker;
  +use Codestriker::Http::Method::AddTopicMethod;
  +
  +# Create a CGI mock object for these tests.
  +my $mock_query = Test::MockObject->new();
  +$mock_query->mock('url',
  +            sub { 'http://localhost.localdomain/codestriker/codestriker.pl' 
} );
  +
  +# Create two method objects to test each URL scheme.
  +my $url_cgi = Codestriker::Http::Method::AddTopicMethod->new($mock_query, 1);
  +my $url_nice = Codestriker::Http::Method::AddTopicMethod->new($mock_query, 
0);
  +
  +is($url_cgi->url(projectid => 10),
  +   $mock_query->url() . '?action=submit_new_topic',
  +   "View URL CGI syntax");
  +   
  +is($url_nice->url(projectid => 10),
  +   $mock_query->url() . '/project/10/topics/add',
  +   "View URL nice syntax");
  +   
  +# Check that the parameters extracted correctly.
  +my $mock_http_input = Test::MockObject->new();
  +$mock_http_input->{query} = $mock_query;
  +$mock_query->mock('path_info',
  +                  sub {
  +                     return $mock_query->url() . '/project/10/topics/add';
  +                  });
  +$mock_query->mock('param', sub { return undef; });                  
  +$url_nice->extract_parameters($mock_http_input);
  +is ($mock_http_input->{projectid}, "10", "project nice URL parameter 
extraction");
  
  
  
  
  
  Index: UrlBuilder.pm
  ===================================================================
  RCS file: 
/cvsroot/codestriker/codestriker/lib/Codestriker/Http/UrlBuilder.pm,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- UrlBuilder.pm     10 Aug 2008 12:18:44 -0000      1.36
  +++ UrlBuilder.pm     11 Aug 2008 22:32:38 -0000      1.37
  @@ -78,22 +78,7 @@
   # Create the URL for viewing a topic.
   sub view_url {
       my ($self, %args) = @_;
  -
  -    die "Parameter topicid missing" unless defined $args{topicid};
  -     die "Parameter projectid missing" unless defined $args{projectid};
  -
  -    if ($self->{cgi_style}) {
  -         return $self->{url_prefix} . "?action=view&topic=$args{topicid}" .
  -                    (defined $args{updated} ? "&updated=$args{updated}" : 
"") .
  -                        (defined $args{tabwidth} ? 
"&tabwidth=$args{tabwidth}" : "") .
  -                        (defined $args{mode} ? "&mode=$args{mode}" : "") .
  -                        (defined $args{fview} ? "&fview=$args{fview}" : "") .
  -                        (defined $args{filenumber} ? "#" . 
"$args{filenumber}|$args{line}|$args{new}" : "");
  -    } else {
  -     return $self->{url_prefix} . 
"/project/$args{projectid}/topic/$args{topicid}/view/text" .
  -            (defined $args{fview} ? "/filenumber/$args{filenumber}" : "") .
  -                        (defined $args{filenumber} ? "#" . 
"$args{filenumber}|$args{line}|$args{new}" : "");
  -    }    
  +    return 
Codestriker::Http::Method::ViewTopicTextMethod->new($query)->url(%args);
   }
   
   # Create the URL for downloading the topic text.
  @@ -115,69 +100,31 @@
   # Create the URL for creating a topic.
   sub create_topic_url {
       my ($self, $obsoletes) = @_;
  -
  -    if ($self->{cgi_style}) {
  -        return $self->{url_prefix} . "?action=create" .
  -                (defined $obsoletes ? "&obsoletes=$obsoletes" : "");
  -    } else {
  -     return $self->{url_prefix} . "/topics/create" .
  -                (defined $obsoletes ? "/obsoletes/$obsoletes" : "");
  -    }
  +    return 
Codestriker::Http::Method::CreateTopicMethod->new($query)->url($obsoletes);
   }        
   
   # Create the URL for editing a topic.
   sub edit_url {
       my ($self, %args) = @_;
  -     
  -    die "Parameter topicid missing" unless defined $args{topicid};
  -     die "Parameter projectid missing" unless defined $args{projectid};
  -
  -    if ($self->{cgi_style}) {
  -         return $self->{url_prefix} . 
"?action=edit&fn=$args{filenumber}&line=$args{line}&new=$args{new}&topic=$args{topicid}"
 .
  -             (defined $args{anchor} ? "&a=$args{anchor}" : "") .
  -             (defined $args{context} ? "&context=$args{context}" : "");
  -    } else {
  -     return $self->{url_prefix} . 
"/project/$args{projectid}/topic/$args{topicid}/comment/" .
  -            "$args{filenumber}|$args{line}|$args{new}/add" .
  -                    (defined $args{anchor} ? "/anchor/$args{anchor}" : "") .
  -                    (defined $args{context} ? "/context/$args{context}" : 
"");
  -    }
  +    return 
Codestriker::Http::Method::AddCommentMethod->new($query)->url(%args);
   }
   
   # Create the URL for viewing a new file.
   sub view_file_url {
       my ($self, %args) = @_;
  -
  -    die "Parameter topicid missing" unless defined $args{topicid};
  -     die "Parameter projectid missing" unless defined $args{projectid};
  -
  -    if ($self->{cgi_style}) {
  -        return $self->{url_prefix} . 
"?action=view_file&fn=$args{filenumber}&" .
  -                "topic=$args{topicid}&new=$args{new}" .
  -                (defined $args{mode} ? "&mode=$args{mode}" : "") .
  -                "#$args{filenumber}|$args{line}|$args{new}";
  -    } else {
  -     return $self->{url_prefix} . 
"/project/$args{projectid}/topic/$args{topicid}/view/file/filenumber/$args{filenumber}"
 .
  -                (defined $args{mode} ? "/mode/$args{mode}" : "") .
  -                "#$args{filenumber}|$args{line}|$args{new}";
  -    }
  +    return 
Codestriker::Http::Method::ViewTopicFileMethod->new($query)->url(%args);
   }
   
   # Create the URL for the search page.
   sub search_url {
       my ($self) = @_;
  -
  -    if ($self->{cgi_style}) {
  -        return $self->{query}->url() . "?action=search";
  -    } else {
  -     return $self->{query}->url() . "/topics/search";
  -    }
  +    return 
Codestriker::Http::Method::SearchTopicsMethod->new($query)->url(%args);
   }
   
   # Create the URL for the documentation page.
   sub doc_url {
       my ($self) = @_;
  -    return $self->{htmldir};
  +    return 
Codestriker::Http::Method::StaticResourcesMethod->new($query)->url(%args);
   }
   
   # Create the URL for listing the topics (and topic search). See
  @@ -201,105 +148,54 @@
   # Create the URL for listing the topics.
   sub _list_topics_url {
       my ($self, %args) = @_;
  -    
  -    return $self->{list_topics_method}->url(%args);
  +    return 
Codestriker::Http::Method::ListTopicsMethod->new($query)->url(%args);
   }
   
   
   # Construct a URL for editing a specific project.
   sub edit_project_url {
       my ($self, $projectid) = @_;
  -
  -    if ($self->{cgi_style}) {
  -        return $self->{url_prefix} . 
"?action=edit_project&projectid=$projectid";
  -    } else {
  -     return $self->{url_prefix} . "/admin/project/$projectid/edit";
  -    }
  +    return 
Codestriker::Http::Method::EditProjectMethod->new($query)->url($projectid);
   }
   
   # Construct a URL for listing all projects.
   sub list_projects_url {
       my ($self) = @_;
  -
  -     if ($self->{cgi_style}) {
  -        return $self->{query}->url() . "?action=list_projects";
  -     } else {
  -             return $self->{query}->url() . "/admin/projects/list";
  -     }
  +    return Codestriker::Http::Method::ListProjectsMethod->new($query)->url();
   }
   
   # Construct a URL for creating a project.
   sub create_project_url {
       my ($self) = @_;
  -
  -     if ($self->{cgi_style}) {
  -        return $self->{query}->url() . "?action=create_project";
  -     } else {
  -             return $self->{query}->url() . "/admin/projects/create";
  -     }
  +    return 
Codestriker::Http::Method::CreateProjectMethod->new($query)->url();
   }
   
   # Create the URL for viewing comments.
   sub view_comments_url {
       my ($self, %args) = @_;
  -
  -    die "Parameter topicid missing" unless defined $args{topicid};
  -     die "Parameter projectid missing" unless defined $args{projectid};
  -
  -     if ($self->{cgi_style}) {
  -        return $self->{url_prefix} . 
"?action=list_comments&topic=$args{topicid}";
  -     } else {
  -             return $self->{url_prefix} . 
"/project/$args{projectid}/topic/$args{topicid}/comments/list";
  -     }
  +    return 
Codestriker::Http::Method::ViewTopicCommentsMethod->new($query)->url(%args);
   }
   
   # Create the URL for viewing the topic properties.
   sub view_topic_properties_url {
       my ($self, %args) = @_;
  -
  -    die "Parameter topicid missing" unless defined $args{topicid};
  -     die "Parameter projectid missing" unless defined $args{projectid};
  -
  -     if ($self->{cgi_style}) {
  -        return $self->{url_prefix} . 
"?action=view_topic_properties&topic=$args{topicid}";
  -     } else {
  -             return $self->{url_prefix} . 
"/project/$args{projectid}/topic/$args{topicid}/properties";
  -     }
  +    return 
Codestriker::Http::Method::ViewTopicPropertiesMethod->new($query)->url(%args);
   }
   
   # Create the URL for viewing the topic metrics.
   sub view_topicinfo_url {
       my ($self, %args) = @_;
  -
  -    die "Parameter topicid missing" unless defined $args{topicid};
  -     die "Parameter projectid missing" unless defined $args{projectid};
  -
  -     if ($self->{cgi_style}) {
  -        return $self->{url_prefix} . "?action=viewinfo&topic=$args{topicid}";
  -     } else {
  -             return $self->{url_prefix} . 
"/project/$args{projectid}/topic/$args{topicid}/metrics";
  -     }
  +    return 
Codestriker::Http::Method::ViewTopicMetricsMethod->new($query)->url(%args);
   }
   
   sub metric_report_url {
       my ($self) = @_;
  -
  -     if ($self->{cgi_style}) {
  -        return $self->{url_prefix} . "?action=metrics_report";
  -     } else {
  -             return $self->{url_prefix} . "/metrics/view";
  -     }
  +    return Codestriker::Http::Method::ViewMetricsMethod->new($query)->url();
   }
   
   sub metric_report_download_raw_data {
       my ($self) = @_;
  -
  -     if ($self->{cgi_style}) {
  -        return $self->{url_prefix} . "?action=metrics_download";
  -     } else {
  -        return $self->{url_prefix} . "/metrics/download";
  -     }
  -     
  +    return 
Codestriker::Http::Method::DownloadMetricsMethod->new($query)->url();
   }
   
   1;
  
  
  
  
  
  Index: Method.pm
  ===================================================================
  RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Method.pm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Method.pm 10 Aug 2008 12:18:44 -0000      1.1
  +++ Method.pm 11 Aug 2008 22:32:38 -0000      1.2
  @@ -18,7 +18,7 @@
        
       my $self = {};
        $self->{query} = $query;
  -    $self->{cgi_style} = $cgi_style;
  +    $self->{cgi_style} = defined $cgi_style ? $cgi_style : 1;
       
       # Determine what prefix is required when using relative URLs.
       # Unfortunately, Netcsape 4.x does things differently to everyone
  
  
  
  
  
  Index: AddTopicMethod.pm
  ===================================================================
  RCS file: AddTopicMethod.pm
  diff -N AddTopicMethod.pm
  --- /dev/null 1 Jan 1970 00:00:00 -0000
  +++ AddTopicMethod.pm 11 Aug 2008 22:32:39 -0000      1.1
  @@ -0,0 +1,53 @@
  
+###############################################################################
  +# Codestriker: Copyright (c) 2001, 2002 David Sitsky.  All rights reserved.
  +# [EMAIL PROTECTED]
  +#
  +# This program is free software; you can redistribute it and modify it under
  +# the terms of the GPL.
  +
  +# Method for adding a topic to a project.
  +
  +package Codestriker::Http::Method::AddTopicMethod;
  +
  +use strict;
  +use Codestriker::Http::Method;
  +
  [EMAIL PROTECTED]::Http::Method::AddTopicMethod::ISA = 
("Codestriker::Http::Method");
  +
  +# Generate a URL for this method.
  +sub url() {
  +    my ($self, %args) = @_;
  +     
  +     die "Parameter projectid missing" unless defined $args{projectid};
  +
  +    if ($self->{cgi_style}) {
  +        return $self->{url_prefix} . "?action=submit_new_topic";
  +    } else {
  +     return $self->{url_prefix} . "/project/$args{projectid}/topics/add";
  +    }
  +}
  +
  +sub extract_parameters {
  +     my ($self, $http_input) = @_;
  +     
  +     my $action = $http_input->{query}->param('action'); 
  +    my $path_info = $http_input->{query}->path_info();
  +    if ($self->{cgi_style} && defined $action && $action eq 
"submit_new_topic") {  
  +             $http_input->extract_cgi_parameters();
  +             return 1;
  +     } elsif ($path_info =~ m{^$self->{url_prefix}/project/\d+/topics/add}) {
  +         $self->_extract_nice_parameters($http_input,
  +                                         project => 'projectid');
  +             return 1;
  +     } else {
  +             return 0;
  +     }
  +}
  +
  +sub execute {
  +     my ($self, $http_input, $http_output) = @_;
  +     
  +     Codestriker::Action::CreateTopic->process($http_input, $http_output);
  +}
  +
  +1;
  
  
  

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Codestriker-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/codestriker-commits

Reply via email to