161 lines
4.9 KiB
PHP
161 lines
4.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../ninjamail.class.php';
|
|
|
|
echo "=== ninjaMail PHP érvényesség és típusvizsgálat ===\n";
|
|
|
|
$passed = 0;
|
|
$failed = 0;
|
|
|
|
function runTest(string $description, callable $fn): void {
|
|
global $passed, $failed;
|
|
try {
|
|
$fn();
|
|
echo " [OK] $description\n";
|
|
$passed++;
|
|
} catch (Throwable $e) {
|
|
echo " [FAIL] $description: " . $e->getMessage() . "\n";
|
|
$failed++;
|
|
}
|
|
}
|
|
|
|
// 1. ninjaMail alaposztály
|
|
runTest("ninjaMail inicializálás és check()", function () {
|
|
$api = new ninjaMail('https://example.org', 'test-key');
|
|
assert($api->check() === true, "check() igaz kell legyen érvényes adatokkal");
|
|
|
|
$apiNoKey = new ninjaMail('https://example.org');
|
|
assert($apiNoKey->check() === false, "check() hamis kell legyen hiányzó kulccsal");
|
|
});
|
|
|
|
// 2. ninjaMailSend
|
|
runTest("ninjaMailSend metódusok és kötelező mezők validációja", function () {
|
|
$s = new ninjaMailSend('https://example.org', 'test-key');
|
|
assert($s->to('user@example.com') === true);
|
|
assert($s->subject('Teszt tárgy') === true);
|
|
assert($s->message('<b>HTML</b>', 'Szöveg') === true);
|
|
|
|
$emptySender = new ninjaMailSend('https://example.org', 'test-key');
|
|
try {
|
|
$emptySender->send();
|
|
throw new Exception("Nem dobott kivételt hiányzó mezők esetén");
|
|
} catch (InvalidArgumentException $e) {
|
|
// Sikeres teszt, elvárt kivétel
|
|
}
|
|
});
|
|
|
|
// 3. ninjaMailSubscription
|
|
runTest("ninjaMailSubscription beállítások és lista validáció", function () {
|
|
$sub = new ninjaMailSubscription('https://example.org', 'test-key');
|
|
assert($sub->list(10) === true);
|
|
assert($sub->list(0) === false);
|
|
assert($sub->list(-5) === false);
|
|
assert($sub->activated(true) === true);
|
|
assert($sub->namechange(true) === true);
|
|
|
|
$emptySub = new ninjaMailSubscription('https://example.org', 'test-key');
|
|
try {
|
|
$emptySub->subscribe('user@example.com');
|
|
throw new Exception("Nem dobott kivételt hiányzó lista esetén");
|
|
} catch (InvalidArgumentException $e) {
|
|
// Sikeres teszt
|
|
}
|
|
|
|
try {
|
|
$emptySub->unsubscribe('user@example.com');
|
|
throw new Exception("Nem dobott kivételt hiányzó lista esetén");
|
|
} catch (InvalidArgumentException $e) {
|
|
// Sikeres teszt
|
|
}
|
|
});
|
|
|
|
// 4. ninjaMailNewsletter
|
|
runTest("ninjaMailNewsletter hírlevél azonosító és üzenet validáció", function () {
|
|
$nl = new ninjaMailNewsletter('https://example.org', 'test-key');
|
|
assert($nl->subject('Tárgy') === true);
|
|
assert($nl->message('Tartalom') === true);
|
|
assert($nl->newsletter(25) === true);
|
|
assert($nl->newsletter() === 25);
|
|
assert($nl->newsletter(0) === false);
|
|
|
|
$emptyNl = new ninjaMailNewsletter('https://example.org', 'test-key');
|
|
try {
|
|
$emptyNl->create();
|
|
throw new Exception("Nem dobott kivételt üres üzenetnél");
|
|
} catch (InvalidArgumentException $e) {
|
|
// Sikeres teszt
|
|
}
|
|
|
|
try {
|
|
$emptyNl->update();
|
|
throw new Exception("Nem dobott kivételt hírlevél ID nélkül");
|
|
} catch (InvalidArgumentException $e) {
|
|
// Sikeres teszt
|
|
}
|
|
|
|
try {
|
|
$emptyNl->send();
|
|
throw new Exception("Nem dobott kivételt hírlevél ID nélkül");
|
|
} catch (InvalidArgumentException $e) {
|
|
// Sikeres teszt
|
|
}
|
|
});
|
|
|
|
// 5. ninjaMailCampaign
|
|
runTest("ninjaMailCampaign kampány validáció", function () {
|
|
$camp = new ninjaMailCampaign('https://example.org', 'test-key');
|
|
assert($camp->campaign(40) === true);
|
|
assert($camp->campaign() === 40);
|
|
assert($camp->campaign(0) === false);
|
|
|
|
try {
|
|
$camp->create('');
|
|
throw new Exception("Nem dobott kivételt üres névnél");
|
|
} catch (InvalidArgumentException $e) {
|
|
// Sikeres teszt
|
|
}
|
|
|
|
$emptyCamp = new ninjaMailCampaign('https://example.org', 'test-key');
|
|
try {
|
|
$emptyCamp->remove();
|
|
throw new Exception("Nem dobott kivételt kampány ID nélkül");
|
|
} catch (InvalidArgumentException $e) {
|
|
// Sikeres teszt
|
|
}
|
|
|
|
try {
|
|
$camp->update([]);
|
|
throw new Exception("Nem dobott kivételt üres listánál");
|
|
} catch (InvalidArgumentException $e) {
|
|
// Sikeres teszt
|
|
}
|
|
|
|
try {
|
|
$camp->attach(0);
|
|
throw new Exception("Nem dobott kivételt érvénytelen hírlevél ID-nél");
|
|
} catch (InvalidArgumentException $e) {
|
|
// Sikeres teszt
|
|
}
|
|
});
|
|
|
|
// 6. ninjaMailStatistics
|
|
runTest("ninjaMailStatistics azonosító validáció", function () {
|
|
$stat = new ninjaMailStatistics('https://example.org', 'test-key');
|
|
try {
|
|
$stat->get(0);
|
|
throw new Exception("Nem dobott kivételt 0 azonosítónál");
|
|
} catch (InvalidArgumentException $e) {
|
|
// Sikeres teszt
|
|
}
|
|
});
|
|
|
|
echo "\nTeszt összefoglaló: $passed sikeres, $failed sikertelen.\n";
|
|
|
|
if ($failed > 0) {
|
|
exit(1);
|
|
}
|
|
|
|
exit(0);
|