Krang::Test::Content - a package to simplify content handling in Krang tests.


  use Krang::ClassLoader 'Test::Content';
  my $creator = pkg('Test::Content')->new();
  # create a Krang::Site object
  my $site = $creator->create_site(preview_url => '',
                                   publish_url => '',
                                   preview_path => '/tmp/preview_dogs',
                                   publish_path => '/tmp/publish_dogs');
  my ($root) = pkg('Category')->find(site_id => $site->site_id);
  # create a Krang::Category object.
  my $poodle_cat = $creator->create_category(dir    => 'poodles',
                                             parent => $root->category_id,
                                             data   => 'Fluffy Poodles of the World');
  # create another Krang::Category object w/ $poodle_cat as parent.
  my $french_poodle_cat = $creator->create_category(dir    => 'french',
                                                    parent => $poodle_cat,
                                                    data   => 'French Poodles Uber Alles');
  # create a Krang::User user.
  my $user = $creator->create_user();
  # get the login username if you don't know it
  my $login = $user->login();
  # get the pw
  my $password = $user->password();
  # create a Krang::Media object.
  my $media = $creator->create_media(category => $poodle_cat);
  # create a Krang::Story object under various categories, with media object.
  my $story1 = $creator->create_story(category     => [$poodle_cat, $french_poodle_cat],
                                      linked_media => [$media]);
  # create Story object linking to media and previous story.
  my $story2 = $creator->create_story(category     => [$poodle_cat, $french_poodle_cat],
                                      linked_story => [$story1],
                                      linked_media => [$media]);
  # Where to find the published story on the filesystem
  my @paths = $creator->publish_paths(story => $story);
  # create a Krang::Contrib object
  my $contributor = $creator->create_contrib();
  # create a Krang::Template object for root element of story
  my $template = $creator->create_template(element => $story->element);
  # create a Krang::Template associated with a specific cat
  $template = $creator->create_template(element => $story->element, category => $poodle_cat);
  # get a Krang::Publisher object
  my $publisher = $creator->publisher();
  # create and deploy test templates
  my @templates = $creator->deploy_test_templates();
  # undeploy test templates
  # undeploy all live templates
  $ok = $creator->undeploy_live_templates();
  # restore previously live templates
  $ok = $creator->redeploy_live_templates();
  # get a random word (returns UTF-8 encoded words if Charset directive is set to utf-8)
  my $word = $creator->get_word();
  # get a random word exclusively composed of ascii letters a-z and A-Z
  my $ascii = $creator->get_word('ascii');
  # delete a previously created object
  $creator->delete_item(item => $story);
  # clean up after the mess you made.  Leave things where you found them.


Krang::Test::Content exists to simplify the process of writing tests for the more advanced subsystems of Krang. Most test suites depend on content existing in the system to test against, and have been rolling their own content-creating routines. This module exists to centralize a lot of that code in one place. Additionally, it provides cleanup functionality, deleting everything that has been created using it.

This module is designed to work with the Default and TestSet1 element sets - it may or may not work with other element sets.

NOTE - It should be clear that this module assumes that the following modules are all in working order: Krang::Site, Krang::Category, Krang::Story, Krang::Media, Krang::Contrib.




Krang::Test::Content will only work against the ElementSet TestSet1. Any other Element Sets will cause unpredictable behavior.


Flesh out the various create_ methods to support more of the test code in Krang. Ideally, this module would also support bin/krang_floodfill, so that all test suites and dummy data are coming from the same source.


Krang::Category, Krang::Story, Krang::Media, Krang::Contrib