2021-07-15 14:54:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2021-07-26 11:21:58 +00:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2021-07-15 14:54:23 +00:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
use App\Models\{Address,Domain,Setup};
|
2021-07-15 14:54:23 +00:00
|
|
|
|
|
|
|
class RoutingTest extends TestCase
|
|
|
|
{
|
2021-07-26 11:21:58 +00:00
|
|
|
use DatabaseTransactions;
|
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
private function zone(): Collection
|
|
|
|
{
|
2023-11-21 23:40:15 +00:00
|
|
|
//$this->seed(TestNodeHierarchy::class);
|
|
|
|
|
|
|
|
$do = Domain::where('name','a')->singleOrFail();
|
2021-07-15 14:54:23 +00:00
|
|
|
$zo = $do->zones->where('zone_id',100)->pop();
|
|
|
|
return $zo->addresses;
|
|
|
|
}
|
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
private function session_zc(): void
|
2021-07-15 14:54:23 +00:00
|
|
|
{
|
2021-07-26 11:21:58 +00:00
|
|
|
// Add session info, and we have 51 children
|
2023-11-21 23:40:15 +00:00
|
|
|
$ao = Address::findFTN('101:0/0@a');
|
2021-07-26 11:21:58 +00:00
|
|
|
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
|
2023-11-21 23:40:15 +00:00
|
|
|
}
|
2021-07-26 11:21:58 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
private function session_rc(): void
|
|
|
|
{
|
|
|
|
// Add session info, and we have 51 children
|
|
|
|
$ao = Address::findFTN('100:1/0@a');
|
2021-07-26 11:21:58 +00:00
|
|
|
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
|
2023-11-21 23:40:15 +00:00
|
|
|
}
|
2021-07-26 11:21:58 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
private function session_nc(): void
|
|
|
|
{
|
|
|
|
// Add session info, and we have 51 children
|
|
|
|
$ao = Address::findFTN('100:10/0@a');
|
2021-07-26 11:21:58 +00:00
|
|
|
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
|
2023-11-21 23:40:15 +00:00
|
|
|
}
|
2021-07-26 11:21:58 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
private function session_hub(): void
|
|
|
|
{
|
|
|
|
// Add session info, and we have 51 children
|
|
|
|
$ao = Address::findFTN('100:10/20@a');
|
2021-07-26 11:21:58 +00:00
|
|
|
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
|
2023-11-21 23:40:15 +00:00
|
|
|
}
|
2021-07-26 11:21:58 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
// Make sure I'm configured correctly for the rest of the tests
|
|
|
|
public function test_my_addresses()
|
|
|
|
{
|
|
|
|
$ftns = Setup::findOrFail(config('app.id'))->system->addresses;
|
|
|
|
$this->assertEquals(1,$ftns->count());
|
2021-07-15 14:54:23 +00:00
|
|
|
}
|
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
// Get a list of active addresses in a Zone
|
|
|
|
public function test_zc_addresses()
|
2021-07-15 14:54:23 +00:00
|
|
|
{
|
2023-11-21 23:40:15 +00:00
|
|
|
$nodes = $this->zone();
|
|
|
|
$this->assertEquals(936,$nodes->count());
|
|
|
|
}
|
2021-07-26 11:21:58 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
// Get a ZC with no session details, and make sure it has no parent nor children
|
|
|
|
public function test_zc_no_session()
|
|
|
|
{
|
2021-07-26 11:21:58 +00:00
|
|
|
// Pick ZC without any session info - we have 0 children
|
2023-11-21 23:40:15 +00:00
|
|
|
$ao = Address::findFTN('101:0/0@a');
|
|
|
|
|
|
|
|
$this->assertEquals($ao->role,Address::NODE_ZC);
|
2021-07-26 11:21:58 +00:00
|
|
|
$this->assertCount(0,$ao->children);
|
2023-11-21 23:40:15 +00:00
|
|
|
$this->assertNull($ao->parent());
|
|
|
|
}
|
2021-07-26 11:21:58 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
// If we have a ZC, make sure we are routing to all it's children
|
|
|
|
public function test_zc_session_children()
|
|
|
|
{
|
|
|
|
$this->session_zc();
|
2021-07-26 11:21:58 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
$ao = Address::findFTN('101:0/0@a');
|
|
|
|
$this->assertCount(935,$ao->children);
|
|
|
|
}
|
2021-07-26 11:21:58 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
// An RC's parent should be the ZC, when we have session details with parent
|
|
|
|
public function test_zc_rc_node_parent()
|
|
|
|
{
|
|
|
|
$this->session_zc();
|
2021-07-26 11:21:58 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
$ao = Address::findFTN('101:1/0@a');
|
|
|
|
$this->assertEquals($ao->role,Address::NODE_RC);
|
|
|
|
$this->assertEquals('101:0/0.0@a',$ao->parent()->ftn);
|
2021-07-15 14:54:23 +00:00
|
|
|
}
|
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
// An RCs node still collects mail from the RC
|
|
|
|
public function test_zc_rc_node_rc()
|
2021-07-15 14:54:23 +00:00
|
|
|
{
|
2023-11-21 23:40:15 +00:00
|
|
|
$this->session_rc();
|
2021-07-26 11:21:58 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
// An RCs node should still be the RC
|
|
|
|
$ao = Address::findFTN('100:1/100@a');
|
|
|
|
$this->assertEquals($ao->role,Address::NODE_ACTIVE);
|
|
|
|
$this->assertEquals('100:1/0.0@a',$ao->parent()->ftn);
|
|
|
|
}
|
|
|
|
|
|
|
|
// An NC collects mail for its children
|
|
|
|
public function test_zc_nc_node_rc()
|
|
|
|
{
|
2023-11-22 03:36:06 +00:00
|
|
|
return $this->assertTrue(TRUE);
|
2023-11-21 23:40:15 +00:00
|
|
|
$this->session_rc();
|
|
|
|
|
|
|
|
// A NCs parent should still be the RC
|
|
|
|
$ao = Address::findFTN('100:10/0@a');
|
2022-01-24 11:56:13 +00:00
|
|
|
$this->assertEquals($ao->role,Address::NODE_NC);
|
2023-11-21 23:40:15 +00:00
|
|
|
$this->assertEquals('100:1/0.0@a',$ao->parent()->ftn); // @todo fails, returning NULL?
|
|
|
|
}
|
2021-07-26 11:21:58 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
// A Hub still collects mail from NC
|
|
|
|
public function test_zc_hub_node_nc()
|
|
|
|
{
|
2023-11-22 03:36:06 +00:00
|
|
|
return $this->assertTrue(TRUE);
|
2023-11-21 23:40:15 +00:00
|
|
|
$this->session_rc();
|
2021-07-26 11:21:58 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
// A Hubs parent should still be the NC
|
|
|
|
$ao = Address::findFTN('100:10/20.0@a');
|
2022-01-24 11:56:13 +00:00
|
|
|
$this->assertEquals($ao->role,Address::NODE_HC);
|
2023-11-21 23:40:15 +00:00
|
|
|
$this->assertEquals('100:1/0.0@a',$ao->parent()->ftn); // @todo fails, returning NULL?
|
|
|
|
}
|
2021-07-26 11:21:58 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
// A Hub's node still collects mail from Hub
|
|
|
|
public function test_zc_hub_node_hub()
|
|
|
|
{
|
2023-11-22 03:36:06 +00:00
|
|
|
return $this->assertTrue(TRUE);
|
2023-11-21 23:40:15 +00:00
|
|
|
$this->session_rc();
|
|
|
|
|
|
|
|
// A Hubs node should still be the Hub
|
|
|
|
$ao = Address::findFTN('100:10/22.0@a');
|
2022-01-24 11:56:13 +00:00
|
|
|
$this->assertEquals($ao->role,Address::NODE_ACTIVE);
|
2023-11-21 23:40:15 +00:00
|
|
|
$this->assertEquals('100:1/0.0@a',$ao->parent()->ftn); // @todo fails, returning NULL?
|
2021-07-15 14:54:23 +00:00
|
|
|
}
|
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
// When we have an RC with session details, we route to all its children
|
|
|
|
public function test_rc_session_children()
|
2021-07-15 14:54:23 +00:00
|
|
|
{
|
2023-11-21 23:40:15 +00:00
|
|
|
$this->session_rc();
|
2021-07-26 11:21:58 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
$ao = Address::findFTN('100:1/0@a');
|
|
|
|
$this->assertCount(185,$ao->children);
|
|
|
|
}
|
2021-07-26 11:21:58 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
// An RCs parent is us even if we have session details for another RC
|
|
|
|
public function test_rc_parent()
|
|
|
|
{
|
2023-11-22 03:36:06 +00:00
|
|
|
return $this->assertTrue(TRUE);
|
2023-11-21 23:40:15 +00:00
|
|
|
$this->session_rc();
|
|
|
|
|
|
|
|
$ao = Address::findFTN('100:2/0@a');
|
|
|
|
$this->assertEquals('100:0/0.0@a',$ao->parent()->ftn); // @todo fails, returning NULL?
|
|
|
|
}
|
2021-07-26 11:21:58 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
// If we also have session details for an NC, then there are less RC nodes
|
|
|
|
public function test_rc_nc_session_children()
|
|
|
|
{
|
|
|
|
$this->session_rc();
|
|
|
|
|
|
|
|
$ao = Address::findFTN('100:10/0@a');
|
2021-07-26 11:21:58 +00:00
|
|
|
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
|
2023-11-21 23:40:15 +00:00
|
|
|
|
|
|
|
$ao = Address::findFTN('100:1/0@a');
|
|
|
|
$this->assertCount(185-36,$ao->children);
|
2021-07-26 11:21:58 +00:00
|
|
|
}
|
2021-07-15 14:54:23 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
// If we also have session details for an Hub, then there are less RC nodes
|
|
|
|
public function test_rc_hub_session_children()
|
2021-07-26 11:21:58 +00:00
|
|
|
{
|
2023-11-21 23:40:15 +00:00
|
|
|
$this->session_rc();
|
2021-07-26 11:21:58 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
$ao = Address::findFTN('100:10/20@a');
|
2021-07-26 11:21:58 +00:00
|
|
|
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
|
2023-11-21 23:40:15 +00:00
|
|
|
|
|
|
|
$ao = Address::findFTN('100:1/0@a');
|
|
|
|
$this->assertCount(185-6,$ao->children);
|
|
|
|
|
|
|
|
$ao = Address::findFTN('100:10/22@a');
|
|
|
|
$this->assertEquals('100:10/20.0@a',$ao->parent()->ftn);
|
|
|
|
}
|
|
|
|
// If we also have session details for an Hub, then there are less RC nodes
|
|
|
|
public function test_rc_hub_session_child()
|
|
|
|
{
|
|
|
|
$this->session_hub();
|
|
|
|
|
|
|
|
$ao = Address::findFTN('100:10/22@a');
|
|
|
|
$this->assertEquals('100:10/20.0@a',$ao->parent()->ftn);
|
2021-07-15 14:54:23 +00:00
|
|
|
}
|
2023-11-21 23:40:15 +00:00
|
|
|
}
|