AlkantarClanX12

Your IP : 216.73.217.24


Current Path : /www/capitalgmcbuickregina_830/public/wp-content/plugins/leadbox/tests/unit/
Upload File :
Current File : /www/capitalgmcbuickregina_830/public/wp-content/plugins/leadbox/tests/unit/LeadDispatchLogTest.php

<?php

use PHPUnit\Framework\TestCase;

/**
 * LBT-1468 — Unit tests for LB_Lead_Dispatch_Log.
 *
 * Pure-PHP: covers PII masking (mask_email / mask_phone) and the text-line
 * builder (format_line). record() touches WordPress (file path / current_time)
 * and is intentionally not exercised here.
 */
final class LeadDispatchLogTest extends TestCase
{
  /* ---------------- mask_email ---------------- */

  public function test_mask_email_keeps_first_char_and_domain(): void
  {
    $this->assertSame('j***@gmail.com', LB_Lead_Dispatch_Log::mask_email('john@gmail.com'));
    $this->assertSame('p***@leadboxhq.com', LB_Lead_Dispatch_Log::mask_email('pablo@leadboxhq.com'));
  }

  public function test_mask_email_empty_is_none(): void
  {
    $this->assertSame('(none)', LB_Lead_Dispatch_Log::mask_email(''));
    $this->assertSame('(none)', LB_Lead_Dispatch_Log::mask_email('   '));
  }

  public function test_mask_email_malformed_is_redacted(): void
  {
    $this->assertSame('***', LB_Lead_Dispatch_Log::mask_email('not-an-email'));
  }

  /* ---------------- mask_phone ---------------- */

  public function test_mask_phone_keeps_last_four_digits(): void
  {
    $this->assertSame('***1234', LB_Lead_Dispatch_Log::mask_phone('6135551234'));
  }

  public function test_mask_phone_strips_formatting_then_masks(): void
  {
    $this->assertSame('***1234', LB_Lead_Dispatch_Log::mask_phone('+1 (613) 555-1234'));
  }

  public function test_mask_phone_empty_or_no_digits_is_none(): void
  {
    $this->assertSame('(none)', LB_Lead_Dispatch_Log::mask_phone(''));
    $this->assertSame('(none)', LB_Lead_Dispatch_Log::mask_phone('n/a'));
  }

  /* ---------------- format_line ---------------- */

  public function test_format_line_success_shape(): void
  {
    $line = LB_Lead_Dispatch_Log::format_line(array(
      'target'      => 'both',
      'backend'     => 'leadbox_os',
      'form_id'     => 12,
      'success'     => true,
      'http_status' => 200,
      'latency_ms'  => 312,
      'lead_id'     => 'cnv_abc',
      'email'       => 'john@gmail.com',
      'phone'       => '6135551234',
    ), '2026-06-05 14:23:01');

    $this->assertStringStartsWith('[2026-06-05 14:23:01] OK  ', $line);
    $this->assertStringContainsString('both/leadbox_os', $line);
    $this->assertStringContainsString('form=12', $line);
    $this->assertStringContainsString('http=200', $line);
    $this->assertStringContainsString('lat=312ms', $line);
    $this->assertStringContainsString('lead_id=cnv_abc', $line);
    $this->assertStringContainsString('contact=j***@gmail.com', $line);
    $this->assertStringContainsString('phone=***1234', $line);
    // No error fields on success.
    $this->assertStringNotContainsString('err=', $line);
    $this->assertStringNotContainsString('msg=', $line);
  }

  public function test_format_line_failure_includes_reason(): void
  {
    $line = LB_Lead_Dispatch_Log::format_line(array(
      'target'      => 'both',
      'backend'     => 'leadbox_os',
      'form_id'     => 12,
      'success'     => false,
      'http_status' => 422,
      'error_code'  => 'validation_failed',
      'message'     => 'Email or Phone required',
      'latency_ms'  => 240,
      'email'       => 'john@gmail.com',
      'phone'       => '6135551234',
    ), '2026-06-05 14:23:05');

    $this->assertStringStartsWith('[2026-06-05 14:23:05] FAIL ', $line);
    $this->assertStringContainsString('http=422', $line);
    $this->assertStringContainsString('err=validation_failed', $line);
    $this->assertStringContainsString('msg="Email or Phone required"', $line);
  }

  public function test_format_line_marks_retry(): void
  {
    $line = LB_Lead_Dispatch_Log::format_line(array(
      'target'   => 'leadbox_os',
      'backend'  => 'leadbox_os',
      'form_id'  => 7,
      'success'  => true,
      'is_retry' => true,
    ), '2026-06-05 10:00:00');

    $this->assertStringContainsString('retry=1', $line);
  }

  public function test_format_line_omits_unknown_fields(): void
  {
    // No http/latency/lead_id/email/phone provided.
    $line = LB_Lead_Dispatch_Log::format_line(array(
      'target'  => 'both',
      'backend' => 'leadbox_os',
      'form_id' => 3,
      'success' => true,
      'note'    => 'sent_no_confirmation',
    ), '2026-06-05 10:00:00');

    $this->assertStringNotContainsString('http=', $line);
    $this->assertStringNotContainsString('lat=', $line);
    $this->assertStringNotContainsString('lead_id=', $line);
    $this->assertStringContainsString('contact=(none)', $line);
    $this->assertStringContainsString('phone=(none)', $line);
    $this->assertStringContainsString('note=sent_no_confirmation', $line);
  }

  public function test_format_line_sanitizes_quotes_and_newlines_in_message(): void
  {
    $line = LB_Lead_Dispatch_Log::format_line(array(
      'target'  => 'both',
      'backend' => 'leadbox_os',
      'form_id' => 1,
      'success' => false,
      'message' => "He said \"no\"\nsecond line",
    ), '2026-06-05 10:00:00');

    // Stays on one line; double quotes downgraded to single.
    $this->assertStringNotContainsString("\n", rtrim($line, "\n"));
    $this->assertStringContainsString("msg=\"He said 'no' second line\"", $line);
  }
}

Home - Capital GMC Buick Regina

No data

Welcome to Capital GMC BUICK – REGINA

Thank you for choosing Capital GMC Buick | Regina, your premier certified Buick and GMC dealership proudly serving drivers in Regina and the surrounding communities. Whether you’re searching for a brand-new Buick or GMC vehicle or a meticulously inspected pre-owned model, we have a diverse selection to match your needs and lifestyle.

Beyond our impressive inventory, we offer a seamless and stress-free financing experience through our well-connected finance centre, where our team of experts is dedicated to securing the best loan or lease options for you, quickly, transparently, and hassle-free.

But our commitment to you doesn’t stop at the sale. Our state-of-the-art service centre is staffed with skilled Buick and GMC technicians who use the latest equipment and genuine OEM parts to keep your vehicle running at its best. From routine maintenance to complex repairs, we’ve got you covered.

Experience top-tier customer service, quality vehicles, and expert care, all in one place. Visit Capital GMC Buick | Regina today or call us at 306-205-8072 with any questions. We’re here to help!

Ask a Question