<?php
namespace nur\data\types;

use nur\t\TestCase;

class TelephoneTypeTest extends TestCase {
  function testWith(): void {
    $type = new TelephoneType();
    self::assertSame("0262 30 65 00", $type->with("306500"));
    self::assertSame("0262 30 65 00", $type->with("0262306500"));
    self::assertSame("0262 30 65 00", $type->with("+262262306500"));
    self::assertSame("0692 29 58 24", $type->with("+262692295824"));
    self::assertSame("0262 30 65 00", $type->with("+33262306500"));
    self::assertSame("0692 29 58 24", $type->with("+33692295824"));
    self::assertSame("0156 12 34 56", $type->with("0156123456"));
    self::assertSame("0156 12 34 56", $type->with("+33156123456"));
  }

  function testEnsureInternational(): void {
    $type = new TelephoneType();
    self::assertSame("+262 262 30 65 00", $type->ensureInternational($type->with("306500")));
    self::assertSame("+262 262 30 65 00", $type->ensureInternational($type->with("0262306500")));
    self::assertSame("+262 262 30 65 00", $type->ensureInternational($type->with("+262262306500")));
    self::assertSame("+262 692 29 58 24", $type->ensureInternational($type->with("+262692295824")));
    self::assertSame("+262 262 30 65 00", $type->ensureInternational($type->with("+33262306500")));
    self::assertSame("+262 692 29 58 24", $type->ensureInternational($type->with("+33692295824")));
    self::assertSame("+33 156 12 34 56", $type->ensureInternational($type->with("0156123456")));
    self::assertSame("+33 156 12 34 56", $type->ensureInternational($type->with("+33156123456")));
  }

  function testEnsureLocal(): void {
    $type = new TelephoneType();
    self::assertSame("2207", $type->ensureLocal($type->with("2207")));
    self::assertSame("0262 30 65 00", $type->ensureLocal($type->with("+262 262 30 65 00")));
    self::assertSame("0692 29 58 24", $type->ensureLocal($type->with("+262 692 29 58 24")));
    self::assertSame("0156 12 34 56", $type->ensureLocal($type->with("+33 156 12 34 56")));
  }
}
