#!/usr/local/cpanel/3rdparty/bin/perl -w

#                                      Copyright 2025 WebPros International, LLC
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited.

package t::medium::Cpanel::Config::ConfigObj::Driver::Sitejet::META;

use cPstrict;

use Test::More tests => 24 + 1;    # +1NoWarnings  # +1logger

use Test::Cpanel::Policy;

use Test::Deep;
use Test::MockModule qw/strict/;
use Test::MockFile   qw/strict/;
use Test::NoWarnings;

use parent qw(
  Cpanel::TestObj
);

use Cpanel::Config::ConfigObj::Driver::Sitejet::META ();
use Cpanel::Locale                                   ();

my $expected;
my $results;

my $mock_cid = Test::MockModule->new("Cpanel::License::CompanyID");
$mock_cid->redefine(
    get_company_id => sub {
        1;
    }
);

my $mock_cpanel_version = Test::MockModule->new("Cpanel::Plugins::Components::Rules::CpanelVersion");
$mock_cpanel_version->redefine( 'is_allowed' => undef );

my $mock_feature_file = Test::MockFile->file( '/usr/local/cpanel/whostmgr/addonfeatures/sitejet_builder_campaign_05_2025', '' );

is( $Cpanel::Config::ConfigObj::Driver::Sitejet::META::VERSION,        '2.0',                              "VERSION () is correct" );
is( Cpanel::Config::ConfigObj::Driver::Sitejet::META::get_driver_name, "sitejet_builder_campaign_08_2025", "get_driver_name () is correct" );

$expected = {
    'is_recommended'       => 0,
    'is_spotlight_feature' => 1,
};
cmp_deeply( Cpanel::Config::ConfigObj::Driver::Sitejet::META::showcase(), $expected, "showcase returns expected hash" ) or diag explain Cpanel::Config::ConfigObj::Driver::Sitejet::META::showcase();

$expected = {
    'vendor' => 'WebPros International, LLC',
    'url'    => 'https://go.cpanel.net/sitejet-builder',
    'name'   => {
        'short'  => "Sitejet AI Website Generator",
        'driver' => 'sitejet_builder_campaign_08_2025',
        'long'   => "Sitejet AI Website Generator",
    },
    'first_appears_in' => '110',
    'abstract'         => "",
    'version'          => '2.0',
    'readonly'         => 1,
};

my $locale_handle    = Cpanel::Locale->get_handle();
my $results_nolocale = Cpanel::Config::ConfigObj::Driver::Sitejet::META::content();
my $results_locale   = Cpanel::Config::ConfigObj::Driver::Sitejet::META::content($locale_handle);
cmp_deeply( $results_nolocale->{'vendor'}, $expected->{'vendor'}, "vendor (no locale) is correct" )   or diag explain $results_nolocale;
cmp_deeply( $results_locale->{'vendor'},   $expected->{'vendor'}, "vendor (with locale) is correct" ) or diag explain $results_locale;

cmp_deeply( $results_nolocale->{'url'}, $expected->{'url'}, "url (no locale) is correct" )   or diag explain $results_nolocale;
cmp_deeply( $results_locale->{'url'},   $expected->{'url'}, "url (with locale) is correct" ) or diag explain $results_locale;

cmp_deeply( $results_nolocale->{'name'}, $expected->{'name'}, "short, driver, and long names (no locale) are correct" )   or diag explain $results_nolocale;
cmp_deeply( $results_locale->{'name'},   $expected->{'name'}, "short, driver, and long names (with locale) are correct" ) or diag explain $results_locale;

cmp_deeply( $results_nolocale->{'first_appears_in'}, $expected->{'first_appears_in'}, "first_appears_in (no locale) is correct" )    or diag explain $results_nolocale;
cmp_deeply( $results_locale->{'first_appears_in'},   $expected->{'first_appears_in'}, "first_appears_in (with locale) are correct" ) or diag explain $results_locale;

cmp_deeply( $results_nolocale->{'version'}, $expected->{'version'}, "version (no locale) is correct" )   or diag explain $results_nolocale;
cmp_deeply( $results_locale->{'version'},   $expected->{'version'}, "version (with locale) is correct" ) or diag explain $results_locale;

cmp_deeply( $results_nolocale->{'readonly'}, $expected->{'readonly'}, "readonly (no locale) is correct" )   or diag explain $results_nolocale;
cmp_deeply( $results_locale->{'readonly'},   $expected->{'readonly'}, "readonly (with locale) is correct" ) or diag explain $results_locale;

# currently tests 2 phrases, with and without locale
my $topline           = Cpanel::Config::ConfigObj::Driver::Sitejet::META::top_line;
my $localized_topline = $locale_handle->makevar($topline);
like( $results_locale->{'abstract'}, qr/\Q$localized_topline\E/, "phrase \"$localized_topline\" found in abstract (with locale)" ) or diag explain $results_locale;

$topline =~ s/\[.+,([^]]*)\]/<strong>$1<\/strong>/;
like( $results_nolocale->{'abstract'}, qr/$topline/, "phrase \"$topline\" found in abstract (no locale)" ) or diag explain $results_nolocale;

# checks 3 bullet points, with and without locale
foreach my $point (Cpanel::Config::ConfigObj::Driver::Sitejet::META::bullet_point_strings) {
    like( $results_nolocale->{'abstract'}, qr/$point/, "phrase \"$point\" found in abstract (no locale)" )   or diag explain $results_nolocale;
    like( $results_locale->{'abstract'},   qr/$point/, "phrase \"$point\" found in abstract (with locale)" ) or diag explain $results_locale;
}

my $note = Cpanel::Config::ConfigObj::Driver::Sitejet::META::note;
like( $results_nolocale->{'abstract'}, qr/$note/, "phrase \"$note\" found in abstract (no locale)" ) or diag explain $results_nolocale;

1;
