From a71c365fa58483926bee6f71332cfd572df09bfc Mon Sep 17 00:00:00 2001 From: Manager Bot Date: Sat, 26 Nov 2022 23:41:03 +0000 Subject: [PATCH] With blog testing now. --- .../04_do_domain/01_with_owned_domain.t | 41 ++++++++++++++ .../04_do_domain/02_with_hosted_domain.t | 56 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 Web/t/01_endpoints/03_blog/04_do_domain/01_with_owned_domain.t create mode 100644 Web/t/01_endpoints/03_blog/04_do_domain/02_with_hosted_domain.t diff --git a/Web/t/01_endpoints/03_blog/04_do_domain/01_with_owned_domain.t b/Web/t/01_endpoints/03_blog/04_do_domain/01_with_owned_domain.t new file mode 100644 index 0000000..bdec646 --- /dev/null +++ b/Web/t/01_endpoints/03_blog/04_do_domain/01_with_owned_domain.t @@ -0,0 +1,41 @@ +#!/usr/bin/env perl +use MJB::Web::Test; + +#== +# This test ensures that a blog can be created with an owned domain. +# +# A user account will be registered, and the user will create a blog on +# blog.example.com, and then it will be confirmed that a blog exists with its +# index page. +# +# Note: During testing ->jekyll uses an alternative root path to store repos at. +# When using ->jekyll in tests, you MUST call $t->clear_tempdir when you are +# done testing to remove the altrernative jekyll root. +#== + +my $t = Test::Mojo::MJB->new('MJB::Web'); + +# Make sure that open registration method is enabled and create a user account. +$t->app->config->{register}{enable_open} = 1; +$t->post_ok( '/register/open', form => { + name => 'fred', + email => 'fred@blog.com', + password => 'SuperSecure', + password_confirm => 'SuperSecure', + }) + ->status_is( 302 ); + +# Create a blog.... +$t->post_ok( '/blog/domain', form => { + domain => 'blog.example.com', + calling_route => 'show_blog_domain_owned', + }); + +# See if we have the blog directory and index.markdown file. +ok -f $t->app->jekyll( 'blog.example.com' )->root . '/blog.example.com/index.markdown', + 'Have an index file for the blog!'; + +# Remove the alternative path. +$t->clear_tempdir; + +done_testing; diff --git a/Web/t/01_endpoints/03_blog/04_do_domain/02_with_hosted_domain.t b/Web/t/01_endpoints/03_blog/04_do_domain/02_with_hosted_domain.t new file mode 100644 index 0000000..e7af1a0 --- /dev/null +++ b/Web/t/01_endpoints/03_blog/04_do_domain/02_with_hosted_domain.t @@ -0,0 +1,56 @@ +#!/usr/bin/env perl +use MJB::Web::Test; + +#== +# This test ensures that a blog can be created with a hosted domain. +# +# A user account will be registered, promoted to admin, and create a hosted +# domain for 'example.com'. The user will then create a blog on +# blog.example.com, and then it will be confirmed that a blog exists with its +# index page. +# +# Note: During testing ->jekyll uses an alternative root path to store repos at. +# When using ->jekyll in tests, you MUST call $t->clear_tempdir when you are +# done testing to remove the altrernative jekyll root. +#== + +my $t = Test::Mojo::MJB->new('MJB::Web'); + +# Make sure that open registration method is enabled and create a user account. +$t->app->config->{register}{enable_open} = 1; +$t->post_ok( '/register/open', form => { + name => 'fred', + email => 'fred@blog.com', + password => 'SuperSecure', + password_confirm => 'SuperSecure', + }) + ->status_is( 302 ) + ->get_ok( '/' ) + ->code_block( sub { + my $self = shift; + $self->stash->{person}->is_admin( 1 ); + ok( $self->stash->{person}->update, 'Promoted fred to an admin' ); + }); + +# Add a hosted domain +$t->post_ok( '/admin/domain', form => { + domain_fqdn => 'example.com', + ssl_challenge => 'http', + }) + ->header_is( location => '/admin/domains' ); + +# Create a blog with the hosted domain method.... +$t->post_ok( '/blog/domain', form => { + hosted_subdomain => 'blog', + hosted_domain_id => 1, + calling_route => 'show_blog_domain_hosted', + }); + +# See if we have the blog directory and index.markdown file. +ok -f $t->app->jekyll( 'blog.example.com' )->root . '/blog.example.com/index.markdown', + 'Have an index file for the blog!'; + +# Remove the alternative path. +$t->clear_tempdir; + +done_testing;