<?php
class SubscriptionTest extends TestCase {
public function testHasNoSubscription()
{
$result = \App\Models\Users\SubscriptionModel::get();
$this->assertEquals(count($result), 0);
}
public function testHasSubscriptions()
{
$result = \App\Models\Users\SubscriptionModel::get();
if (count($result) == 0) {
$subscription_names = [
[
'fastspring_name' => 'replug-personal',
'display_name' => 'Basic Monthly',
'price' => 9,
'limits' => [
'visits' => 10000,
'custom_domains' => false,
'branding' => false,
'team_members' => false,
'clicks' => 5000,
'brand' => 1,
'campaign' => 5,
'pixel' => 1,
'custom_domains_limit' => 0,
'team_members_limit' => 0
]
],
[
'fastspring_name' => 'replug-personal-annual',
'display_name' => 'Basic Annually',
'price' => 86,
'limits' => [
'visits' => 10000,
'custom_domains' => false,
'branding' => false,
'team_members' => false,
'clicks' => 5000,
'brand' => 1,
'campaign' => 5,
'pixel' => 1,
'custom_domains_limit' => 0,
'team_members_limit' => 0
]
],
[
'fastspring_name' => 'replug-professional',
'display_name' => 'Professional Monthly',
'price' => 29,
'limits' => [
'visits' => 50000,
'custom_domains' => true,
'branding' => true,
'team_members' => true,
'clicks' => 50000,
'brand' => 5,
'campaign' => 5000,
'pixel' => 5000,
'custom_domains_limit' => 5,
'team_members_limit' => 3
]
],
[
'fastspring_name' => 'replug-professional-annual',
'display_name' => 'Professional Annually',
'price' => 278,
'limits' => [
'visits' => 50000,
'custom_domains' => true,
'branding' => true,
'team_members' => true,
'clicks' => 50000,
'brand' => 5,
'campaign' => 5000,
'pixel' => 5000,
'custom_domains_limit' => 5,
'team_members_limit' => 3
]
],
[
'fastspring_name' => 'replug-agency',
'display_name' => 'Agency Monthly',
'price' => 79,
'limits' => [
'visits' => 300000,
'custom_domains' => true,
'branding' => true,
'team_members' => true,
'clicks' => 200000,
'brand' => 10,
'campaign' => 5000,
'pixel' => 5000,
'custom_domains_limit' => 10,
'team_members_limit' => 10
]
],
[
'fastspring_name' => 'replug-agency-annual',
'display_name' => 'Agency Annually',
'price' => 758,
'limits' => [
'visits' => 300000,
'custom_domains' => true,
'branding' => true,
'team_members' => true,
'clicks' => 200000,
'brand' => 10,
'campaign' => 5000,
'pixel' => 5000,
'custom_domains_limit' => 10,
'team_members_limit' => 10
]
],
[
'fastspring_name' => 'lifetime',
'display_name' => 'Lifetime',
'price' => 297,
'limits' => [
'visits' => 50000,
'custom_domains' => true,
'branding' => true,
'team_members' => true,
'clicks' => 1000000,
'brand' => 500,
'campaign' => 5000,
'pixel' => 5000,
'custom_domains_limit' => 5000,
'team_members_limit' => 50
]
],
[
'fastspring_name' => 'replug-lifetime',
'display_name' => 'Lifetime',
'price' => 67,
'limits' => [
'visits' => 50000,
'custom_domains' => true,
'branding' => true,
'team_members' => true,
'clicks' => 1000000,
'brand' => 500,
'campaign' => 5000,
'pixel' => 5000,
'custom_domains_limit' => 5000,
'team_members_limit' => 50
]
],
[
'fastspring_name' => 'trial',
'display_name' => 'Trial',
'price' => 0,
'limits' => [
'visits' => 50000,
'custom_domains' => true,
'branding' => true,
'team_members' => true,
'clicks' => 50000,
'brand' => 1,
'campaign' => 5,
'pixel' => 1,
'custom_domains_limit' => 0,
'team_members_limit' => 0
]
],
[
'fastspring_name' => 'free',
'display_name' => 'free',
'price' => 0,
'limits' => [
'visits' => 1000,
'custom_domains' => false,
'branding' => false,
'team_members' => false,
'clicks' => 50000,
'brand' => 1,
'campaign' => 5,
'pixel' => 1,
'custom_domains_limit' => 0,
'team_members_limit' => 0
]
],
[
'fastspring_name' => 'contentstudio-replug',
'display_name' => 'Lifetime',
'price' => 67,
'limits' => [
'visits' => 50000,
'custom_domains' => true,
'branding' => true,
'team_members' => true,
'clicks' => 1000000,
'brand' => 100,
'campaign' => 5000,
'pixel' => 5000,
'custom_domains_limit' => 5000,
'team_members_limit' => 50
]
],
[
'fastspring_name' => 'replug-lifetime-bundle',
'display_name' => 'Lifetime',
'price' => 67,
'limits' => [
'visits' => 50000,
'custom_domains' => true,
'branding' => true,
'team_members' => true,
'clicks' => 1000000,
'brand' => 100,
'campaign' => 5000,
'pixel' => 5000,
'custom_domains_limit' => 5000,
'team_members_limit' => 50
]
],
[
'fastspring_name' => 'trial-personal',
'display_name' => 'Basic Trial',
'price' => 9,
'limits' => [
'visits' => 10000,
'custom_domains' => false,
'branding' => false,
'team_members' => false,
'clicks' => 5000,
'brand' => 1,
'campaign' => 5,
'pixel' => 1,
'custom_domains_limit' => 0,
'team_members_limit' => 0
]
],
[
'fastspring_name' => 'trial-professional',
'display_name' => 'Professional Trial',
'price' => 29,
'limits' => [
'visits' => 50000,
'custom_domains' => true,
'branding' => true,
'team_members' => true,
'clicks' => 50000,
'brand' => 5,
'campaign' => 5000,
'pixel' => 5000,
'custom_domains_limit' => 5,
'team_members_limit' => 3
]
],
[
'fastspring_name' => 'trial-agency',
'display_name' => 'Agency Trial',
'price' => 79,
'limits' => [
'visits' => 300000,
'custom_domains' => true,
'branding' => true,
'team_members' => true,
'clicks' => 200000,
'brand' =>10,
'campaign' => 5000,
'pixel' => 5000,
'custom_domains_limit' => 10,
'team_members_limit' => 10
]
],
[
'fastspring_name' => 'trial-personal-old',
'display_name' => 'Basic Trial',
'price' => 79,
'limits' => [
'visits' => 10000,
'custom_domains' => false,
'branding' => false,
'team_members' => false,
'clicks' => 5000,
'brand' =>1,
'campaign' => 5,
'pixel' => 1,
'custom_domains_limit' => 0,
'team_members_limit' => 0
]
],
[
'fastspring_name' => 'replug-pro-lifetime',
'display_name' => 'Pro Lifetime',
'price' => 69,
'limits' => [
'visits' => 50000,
'custom_domains' => false,
'branding' => false,
'team_members' => false,
'clicks' => 50000,
'brand' =>5,
'campaign' => 5000,
'pixel' => 50000,
'custom_domains_limit' =>5,
'team_members_limit' => 3
]
],
[
'fastspring_name' => 'replug-agency-lifetime',
'display_name' => 'Agency Lifetime',
'price' => 99,
'limits' => [
'visits' => 200000,
'custom_domains' => false,
'branding' => false,
'team_members' => false,
'clicks' => 200000,
'brand' =>10,
'campaign' => 5000,
'pixel' => 50000,
'custom_domains_limit' =>10,
'team_members_limit' => 10
]
],
];
foreach ($subscription_names as $sub) {
$Subscription = new \App\Models\Users\SubscriptionModel();
foreach ($sub as $key => $value) {
$Subscription->$key = $value;
}
$Subscription->save();
Log::info('Subscription stored into the database');
}
}
{
assert(true, 'Subscription already exists in the database');
}
}
public function testDowngradeUsers()
{
$subscription_id = \App\Models\Users\SubscriptionModel::where('fastspring_name', 'trial')->first();
print_r($subscription_id->_id);
$users = \App\Models\UserModel::where('referral_level', '<', 10)->get();
foreach ($users as $user) {
$user->subscription_id = $subscription_id->_id;
$user->created_at = \Carbon\Carbon::now('UTC');
$user->save();
}
}
public function testDowngradeReferralMoreUsers()
{
$subscription_id = \App\Models\Users\SubscriptionModel::where('fastspring_name', 'trial')->first();
print_r($subscription_id->_id);
$users = \App\Models\UserModel::where('referral_level', '>', 10)->get();
foreach ($users as $user) {
$user->subscription_id = $subscription_id->_id;
$user->created_at = \Carbon\Carbon::now('UTC');
$user->save();
}
}
public function testUpgradeReplugUsers()
{
$subscription_id = \App\Models\Users\SubscriptionModel::where('fastspring_name', 'lifetime')->first();
print_r($subscription_id->_id);
$users = \App\Models\UserModel::where('referral_level', '=', 10)->get();
foreach ($users as $user) {
$user->subscription_id = $subscription_id->_id;
$user->created_at = \Carbon\Carbon::now('UTC');
$user->save();
}
}
public function testSetSubscriptionTime()
{
$subscriptions = \App\Models\Users\SubscriptionModel::where('fastspring_name', 'trial-professional')
->orWhere('fastspring_name', 'trial-agency')
->orWhere('fastspring_name', 'trial-personal')
->get();
foreach ($subscriptions as $subscription) {
$users = \App\Models\UserModel::where('subscription_id',$subscription['_id'])->get();
foreach ($users as $user)
{
$user->subscription_time = \Carbon\Carbon::now('UTC');
$user->save();
}
}
}
public function testCheckTrialExpire()
{
$subscriptions = \App\Models\Users\SubscriptionModel::where('fastspring_name', 'trial-professional')
->orWhere('fastspring_name', 'trial-agency')
->orWhere('fastspring_name', 'trial-personal')
->get();
foreach ($subscriptions as $subscription) {
$users = \App\Models\UserModel::where('subscription_id',$subscription['_id'])->get();
foreach ($users as $user)
{
// $user->subscription_time
}
}
}
public function testUserEmailLowerString(){
$users = \App\Models\UserModel::all();
foreach ($users as $user){
\App\Models\UserModel::where('_id',$user['_id'])->update([
'email'=>strtolower(trim($user['email'])),
'username'=>strtolower(trim($user['username'])),
]);
}
}
public function testUserPoweredBy(){
$users = \App\Models\UserModel::all();
foreach ($users as $user){
if(isset($user['subscription_id'])) {
$poweredBy = false;
$subscription_data = \App\Models\Users\SubscriptionModel::where('_id', $user['subscription_id'])->first();
if ($subscription_data && isset($subscription_data['limits']) && isset($subscription_data['limits']['branding'])) {
$poweredBy = $subscription_data['limits']['branding'];
}
\App\Models\UserModel::where('_id', $user['_id'])->update([
'poweredBy' => $poweredBy
]);
}
}
}
public function testTrailFinish()
{
$users = \App\Models\UserModel::where('trial_finish',true)
->whereNotIn('subscription_id', ['5a0fdd4daf2aae37026e073a', '5a0fdd4daf2aae37026e073b',
'5ae8677f6814943a284b197e','5ae867ac6814943a284bb072','5ae8b84d6814943a2847c4de','5ae8676a6814943a284ad7d4'])
->get();
echo "<pre>";
print_r($users);
exit();
}
}