Changeset 13781
- Timestamp:
- 01/22/12 19:31:26 (4 weeks ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
UnitTestContrib/test/unit/PluginHandlerTests.pm (modified) (6 diffs)
-
core/lib/Foswiki/Meta.pm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/UnitTestContrib/test/unit/PluginHandlerTests.pm
r13771 r13781 5 5 # Make sure that all the right plugin handlers are called in the 6 6 # 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* |39 7 # 40 8 # We do this by actually writing a valid plugin implementation to the … … 194 162 sub beforeSaveHandler { 195 163 #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]"); 197 167 $tester->assert_str_equals($tester->{test_web}, $_[2], "THREE $_[2]"); 198 168 $tester->assert($_[3]->isa('Foswiki::Meta'), "FOUR $_[3]"); … … 212 182 $tester->assert_null($_[3]); 213 183 $tester->assert($_[4]->isa('Foswiki::Meta'), "OUCH $_[4]"); 184 # ensure we have a loaded rev 185 $tester->assert($_[4]->getLoadedRev()); 214 186 $tester->assert_str_equals('Wibble', $_[4]->get('WIBBLE')->{wibble}); 215 187 $tester->assert_matches( qr/B4SAVE/, $_[0]); … … 227 199 HERE 228 200 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 ); 233 204 $meta->put( 'WIBBLE', { wibble => 'Wibble' } ); 234 205 $meta->save(); … … 553 524 sub afterUploadHandler { 554 525 my ($attachmentAttrHash, $meta) = @_; 526 # ensure we have a loaded rev 527 $tester->assert($meta->getLoadedRev()); 555 528 $called->{afterUploadHandler}++; 556 529 } … … 594 567 sub beforeUploadHandler { 595 568 my( $attrHashRef, $meta ) = @_; 569 # ensure we have a loaded rev 570 $tester->assert($meta->getLoadedRev()); 596 571 $called->{beforeUploadHandler}++; 597 572 } -
trunk/core/lib/Foswiki/Meta.pm
r13771 r13781 1877 1877 my $pretext = $text; # text before the handler modifies it 1878 1878 my $premeta = $this->stringify(); # just the meta, no text 1879 # The meta obj may not have a loaded rev yet. If anything in the 1880 # beforeSaveHandlers tries to do an access check with an unloadedRev, 1881 # it will attempt to load the latest which we really don't want it to do. 1882 # So we mark it as NEW. 1883 $this->{_loadedRev} = 'NEW' unless defined $this->{_loadedRev}; 1879 unless ( $this->{_loadedRev} ) { 1880 # The meta obj doesn't have a loaded rev yet, and we have to block the 1881 # beforeSaveHandlers from loading the topic from store. We are saving, 1882 # and anything we have in $this is going to get written anyway, so we 1883 # can simply mark it as "the latest". 1884 # SMELL: this may not work if the beforeSaveHandler tries to use the 1885 # meta obj for access control checks, so that is not recommended. 1886 $this->{_loadedRev} = $this->getLatestRev(); 1887 } 1888 1884 1889 $plugins->dispatch( 'beforeSaveHandler', $text, $this->{_topic}, 1885 1890 $this->{_web}, $this ); 1886 undef $this->{_loadedRev} if $this->{_loadedRev} eq 'NEW';1887 1891 1888 1892 # If the text has changed; it may be a text or meta change, or both … … 1912 1916 $signal = shift; 1913 1917 }; 1918 1919 ASSERT($newRev, $this->{loadedRev}) if DEBUG; 1914 1920 1915 1921 # Semantics inherited from TWiki. See
Note: See TracChangeset
for help on using the changeset viewer.
