ver. 0.279: Newsletter frontend migration, Languages facade elimination, bug fix newsletter_unsubscribe
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -75,4 +75,145 @@ class NewsletterRepositoryTest extends TestCase
|
||||
|
||||
$this->assertSame('Template text', $repository->templateByName('#abc'));
|
||||
}
|
||||
|
||||
// ── Frontend methods tests ──
|
||||
|
||||
public function testUnsubscribeReturnsFalseForInvalidHash(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_newsletter', 'id', ['hash' => 'bad-hash'])
|
||||
->willReturn(null);
|
||||
|
||||
$repository = new NewsletterRepository($mockDb, $this->createMock(SettingsRepository::class));
|
||||
|
||||
$this->assertFalse($repository->unsubscribe('bad-hash'));
|
||||
}
|
||||
|
||||
public function testUnsubscribeDeletesSubscriber(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_newsletter', 'id', ['hash' => 'abc123'])
|
||||
->willReturn(42);
|
||||
$mockDb->expects($this->once())
|
||||
->method('delete')
|
||||
->with('pp_newsletter', ['id' => 42]);
|
||||
|
||||
$repository = new NewsletterRepository($mockDb, $this->createMock(SettingsRepository::class));
|
||||
|
||||
$this->assertTrue($repository->unsubscribe('abc123'));
|
||||
}
|
||||
|
||||
public function testConfirmSubscriptionReturnsFalseForInvalidHash(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_newsletter', 'id', ['AND' => ['hash' => 'bad', 'status' => 0]])
|
||||
->willReturn(null);
|
||||
|
||||
$repository = new NewsletterRepository($mockDb, $this->createMock(SettingsRepository::class));
|
||||
|
||||
$this->assertFalse($repository->confirmSubscription('bad'));
|
||||
}
|
||||
|
||||
public function testConfirmSubscriptionUpdatesStatus(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_newsletter', 'id', ['AND' => ['hash' => 'valid', 'status' => 0]])
|
||||
->willReturn(10);
|
||||
$mockDb->expects($this->once())
|
||||
->method('update')
|
||||
->with('pp_newsletter', ['status' => 1], ['id' => 10]);
|
||||
|
||||
$repository = new NewsletterRepository($mockDb, $this->createMock(SettingsRepository::class));
|
||||
|
||||
$this->assertTrue($repository->confirmSubscription('valid'));
|
||||
}
|
||||
|
||||
public function testGetHashByEmailReturnsHash(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_newsletter', 'hash', ['email' => 'test@test.pl'])
|
||||
->willReturn('abc123');
|
||||
|
||||
$repository = new NewsletterRepository($mockDb, $this->createMock(SettingsRepository::class));
|
||||
|
||||
$this->assertSame('abc123', $repository->getHashByEmail('test@test.pl'));
|
||||
}
|
||||
|
||||
public function testGetHashByEmailReturnsNullForMissing(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_newsletter', 'hash', ['email' => 'none@test.pl'])
|
||||
->willReturn(null);
|
||||
|
||||
$repository = new NewsletterRepository($mockDb, $this->createMock(SettingsRepository::class));
|
||||
|
||||
$this->assertNull($repository->getHashByEmail('none@test.pl'));
|
||||
}
|
||||
|
||||
public function testRemoveByEmailDeletesSubscriber(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_newsletter', 'id', ['email' => 'test@test.pl'])
|
||||
->willReturn(5);
|
||||
$mockDb->expects($this->once())
|
||||
->method('delete')
|
||||
->with('pp_newsletter', ['email' => 'test@test.pl'])
|
||||
->willReturn(true);
|
||||
|
||||
$repository = new NewsletterRepository($mockDb, $this->createMock(SettingsRepository::class));
|
||||
|
||||
$this->assertTrue($repository->removeByEmail('test@test.pl'));
|
||||
}
|
||||
|
||||
public function testRemoveByEmailReturnsFalseForMissing(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_newsletter', 'id', ['email' => 'none@test.pl'])
|
||||
->willReturn(null);
|
||||
|
||||
$repository = new NewsletterRepository($mockDb, $this->createMock(SettingsRepository::class));
|
||||
|
||||
$this->assertFalse($repository->removeByEmail('none@test.pl'));
|
||||
}
|
||||
|
||||
public function testSignupReturnsFalseForExistingEmail(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_newsletter', 'id', ['email' => 'exists@test.pl'])
|
||||
->willReturn(1);
|
||||
|
||||
$repository = new NewsletterRepository($mockDb, $this->createMock(SettingsRepository::class));
|
||||
|
||||
$this->assertFalse($repository->signup('exists@test.pl', 'example.com', false, []));
|
||||
}
|
||||
|
||||
public function testConstructorAcceptsOptionalDependencies(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$settingsRepo = $this->createMock(SettingsRepository::class);
|
||||
$articleRepo = $this->createMock(\Domain\Article\ArticleRepository::class);
|
||||
$renderer = $this->createMock(\Domain\Newsletter\NewsletterPreviewRenderer::class);
|
||||
|
||||
$repository = new NewsletterRepository($mockDb, $settingsRepo, $articleRepo, $renderer);
|
||||
|
||||
$this->assertInstanceOf(NewsletterRepository::class, $repository);
|
||||
}
|
||||
}
|
||||
@@ -5,23 +5,26 @@ use PHPUnit\Framework\TestCase;
|
||||
use admin\Controllers\ShopProductController;
|
||||
use Domain\Product\ProductRepository;
|
||||
use Domain\Integrations\IntegrationsRepository;
|
||||
use Domain\Languages\LanguagesRepository;
|
||||
|
||||
class ShopProductControllerTest extends TestCase
|
||||
{
|
||||
private $repository;
|
||||
private $integrationsRepository;
|
||||
private $languagesRepository;
|
||||
private $controller;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->repository = $this->createMock(ProductRepository::class);
|
||||
$this->integrationsRepository = $this->createMock(IntegrationsRepository::class);
|
||||
$this->controller = new ShopProductController($this->repository, $this->integrationsRepository);
|
||||
$this->languagesRepository = $this->createMock(LanguagesRepository::class);
|
||||
$this->controller = new ShopProductController($this->repository, $this->integrationsRepository, $this->languagesRepository);
|
||||
}
|
||||
|
||||
public function testConstructorAcceptsRepositories(): void
|
||||
{
|
||||
$controller = new ShopProductController($this->repository, $this->integrationsRepository);
|
||||
$controller = new ShopProductController($this->repository, $this->integrationsRepository, $this->languagesRepository);
|
||||
$this->assertInstanceOf(ShopProductController::class, $controller);
|
||||
}
|
||||
|
||||
@@ -105,9 +108,10 @@ class ShopProductControllerTest extends TestCase
|
||||
$constructor = $reflection->getConstructor();
|
||||
$params = $constructor->getParameters();
|
||||
|
||||
$this->assertCount(2, $params);
|
||||
$this->assertCount(3, $params);
|
||||
$this->assertEquals('Domain\Product\ProductRepository', $params[0]->getType()->getName());
|
||||
$this->assertEquals('Domain\Integrations\IntegrationsRepository', $params[1]->getType()->getName());
|
||||
$this->assertEquals('Domain\Languages\LanguagesRepository', $params[2]->getType()->getName());
|
||||
}
|
||||
|
||||
public function testHasFormBuildingHelpers(): void
|
||||
|
||||
@@ -49,6 +49,9 @@ if (!class_exists('S')) {
|
||||
public static function set_message($msg) {}
|
||||
public static function clear_redis_cache() {}
|
||||
public static function clear_product_cache($id) {}
|
||||
public static function email_check($email) { return filter_var($email, FILTER_VALIDATE_EMAIL); }
|
||||
public static function get_session($key) { return $_SESSION[$key] ?? null; }
|
||||
public static function set_session($key, $value) { $_SESSION[$key] = $value; }
|
||||
public static function send_email($to, $subject, $body) { return true; }
|
||||
public static function remove_special_chars($str) { return str_ireplace(['\'', '"', ',', ';', '<', '>'], ' ', $str); }
|
||||
public static function normalize_decimal($val, $precision = 2) { return round((float)$val, $precision); }
|
||||
|
||||
Reference in New Issue
Block a user