Changeset 13782


Ignore:
Timestamp:
01/22/12 19:36:26 (4 weeks ago)
Author:
CrawfordCurrie
Message:

Item11461: no need to fake the loaded rev, as we know the new content being saved is correct for the current rev (even if it was generated internally)

Location:
branches/Release01x01
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/Release01x01/UnitTestContrib/test/unit/PluginHandlerTests.pm

    r13773 r13782  
    55# Make sure that all the right plugin handlers are called in the 
    66# right places with the right parameters. 
    7 # 
    8 # Here are the handlers we need to test, and the current status: 
    9 # 
    10 # | *Handler*                    | *Tested by* | 
    11 # | afterAttachmentSaveHandler   | *untested* | 
    12 # | afterUploadHandler           | *untested* | 
    13 # | afterCommonTagsHandler       | test_commonTagsHandlers | 
    14 # | afterEditHandler             | *untested* | 
    15 # | afterRenameHandler           | *untested* | 
    16 # | afterSaveHandler             | test_saveHandlers | 
    17 # | beforeUploadHandler          | *untested* | 
    18 # | beforeAttachmentSaveHandler  | *untested* | 
    19 # | beforeCommonTagsHandler      | test_commonTagsHandlers | 
    20 # | beforeEditHandler            | *untested* | 
    21 # | beforeSaveHandler            | test_saveHandlers | 
    22 # | commonTagsHandler            | test_commonTagsHandlers | 
    23 # | earlyInitPlugin              | test_earlyInit | 
    24 # | endRenderingHandler          | test_renderingHandlers | 
    25 # | initPlugin                   | all tests | 
    26 # | initializeUserHandler        | test_earlyInit | 
    27 # | insidePREHandler             | test_renderingHandlers | 
    28 # | modifyHeaderHandler          | *untested* | 
    29 # | mergeHandler                 | *untested* | 
    30 # | outsidePREHandler            | test_renderingHandlers | 
    31 # | postRenderingHandler         | test_renderingHandlers | 
    32 # | preRenderingHandler          | test_renderingHandlers | 
    33 # | redirectrequestHandler       | *untested* | 
    34 # | registrationHandler          | *untested* | 
    35 # | renderFormFieldForEditHandler| *untested* | 
    36 # | renderWikiWordHandler        | *untested* | 
    37 # | startRenderingHandler        | test_renderingHandlers | 
    38 # | writeHeaderHandler           | *untested* | 
    397# 
    408# We do this by actually writing a valid plugin implementation to the 
     
    194162sub beforeSaveHandler { 
    195163    #my( $text, $topic, $theWeb, $meta ) = @_; 
    196     $tester->assert_str_equals('Tropic', $_[1], "TWO $_[1]"); 
     164    # ensure we have a loaded rev 
     165    $tester->assert($_[3]->getLoadedRev()); 
     166     $tester->assert_str_equals('Tropic', $_[1], "TWO $_[1]"); 
    197167    $tester->assert_str_equals($tester->{test_web}, $_[2], "THREE $_[2]"); 
    198168    $tester->assert($_[3]->isa('Foswiki::Meta'), "FOUR $_[3]"); 
     
    212182    $tester->assert_null($_[3]); 
    213183    $tester->assert($_[4]->isa('Foswiki::Meta'), "OUCH $_[4]"); 
     184    # ensure we have a loaded rev 
     185    $tester->assert($_[4]->getLoadedRev()); 
    214186    $tester->assert_str_equals('Wibble', $_[4]->get('WIBBLE')->{wibble}); 
    215187    $tester->assert_matches( qr/B4SAVE/, $_[0]); 
     
    227199HERE 
    228200 
    229 # Test to ensure that the before and after save handlers are both called, 
    230 # and that modifications made to the text are actaully written to the topic file 
    231     my $meta = 
    232       Foswiki::Meta->load( $this->{session}, $this->{test_web}, "Tropic" ); 
     201    # Test to ensure that the before and after save handlers are both called, 
     202    # and that modifications made to the text are actaully written to the topic file 
     203    my $meta = Foswiki::Meta->new( $this->{session}, $this->{test_web}, "Tropic", $text ); 
    233204    $meta->put( 'WIBBLE', { wibble => 'Wibble' } ); 
    234205    $meta->save(); 
     
    553524sub afterUploadHandler { 
    554525    my ($attachmentAttrHash, $meta) = @_; 
     526    # ensure we have a loaded rev 
     527    $tester->assert($meta->getLoadedRev()); 
    555528    $called->{afterUploadHandler}++; 
    556529} 
     
    594567sub beforeUploadHandler { 
    595568    my( $attrHashRef, $meta ) = @_; 
     569    # ensure we have a loaded rev 
     570    $tester->assert($meta->getLoadedRev()); 
    596571    $called->{beforeUploadHandler}++; 
    597572} 
  • branches/Release01x01/core/lib/Foswiki/Meta.pm

    r13773 r13782  
    18981898        my $pretext = $text;               # text before the handler modifies it 
    18991899        my $premeta = $this->stringify();  # just the meta, no text 
    1900  
    1901         # The meta obj may not have a loaded rev yet. If anything in the 
    1902         # beforeSaveHandlers tries to do an access check with an unloadedRev, 
    1903         # it will attempt to load the latest which we really don't want it to do. 
    1904         # So we mark it as NEW. 
    1905         $this->{_loadedRev} = 'NEW' unless defined $this->{_loadedRev}; 
     1900        unless ( $this->{_loadedRev} ) { 
     1901            # The meta obj doesn't have a loaded rev yet, and we have to block the 
     1902            # beforeSaveHandlers from loading the topic from store. We are saving, 
     1903            # and anything we have in $this is going to get written anyway, so we 
     1904            # can simply mark it as "the latest". 
     1905            # SMELL: this may not work if the beforeSaveHandler tries to use the 
     1906            # meta obj for access control checks, so that is not recommended. 
     1907            $this->{_loadedRev} = $this->getLatestRev(); 
     1908        } 
     1909 
    19061910        $plugins->dispatch( 'beforeSaveHandler', $text, $this->{_topic}, 
    19071911            $this->{_web}, $this ); 
    1908         undef $this->{_loadedRev} if $this->{_loadedRev} eq 'NEW'; 
    19091912 
    19101913        # If the text has changed; it may be a text or meta change, or both 
Note: See TracChangeset for help on using the changeset viewer.