snipe-it/tests/Support/Settings.php

139 lines
3.6 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Support;
use App\Models\Setting;
2023-11-27 06:50:43 -08:00
use Illuminate\Support\Facades\Crypt;
class Settings
{
private Setting $setting;
2023-04-06 17:58:53 -07:00
2023-04-06 17:42:15 -07:00
private function __construct()
{
$this->setting = Setting::factory()->create();
}
2023-04-06 17:58:53 -07:00
public static function initialize(): Settings
2023-04-06 17:42:15 -07:00
{
return new self();
}
public function enableAlertEmail(string $email = 'notifications@afcrichmond.com'): Settings
{
return $this->update(['alert_email' => $email]);
}
public function disableAlertEmail(): Settings
{
return $this->update(['alert_email' => null]);
}
2023-04-06 18:46:29 -07:00
public function enableMultipleFullCompanySupport(): Settings
{
2023-04-06 18:46:29 -07:00
return $this->update(['full_multiple_companies_support' => 1]);
}
2023-06-06 16:31:14 -07:00
public function disableMultipleFullCompanySupport(): Settings
{
return $this->update(['full_multiple_companies_support' => 0]);
}
2023-04-17 17:31:12 -07:00
public function enableWebhook(): Settings
{
return $this->update([
'webhook_botname' => 'SnipeBot5000',
'webhook_endpoint' => 'https://hooks.slack.com/services/NZ59/Q446/672N',
'webhook_channel' => '#it',
]);
}
public function disableWebhook(): Settings
{
return $this->update([
'webhook_botname' => '',
'webhook_endpoint' => '',
'webhook_channel' => '',
]);
}
public function enableAutoIncrement(): Settings
{
return $this->update([
'auto_increment_assets' => 1,
'auto_increment_prefix' => 'ABCD',
'next_auto_tag_base' => 123,
'zerofill_count' => 5
]);
2023-11-28 13:17:46 -08:00
}
public function disableAutoIncrement(): Settings
{
return $this->update([
'auto_increment_assets' => 0,
'auto_increment_prefix' => 0,
'next_auto_tag_base' => 0,
2023-11-28 13:17:46 -08:00
'zerofill_count' => 0
]);
}
2023-11-28 13:17:46 -08:00
public function enableUniqueSerialNumbers(): Settings
{
return $this->update(['unique_serial' => 1]);
}
public function disableUniqueSerialNumbers(): Settings
{
return $this->update(['unique_serial' => 0]);
}
2023-11-27 06:50:43 -08:00
public function enableLdap(): Settings
{
return $this->update([
'ldap_enabled' => 1,
'ldap_server' => 'ldaps://ldap.example.com',
'ldap_uname' => 'fake_username',
'ldap_pword' => Crypt::encrypt("fake_password"),
'ldap_basedn' => 'CN=Users,DC=ad,DC=example,Dc=com'
]);
}
public function enableAnonymousLdap(): Settings
{
return $this->update([
'ldap_enabled' => 1,
'ldap_server' => 'ldaps://ldap.example.com',
// 'ldap_uname' => 'fake_username',
'ldap_pword' => Crypt::encrypt("fake_password"),
'ldap_basedn' => 'CN=Users,DC=ad,DC=example,Dc=com'
]);
}
public function enableBadPasswordLdap(): Settings
{
return $this->update([
'ldap_enabled' => 1,
'ldap_server' => 'ldaps://ldap.example.com',
'ldap_uname' => 'fake_username',
'ldap_pword' => "badly_encrypted_password!",
'ldap_basedn' => 'CN=Users,DC=ad,DC=example,Dc=com'
]);
}
2023-04-06 17:58:53 -07:00
/**
* @param array $attributes Attributes to modify in the application's settings.
*/
2023-04-06 18:46:29 -07:00
public function set(array $attributes): Settings
2023-04-06 17:48:23 -07:00
{
2023-04-06 18:46:29 -07:00
return $this->update($attributes);
2023-04-06 17:48:23 -07:00
}
2023-04-06 18:46:29 -07:00
private function update(array $attributes): Settings
{
Setting::unguarded(fn() => $this->setting->update($attributes));
2023-04-06 17:50:24 -07:00
Setting::$_cache = null;
2023-04-06 18:46:29 -07:00
return $this;
}
}