<?php

namespace Tests\Unit\Framework;

use InvalidArgumentException;
use Tests\TestCase;

class HelpersTest extends TestCase
{
    public function testDbTable(): void
    {

        $this->assertEquals('oc_some_table', db_table('some_table'));
    }

    public function testDbColumnWithTableAndColumn(): void
    {
        $column = 'users.email';
        $expected = 'oc_users.email';

        $this->assertEquals($expected, db_column($column));
    }

    public function testDbColumnWithoutTable(): void
    {
        $column = 'email';
        $expected = 'email';

        $this->assertEquals($expected, db_column($column));
    }

    public function testDbColumnWithEmptyTable(): void
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('Invalid column reference: ');

        db_column('.email');
    }

    public function testDbColumnWithEmptyColumn(): void
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('Invalid column reference: ');

        db_column('users.');
    }

    public function testDbColumnWithEmptyTableAndColumn(): void
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('Invalid column reference: ');

        db_column('.');
    }
}
