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/LeadMapperTest.php

<?php

use PHPUnit\Framework\TestCase;

/**
 * LBT-1468 — Unit tests for LB_Lead_Mapper::toLeadboxOs().
 *
 * Pure-PHP: builds an LB_Lead_Dto from a form-style array and asserts the
 * Leadbox Platform payload shape (flat PascalCase, AdditionalData bag, dropped /
 * forwarded keys, boolean coercion). No WordPress runtime required.
 */
final class LeadMapperTest extends TestCase
{
    /**
     * Build a DTO the same way the Ninja Forms action does (FromArray).
     */
    private function dto(array $data): LB_Lead_Dto
    {
        $dto = new LB_Lead_Dto();
        $dto->FromArray($data);
        return $dto;
    }

    public function test_maps_required_top_level_fields(): void
    {
        $payload = LB_Lead_Mapper::toLeadboxOs($this->dto([
            'first_name' => 'John',
            'last_name'  => 'Doe',
            'email'      => 'john@example.com',
            'phone'      => '6135551234',
        ]));

        $this->assertSame('John', $payload['Name']);
        $this->assertSame('Doe', $payload['Lastname']);
        $this->assertSame('john@example.com', $payload['Email']);
        $this->assertSame('6135551234', $payload['Phone']);
    }

    public function test_resolves_field_aliases(): void
    {
        $payload = LB_Lead_Mapper::toLeadboxOs($this->dto([
            'firstname'   => 'Jane',
            'lastname'    => 'Smith',
            'phonenumber' => '5145559876',
        ]));

        $this->assertSame('Jane', $payload['Name']);
        $this->assertSame('Smith', $payload['Lastname']);
        $this->assertSame('5145559876', $payload['Phone']);
    }

    public function test_payload_is_flat_pascal_case(): void
    {
        $payload = LB_Lead_Mapper::toLeadboxOs($this->dto([
            'first_name' => 'John',
            'email'      => 'john@example.com',
        ]));

        // Every top-level key is PascalCase (first char upper-case).
        foreach (array_keys($payload) as $key) {
            $this->assertMatchesRegularExpression('/^[A-Z]/', $key, "Top-level key '$key' should be PascalCase");
        }
        // No nesting except AdditionalData.
        foreach ($payload as $key => $value) {
            if ($key !== 'AdditionalData') {
                $this->assertIsNotArray($value, "Top-level field '$key' should be a scalar");
            }
        }
    }

    public function test_source_defaults_to_website(): void
    {
        $payload = LB_Lead_Mapper::toLeadboxOs($this->dto([
            'email'  => 'x@y.com',
            'source' => '',
        ]));
        $this->assertSame('website', $payload['Source']);
    }

    public function test_type_is_lowercased_for_flow_routing(): void
    {
        $payload = LB_Lead_Mapper::toLeadboxOs($this->dto([
            'email' => 'x@y.com',
            'type'  => 'EmailAFriend',
        ]));
        $this->assertSame('emailafriend', $payload['Type']);

        $financing = LB_Lead_Mapper::toLeadboxOs($this->dto([
            'email' => 'x@y.com',
            'type'  => 'Financing',
        ]));
        $this->assertSame('financing', $financing['Type']);
    }

    public function test_type_defaults_to_general(): void
    {
        $payload = LB_Lead_Mapper::toLeadboxOs($this->dto(['email' => 'x@y.com']));
        $this->assertSame('general', $payload['Type']);
    }

    public function test_message_falls_back_to_comments(): void
    {
        $payload = LB_Lead_Mapper::toLeadboxOs($this->dto([
            'email'    => 'x@y.com',
            'comments' => 'Please call me',
        ]));
        $this->assertSame('Please call me', $payload['Message']);
        $this->assertSame('Please call me', $payload['Comments']);
    }

    public function test_message_preferred_over_comments(): void
    {
        $payload = LB_Lead_Mapper::toLeadboxOs($this->dto([
            'email'    => 'x@y.com',
            'message'  => 'Primary message',
            'comments' => 'Secondary comments',
        ]));
        $this->assertSame('Primary message', $payload['Message']);
        $this->assertSame('Secondary comments', $payload['Comments']);
    }

    public function test_forwards_skip_flags_as_real_booleans(): void
    {
        $payload = LB_Lead_Mapper::toLeadboxOs($this->dto([
            'email'            => 'x@y.com',
            'skipadf'          => 'true',
            'skipdelivr'       => 'false',
            'skipshiftdigital' => 'true',
        ]));

        $this->assertArrayHasKey('SkipADF', $payload);
        $this->assertArrayHasKey('SkipDelivr', $payload);
        $this->assertArrayHasKey('SkipShiftDigital', $payload);

        $this->assertTrue($payload['SkipADF']);
        $this->assertFalse($payload['SkipDelivr']);
        $this->assertTrue($payload['SkipShiftDigital']);
    }

    public function test_skip_flags_omitted_when_absent(): void
    {
        $payload = LB_Lead_Mapper::toLeadboxOs($this->dto(['email' => 'x@y.com']));
        $this->assertArrayNotHasKey('SkipADF', $payload);
        $this->assertArrayNotHasKey('SkipDelivr', $payload);
        $this->assertArrayNotHasKey('SkipShiftDigital', $payload);
    }

    public function test_drops_send_adf_to(): void
    {
        $payload = LB_Lead_Mapper::toLeadboxOs($this->dto([
            'email'     => 'x@y.com',
            'SendADFTo' => 'adf@dealer.com',
        ]));

        $this->assertArrayNotHasKey('SendADFTo', $payload);
        $this->assertArrayNotHasKey('SendADFTo', $payload['AdditionalData'] ?? []);
    }

    public function test_drops_blocklist_and_internal_keys(): void
    {
        $payload = LB_Lead_Mapper::toLeadboxOs($this->dto([
            'email'                => 'x@y.com',
            'grecaptcha'           => 'token',           // DTO blocklist
            'g-recaptcha-response' => 'token',           // DTO blocklist
            'subject'              => 'dropme',          // DTO blocklist
            'body'                 => 'dropme',          // DTO blocklist
            'form_id'              => '42',              // mapper drop
            'htmlfoo'              => 'dropme',          // DTO html* drop
        ]));

        $flat = json_encode($payload);
        foreach (['grecaptcha', 'recaptcha', 'subject', 'dropme', 'form_id', 'htmlfoo'] as $needle) {
            $this->assertStringNotContainsStringIgnoringCase($needle, $flat, "'$needle' must not be forwarded");
        }
    }

    public function test_additional_data_carries_vehicle_and_attribution(): void
    {
        $payload = LB_Lead_Mapper::toLeadboxOs($this->dto([
            'email'       => 'x@y.com',
            'stocknumber' => 'STK-1234',
            'vin'         => '1HGCM82633A004352',
            'vdp_url'     => 'https://dealer.com/civic',
            'gclid'       => 'CjwKabc',
            'utm_source'  => 'google',
            'utm_medium'  => 'cpc',
            'referrer'    => 'https://google.com',
        ]));

        $this->assertArrayHasKey('AdditionalData', $payload);
        $ad = $payload['AdditionalData'];

        // stocknumber is normalized to the documented `stock` key.
        $this->assertSame('STK-1234', $ad['stock']);
        $this->assertArrayNotHasKey('stocknumber', $ad);

        $this->assertSame('1HGCM82633A004352', $ad['vin']);
        $this->assertSame('https://dealer.com/civic', $ad['vdp_url']);
        $this->assertSame('CjwKabc', $ad['gclid']);
        $this->assertSame('google', $ad['utm_source']);
        $this->assertSame('cpc', $ad['utm_medium']);
        $this->assertSame('https://google.com', $ad['referrer']);
    }

    public function test_vehicle_id_cast_to_int_when_numeric(): void
    {
        $payload = LB_Lead_Mapper::toLeadboxOs($this->dto([
            'email'     => 'x@y.com',
            'vehicleid' => '42',
        ]));
        $this->assertSame(42, $payload['VehicleId']);
    }

    public function test_location_id_omitted_by_default(): void
    {
        $payload = LB_Lead_Mapper::toLeadboxOs($this->dto(['email' => 'x@y.com']));
        $this->assertArrayNotHasKey('LocationId', $payload);
    }

    public function test_location_id_promoted_when_numeric(): void
    {
        $payload = LB_Lead_Mapper::toLeadboxOs($this->dto([
            'email'       => 'x@y.com',
            'location_id' => '10',
        ]));
        $this->assertSame(10, $payload['LocationId']);
        // It must not also leak into AdditionalData.
        $this->assertArrayNotHasKey('location_id', $payload['AdditionalData'] ?? []);
    }

    public function test_empty_values_are_omitted(): void
    {
        $payload = LB_Lead_Mapper::toLeadboxOs($this->dto([
            'email'      => 'x@y.com',
            'first_name' => '',
            'phone'      => '   ',
        ]));
        $this->assertArrayNotHasKey('Name', $payload);
        $this->assertArrayNotHasKey('Phone', $payload);
    }
}

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