<commit_before>#!/usr/bin/env perl

use strict;
use warnings;
use Test::Most;
use Test::WWW::Mechanize;
use Test::JSON;
#use Carp::Always;

my $base = $ENV{CASHMUSIC_TEST_URL} || 'http://localhost:80';
my $mech = Test::WWW::Mechanize->new;

BEGIN {
    # Run the test installer every time we run these tests
    qx "php installers/php/test_installer.php";
}

$mech->get_ok("$base/interfaces/php/admin/");
$mech->content_contains('email');
$mech->content_contains('password');
$mech->content_contains('CASH Music');
$mech->submit_form_ok({
    form_number => 1,
    fields      => {
        # these are specified in the test installer
        address  => 'root@localhost',
        password => '<PASSWORD>',
        login    => 1,
    },
}, 'log in to admin area');
$mech->content_unlike(qr/Try Again/);


my @admin_urls    = qw{
    settings commerce elements assets calendar
    people people/mailinglists people/mailinglists/view people/mailinglists/export people/mailinglists/add
    help help/gettingstarted
};
my @metadata_urls = map { "components/elements/$_/metadata.json" } qw{emailcollection tourdates};

for my $url (@admin_urls) {
    $mech->get_ok("$base/interfaces/php/admin/$url");
}

for my $url (@metadata_urls) {
    my $full_url = "$base/interfaces/php/admin/$url";
    $mech->get_ok($full_url);
    is_valid_json($mech->content, "$full_url is valid JSON");
}

$mech->get_ok("$base/interfaces/php/admin/elements/view/100");
$mech->content_contains("Portugal. The Man");
$mech->content_contains('cash_embedElement(100)');
$mech->get_ok("$base/interfaces/php/admin/elements/view/101");
$mech->content_contains("Iron & Wine");
$mech->content_contains('cash_embedElement(101)');
$mech->get_ok("$base/interfaces/php/admin/elements/view/102");
$mech->content_contains("Wild Flag");
$mech->content_contains('cash_embedElement(102)');

$mech->get_ok("$base/interfaces/php/admin/elements/delete/101");
$mech->submit_form_ok({
    form_number => 1,
    fields => {
        doelementdelete => "makeitso",
    },
}, 'delete element form');

# Look for errors like
# SQLSTATE[HY000]: General error: 8 attempt to write a readonly database
$mech->content_unlike(qr/SQLSTATE.*error/i);

$mech->get_ok("$base/interfaces/php/admin/assets/add/playlist/");
$mech->content_contains('Add Playlist');

$mech->get_ok("$base/interfaces/php/admin/assets/add/single/");
$mech->submit_form_ok({
    form_number => 1,
    fields      => {
        asset_description => 'asdf',
        asset_location    => 'http://aasdf.com',
        asset_title       => 'adsf',
        doassetadd        => 'makeitso',
        settings_id       => 0
    },
}, 'add asset form');
$mech->content_unlike(qr/Error/);
$mech->content_contains('Success');

$mech->get_ok("$base/interfaces/php/admin/elements/add/emailcollection");
$mech->submit_form_ok({
    form_name   => 'emailcollection',
    fields      => {
        asset_id         =>   '100',
        comment_or_radio =>   'none',
        doelementadd     =>   'makeitso',
        element_name     =>   'foooobaf',
        element_type     =>   'emailcollection',
        emal_list_id     =>   '100',
        message_invalid_email =>  "Sorry, that email address wasn't valid. Please try again.",
        message_privacy  => "We won't share, sell, or be jerks with your email address.",
        message_success  => "Thanks! You're all signed up. Here's your download",
   },
}, 'add email collection form');
$mech->content_like(qr/Success/);

$mech->get_ok("$base/interfaces/php/admin/elements/add/tourdates");
$mech->submit_form_ok({
    form_name   => "tourdates",
    fields      => {
        doelementadd        => 'makeitso',
        element_name        => 'Nyarlathotep Live Tour',
        element_type        => 'tourdates',
        visible_event_types => 'upcoming',
    },
}, 'add tourdates form');
$mech->content_unlike(qr/Error/);
$mech->content_like(qr/Success/);

$mech->get("$base/interfaces/php/admin/people/mailinglists/add");
$mech->submit_form_ok({
    form_number => 1,
    fields      => {
        dolistadd        =>   'makeitso',
        list_description =>   'Ultharian cats',
        list_name        =>   'cats_of_ulthar',
        settings_id      =>   0,
    },
}, 'add mailing list');
$mech->content_like(qr/Success/);

done_testing;<commit_msg>Add an integration test for adding a social feed element<commit_after>#!/usr/bin/env perl

use strict;
use warnings;
use Test::Most;
use Test::WWW::Mechanize;
use Test::JSON;
#use Carp::Always;

my $base = $ENV{CASHMUSIC_TEST_URL} || 'http://localhost:80';
my $mech = Test::WWW::Mechanize->new;

BEGIN {
    # Run the test installer every time we run these tests
    qx "php installers/php/test_installer.php";
}

$mech->get_ok("$base/interfaces/php/admin/");
$mech->content_contains('email');
$mech->content_contains('password');
$mech->content_contains('CASH Music');
$mech->submit_form_ok({
    form_number => 1,
    fields      => {
        # these are specified in the test installer
        address  => 'root@localhost',
        password => '<PASSWORD>',
        login    => 1,
    },
}, 'log in to admin area');
$mech->content_unlike(qr/Try Again/);


my @admin_urls    = qw{
    settings commerce elements assets calendar
    people people/mailinglists people/mailinglists/view people/mailinglists/export people/mailinglists/add
    help help/gettingstarted elements/add/socialfeeds
};
my @metadata_urls = map { "components/elements/$_/metadata.json" } qw{emailcollection tourdates};

for my $url (@admin_urls) {
    $mech->get_ok("$base/interfaces/php/admin/$url");
}

for my $url (@metadata_urls) {
    my $full_url = "$base/interfaces/php/admin/$url";
    $mech->get_ok($full_url);
    is_valid_json($mech->content, "$full_url is valid JSON");
}

$mech->get_ok("$base/interfaces/php/admin/elements/view/100");
$mech->content_contains("Portugal. The Man");
$mech->content_contains('cash_embedElement(100)');
$mech->get_ok("$base/interfaces/php/admin/elements/view/101");
$mech->content_contains("Iron & Wine");
$mech->content_contains('cash_embedElement(101)');
$mech->get_ok("$base/interfaces/php/admin/elements/view/102");
$mech->content_contains("Wild Flag");
$mech->content_contains('cash_embedElement(102)');

$mech->get_ok("$base/interfaces/php/admin/elements/delete/101");
$mech->submit_form_ok({
    form_number => 1,
    fields => {
        doelementdelete => "makeitso",
    },
}, 'delete element form');

# Look for errors like
# SQLSTATE[HY000]: General error: 8 attempt to write a readonly database
$mech->content_unlike(qr/SQLSTATE.*error/i);

$mech->get_ok("$base/interfaces/php/admin/assets/add/playlist/");
$mech->content_contains('Add Playlist');

$mech->get_ok("$base/interfaces/php/admin/assets/add/single/");
$mech->submit_form_ok({
    form_number => 1,
    fields      => {
        asset_description => 'asdf',
        asset_location    => 'http://aasdf.com',
        asset_title       => 'adsf',
        doassetadd        => 'makeitso',
        settings_id       => 0
    },
}, 'add asset form');
$mech->content_unlike(qr/Error/);
$mech->content_contains('Success');

$mech->get_ok("$base/interfaces/php/admin/elements/add/emailcollection");
$mech->submit_form_ok({
    form_name   => 'emailcollection',
    fields      => {
        asset_id         =>   '100',
        comment_or_radio =>   'none',
        doelementadd     =>   'makeitso',
        element_name     =>   'foooobaf',
        element_type     =>   'emailcollection',
        emal_list_id     =>   '100',
        message_invalid_email =>  "Sorry, that email address wasn't valid. Please try again.",
        message_privacy  => "We won't share, sell, or be jerks with your email address.",
        message_success  => "Thanks! You're all signed up. Here's your download",
   },
}, 'add email collection form');
$mech->content_like(qr/Success/);

$mech->get_ok("$base/interfaces/php/admin/elements/add/tourdates");
$mech->submit_form_ok({
    form_name   => "tourdates",
    fields      => {
        doelementadd        => 'makeitso',
        element_name        => 'Nyarlathotep Live Tour',
        element_type        => 'tourdates',
        visible_event_types => 'upcoming',
    },
}, 'add tourdates form');
$mech->content_unlike(qr/Error/);
$mech->content_like(qr/Success/);

$mech->get("$base/interfaces/php/admin/people/mailinglists/add");
$mech->submit_form_ok({
    form_number => 1,
    fields      => {
        dolistadd        =>   'makeitso',
        list_description =>   'Ultharian cats',
        list_name        =>   'cats_of_ulthar',
        settings_id      =>   0,
    },
}, 'add mailing list');
$mech->content_like(qr/Success/);

$mech->get("$base/interfaces/php/admin/elements/add/socialfeeds");
$mech->submit_form_ok({
    form_number => 1,
    fields      => {
        doelementadd => 'makeitso',
        element_name => 'miskatonic_fireside_chat',
        element_type => 'socialfeeds',
    },
}, 'add social feeds');
$mech->content_like(qr/Success/);

done_testing;
{'fraction_non_alphanumeric': 0.1646443281754425, 'fraction_numerical': 0.009017032171880218, 'mean_word_length': 3.4497275879148095, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 165, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3602310', 'n_tokens_mistral': 3149, 'n_tokens_neox': 3033, 'n_words': 536}