Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Item13897: First working test in unit test!
Yes, QueryTests does it! Don't ask why is this particular one – it was just small enough start with... Yet, not sure if successfull pass isn't caused by a hidden bug. - Added Unit::TestApp class to avoid polluting Foswiki::App with test-only related code. - Added Foswiki::Object::Parent and *::Child classes. They were spawned as a side-effect of a nonviable idea and are not used; but as they were planned for some future development I decided have them included now. - Foswiki::Aux::Localize can behaviour can now be tuned by additional flags. The flags are set using setLocalizeFlags() method provided by a class with Localize role. Currently the only flag supported is clearAttributes which indicates whether attributes of the object being localized must be cleared or left alone. Used by FoswikiTestCase pushApp method. - New Foswiki::Object feature – object cloning. As any cloning it has it's problems and not every clone is the exact copy of the original – yet it tries to do its best. Especially when it's going about rather simple classes like Foswiki::Config. An object may provide additional aid to the process by declaring _clone_attrName() methods where attrName is the attribute name to be cloned. These methods must return a cloned copy of attrName attribute. - Foswiki::AppObject now declares the app attribute as protected. - Added Foswiki::AppObject _clone_app() method to support object cloning. - Added new concept to FoswikiTestCase – push/pop of application object. It's developed as a replacement for the old style code when a request object is preserved -> new temporary $session is created -> some code executed -> new semi-permanent $session is created and the original request object is restored. For now we just pushApp -> do some code -> popApp. Note that createNewFoswikiApp() and popApp() call _fixupAppObject() to set all attributes of the current test case object which are descendants of Foswiki::App to have their app attribute point to the currently active application. Generally it shall be transparent to the end user. But if in some case a new application object is created and set active by a test case it must call _fixupAppObject() too.
- Loading branch information
Showing
16 changed files
with
605 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# See bottom of file for license and copyright | ||
|
||
package Unit::TestApp; | ||
use v5.14; | ||
|
||
use Scalar::Util qw(blessed); | ||
|
||
use Moo; | ||
use namespace::clean; | ||
extends qw(Foswiki::App); | ||
|
||
#with qw(Foswiki::Aux::Localize); | ||
|
||
#sub setLocalizableAttributes { | ||
# return | ||
# qw( | ||
# access attach cache cfg env forms | ||
# logger engine heap i18n plugins prefs | ||
# renderer request _requestParams response | ||
# search store templates macros context | ||
# ui remoteUser user users zones _dispatcherAttrs | ||
# ) | ||
# ; | ||
#} | ||
|
||
sub BUILD { | ||
my $this = shift; | ||
|
||
# Fixup Foswiki::AppObject descendants which have been cloned from objects | ||
# on another Foswiki::App instance. | ||
foreach my $attr ( keys %$this ) { | ||
if ( | ||
blessed( $this->{$attr} ) | ||
&& $this->$attr->isa('Foswiki::Object') | ||
&& $this->$attr->does('Foswiki::AppObject') | ||
&& ( !defined( $this->$attr->app ) | ||
|| ( $this->$attr->app != $this ) ) | ||
) | ||
{ | ||
$this->$attr->_set_app($this); | ||
} | ||
} | ||
} | ||
|
||
=begin TML | ||
---++ ObjectMethod cloneEnv => \%envHash | ||
Clones current application =env= hash. | ||
=cut | ||
|
||
sub cloneEnv { | ||
my $this = shift; | ||
|
||
# SMELL Use Foswiki::Object internals. | ||
return $this->_cloneData( $this->env, 'env' ); | ||
} | ||
|
||
1; | ||
|
||
__DATA__ | ||
Author: Crawford Currie, http://c-dot.co.uk | ||
Copyright (C) 2007-2016 Foswiki Contributors | ||
All Rights Reserved. | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation; either version 2 | ||
of the License, or (at your option) any later version. For | ||
more details read LICENSE in the root of this distribution. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
As per the GPL, removal of this notice is prohibited. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.