Parse and validate AT Protocol Lexicons with DTO generation for Laravel
1<?php
2
3namespace SocialDept\AtpSchema\Tests\Unit\Validation\Rules;
4
5use Orchestra\Testbench\TestCase;
6use SocialDept\AtpSchema\Validation\Rules\Cid;
7
8class CidTest extends TestCase
9{
10 protected Cid $rule;
11
12 protected function setUp(): void
13 {
14 parent::setUp();
15
16 $this->rule = new Cid();
17 }
18
19 public function test_it_validates_cidv0(): void
20 {
21 $valid = 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V';
22
23 $failed = false;
24 $this->rule->validate('cid', $valid, function () use (&$failed) {
25 $failed = true;
26 });
27
28 $this->assertFalse($failed);
29 }
30
31 public function test_it_validates_cidv1_with_base32(): void
32 {
33 $valid = 'bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi';
34
35 $failed = false;
36 $this->rule->validate('cid', $valid, function () use (&$failed) {
37 $failed = true;
38 });
39
40 $this->assertFalse($failed);
41 }
42
43 public function test_it_validates_cidv1_with_base58(): void
44 {
45 $valid = 'zdj7WhuEjrB52m1BisYCtmjH1hSKa7yZ3jEZ9JcXaFRD51wVz';
46
47 $failed = false;
48 $this->rule->validate('cid', $valid, function () use (&$failed) {
49 $failed = true;
50 });
51
52 $this->assertFalse($failed);
53 }
54
55 public function test_it_rejects_invalid_cid(): void
56 {
57 $invalid = 'not-a-cid';
58
59 $failed = false;
60 $this->rule->validate('cid', $invalid, function () use (&$failed) {
61 $failed = true;
62 });
63
64 $this->assertTrue($failed);
65 }
66
67 public function test_it_rejects_cidv0_with_wrong_length(): void
68 {
69 $invalid = 'QmShortCid';
70
71 $failed = false;
72 $this->rule->validate('cid', $invalid, function () use (&$failed) {
73 $failed = true;
74 });
75
76 $this->assertTrue($failed);
77 }
78
79 public function test_it_rejects_non_string(): void
80 {
81 $failed = false;
82 $this->rule->validate('cid', 123, function () use (&$failed) {
83 $failed = true;
84 });
85
86 $this->assertTrue($failed);
87 }
88}