Skip to content

Commit f7eed2c

Browse files
carlbennettclaude
andcommitted
Add PHPUnit tests for remaining Discord embeds, EventLog, and Search\Results
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 00f17af commit f7eed2c

7 files changed

Lines changed: 634 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace BNETDocs\Tests\Libraries\Discord;
4+
5+
use \BNETDocs\Libraries\Discord\EmbedImage;
6+
use \PHPUnit\Framework\TestCase;
7+
8+
class EmbedImageTest extends TestCase
9+
{
10+
// Constructor
11+
12+
public function testConstructorSetsUrl(): void
13+
{
14+
$img = new EmbedImage('https://example.com/img.png');
15+
$data = $img->jsonSerialize();
16+
$this->assertSame('https://example.com/img.png', $data['url']);
17+
}
18+
19+
public function testConstructorOptionalDimensions(): void
20+
{
21+
$img = new EmbedImage('https://example.com/img.png', 640, 480);
22+
$data = $img->jsonSerialize();
23+
$this->assertSame(640, $data['width']);
24+
$this->assertSame(480, $data['height']);
25+
}
26+
27+
public function testConstructorOptionalProxyUrl(): void
28+
{
29+
$img = new EmbedImage('https://example.com/img.png', 0, 0, 'https://proxy.example.com/img.png');
30+
$data = $img->jsonSerialize();
31+
$this->assertSame('https://proxy.example.com/img.png', $data['proxy_url']);
32+
}
33+
34+
// jsonSerialize — empty() strips zero integers and empty strings
35+
36+
public function testJsonSerializeOmitsZeroWidth(): void
37+
{
38+
// empty(0) === true, so zero width is filtered out
39+
$img = new EmbedImage('https://example.com/img.png', 0, 0);
40+
$data = $img->jsonSerialize();
41+
$this->assertArrayNotHasKey('width', $data);
42+
}
43+
44+
public function testJsonSerializeOmitsZeroHeight(): void
45+
{
46+
$img = new EmbedImage('https://example.com/img.png', 0, 0);
47+
$data = $img->jsonSerialize();
48+
$this->assertArrayNotHasKey('height', $data);
49+
}
50+
51+
public function testJsonSerializeOmitsEmptyProxyUrl(): void
52+
{
53+
$img = new EmbedImage('https://example.com/img.png');
54+
$data = $img->jsonSerialize();
55+
$this->assertArrayNotHasKey('proxy_url', $data);
56+
}
57+
58+
public function testJsonSerializeIncludesNonZeroDimensions(): void
59+
{
60+
$img = new EmbedImage('https://example.com/img.png', 100, 200);
61+
$data = $img->jsonSerialize();
62+
$this->assertArrayHasKey('width', $data);
63+
$this->assertArrayHasKey('height', $data);
64+
}
65+
66+
public function testJsonSerializeAlwaysIncludesUrl(): void
67+
{
68+
$img = new EmbedImage('https://example.com/img.png');
69+
$data = $img->jsonSerialize();
70+
$this->assertArrayHasKey('url', $data);
71+
}
72+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace BNETDocs\Tests\Libraries\Discord;
4+
5+
use \BNETDocs\Libraries\Discord\EmbedProvider;
6+
use \PHPUnit\Framework\TestCase;
7+
8+
class EmbedProviderTest extends TestCase
9+
{
10+
// Constructor
11+
12+
public function testConstructorSetsName(): void
13+
{
14+
$p = new EmbedProvider('BNETDocs');
15+
$data = $p->jsonSerialize();
16+
$this->assertSame('BNETDocs', $data['name']);
17+
}
18+
19+
public function testConstructorOptionalUrl(): void
20+
{
21+
$p = new EmbedProvider('BNETDocs', 'https://bnetdocs.org');
22+
$data = $p->jsonSerialize();
23+
$this->assertSame('https://bnetdocs.org', $data['url']);
24+
}
25+
26+
// jsonSerialize
27+
28+
public function testJsonSerializeOmitsEmptyUrl(): void
29+
{
30+
$p = new EmbedProvider('BNETDocs');
31+
$data = $p->jsonSerialize();
32+
$this->assertArrayNotHasKey('url', $data);
33+
}
34+
35+
public function testJsonSerializeIncludesNonEmptyUrl(): void
36+
{
37+
$p = new EmbedProvider('BNETDocs', 'https://bnetdocs.org');
38+
$data = $p->jsonSerialize();
39+
$this->assertArrayHasKey('url', $data);
40+
}
41+
42+
public function testJsonSerializeOmitsEmptyName(): void
43+
{
44+
// No validation on name length; empty name is stripped by empty()
45+
$p = new EmbedProvider('');
46+
$data = $p->jsonSerialize();
47+
$this->assertArrayNotHasKey('name', $data);
48+
}
49+
50+
public function testJsonSerializeImplementsJsonSerializable(): void
51+
{
52+
$p = new EmbedProvider('Name');
53+
$this->assertInstanceOf(\JsonSerializable::class, $p);
54+
}
55+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace BNETDocs\Tests\Libraries\Discord;
4+
5+
use \BNETDocs\Libraries\Discord\EmbedImage;
6+
use \BNETDocs\Libraries\Discord\EmbedThumbnail;
7+
use \PHPUnit\Framework\TestCase;
8+
9+
class EmbedThumbnailTest extends TestCase
10+
{
11+
public function testExtendsEmbedImage(): void
12+
{
13+
$t = new EmbedThumbnail('https://example.com/thumb.png');
14+
$this->assertInstanceOf(EmbedImage::class, $t);
15+
}
16+
17+
public function testJsonSerializeIncludesUrl(): void
18+
{
19+
$t = new EmbedThumbnail('https://example.com/thumb.png');
20+
$data = $t->jsonSerialize();
21+
$this->assertSame('https://example.com/thumb.png', $data['url']);
22+
}
23+
24+
public function testJsonSerializeWithDimensions(): void
25+
{
26+
$t = new EmbedThumbnail('https://example.com/thumb.png', 320, 240);
27+
$data = $t->jsonSerialize();
28+
$this->assertSame(320, $data['width']);
29+
$this->assertSame(240, $data['height']);
30+
}
31+
32+
public function testJsonSerializeOmitsZeroDimensions(): void
33+
{
34+
$t = new EmbedThumbnail('https://example.com/thumb.png');
35+
$data = $t->jsonSerialize();
36+
$this->assertArrayNotHasKey('width', $data);
37+
$this->assertArrayNotHasKey('height', $data);
38+
}
39+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace BNETDocs\Tests\Libraries\Discord;
4+
5+
use \BNETDocs\Libraries\Discord\EmbedVideo;
6+
use \PHPUnit\Framework\TestCase;
7+
8+
class EmbedVideoTest extends TestCase
9+
{
10+
// Constructor
11+
12+
public function testConstructorSetsUrl(): void
13+
{
14+
$v = new EmbedVideo('https://example.com/video.mp4');
15+
$data = $v->jsonSerialize();
16+
$this->assertSame('https://example.com/video.mp4', $data['url']);
17+
}
18+
19+
public function testConstructorOptionalDimensions(): void
20+
{
21+
$v = new EmbedVideo('https://example.com/video.mp4', 1920, 1080);
22+
$data = $v->jsonSerialize();
23+
$this->assertSame(1920, $data['width']);
24+
$this->assertSame(1080, $data['height']);
25+
}
26+
27+
// jsonSerialize — empty() strips zero integers and empty url
28+
29+
public function testJsonSerializeOmitsZeroWidth(): void
30+
{
31+
$v = new EmbedVideo('https://example.com/video.mp4', 0, 0);
32+
$data = $v->jsonSerialize();
33+
$this->assertArrayNotHasKey('width', $data);
34+
}
35+
36+
public function testJsonSerializeOmitsZeroHeight(): void
37+
{
38+
$v = new EmbedVideo('https://example.com/video.mp4', 0, 0);
39+
$data = $v->jsonSerialize();
40+
$this->assertArrayNotHasKey('height', $data);
41+
}
42+
43+
public function testJsonSerializeOmitsEmptyUrl(): void
44+
{
45+
$v = new EmbedVideo('');
46+
$data = $v->jsonSerialize();
47+
$this->assertArrayNotHasKey('url', $data);
48+
}
49+
50+
public function testJsonSerializeIncludesNonZeroDimensions(): void
51+
{
52+
$v = new EmbedVideo('https://example.com/video.mp4', 640, 360);
53+
$data = $v->jsonSerialize();
54+
$this->assertArrayHasKey('width', $data);
55+
$this->assertArrayHasKey('height', $data);
56+
}
57+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?php
2+
3+
namespace BNETDocs\Tests\Libraries\EventLog;
4+
5+
use \BNETDocs\Libraries\EventLog\EventType;
6+
use \BNETDocs\Libraries\EventLog\EventTypes;
7+
use \PHPUnit\Framework\TestCase;
8+
use \UnexpectedValueException;
9+
10+
class EventTypeTest extends TestCase
11+
{
12+
// color() — representative cases for each color bucket
13+
14+
public function testColorBlueForBlizzardVisit(): void
15+
{
16+
$this->assertSame(0x5865F2, EventType::color(EventTypes::BLIZZARD_VISIT));
17+
}
18+
19+
public function testColorGrayForLogNote(): void
20+
{
21+
$this->assertSame(0x99AAB5, EventType::color(EventTypes::LOG_NOTE));
22+
}
23+
24+
public function testColorGrayForSlackUnfurl(): void
25+
{
26+
$this->assertSame(0x99AAB5, EventType::color(EventTypes::SLACK_UNFURL));
27+
}
28+
29+
public function testColorGreenForUserCreated(): void
30+
{
31+
$this->assertSame(0x57F287, EventType::color(EventTypes::USER_CREATED));
32+
}
33+
34+
public function testColorGreenForDocumentCreated(): void
35+
{
36+
$this->assertSame(0x57F287, EventType::color(EventTypes::DOCUMENT_CREATED));
37+
}
38+
39+
public function testColorGreenForServerCreated(): void
40+
{
41+
$this->assertSame(0x57F287, EventType::color(EventTypes::SERVER_CREATED));
42+
}
43+
44+
public function testColorRedForUserDeleted(): void
45+
{
46+
$this->assertSame(0xED4245, EventType::color(EventTypes::USER_DELETED));
47+
}
48+
49+
public function testColorRedForUserLogout(): void
50+
{
51+
$this->assertSame(0xED4245, EventType::color(EventTypes::USER_LOGOUT));
52+
}
53+
54+
public function testColorRedForPacketDeleted(): void
55+
{
56+
$this->assertSame(0xED4245, EventType::color(EventTypes::PACKET_DELETED));
57+
}
58+
59+
public function testColorYellowForUserEdited(): void
60+
{
61+
$this->assertSame(0xFEE75C, EventType::color(EventTypes::USER_EDITED));
62+
}
63+
64+
public function testColorYellowForDocumentEdited(): void
65+
{
66+
$this->assertSame(0xFEE75C, EventType::color(EventTypes::DOCUMENT_EDITED));
67+
}
68+
69+
public function testColorYellowForServerEdited(): void
70+
{
71+
$this->assertSame(0xFEE75C, EventType::color(EventTypes::SERVER_EDITED));
72+
}
73+
74+
public function testColorDefaultsToGrayForUnknownId(): void
75+
{
76+
$this->assertSame(0x99AAB5, EventType::color(99999));
77+
}
78+
79+
// __toString() — representative cases across all categories
80+
81+
public function testToStringLogNote(): void
82+
{
83+
$e = new EventType(EventTypes::LOG_NOTE);
84+
$this->assertSame('Log Note', (string) $e);
85+
}
86+
87+
public function testToStringSiteDeploy(): void
88+
{
89+
$e = new EventType(EventTypes::SITE_DEPLOY);
90+
$this->assertSame('Site Deploy', (string) $e);
91+
}
92+
93+
public function testToStringUserCreated(): void
94+
{
95+
$e = new EventType(EventTypes::USER_CREATED);
96+
$this->assertSame('User Created', (string) $e);
97+
}
98+
99+
public function testToStringUserLogin(): void
100+
{
101+
$e = new EventType(EventTypes::USER_LOGIN);
102+
$this->assertSame('User Login', (string) $e);
103+
}
104+
105+
public function testToStringUserLogout(): void
106+
{
107+
$e = new EventType(EventTypes::USER_LOGOUT);
108+
$this->assertSame('User Logout', (string) $e);
109+
}
110+
111+
public function testToStringNewsCreated(): void
112+
{
113+
$e = new EventType(EventTypes::NEWS_CREATED);
114+
$this->assertSame('News Post Created', (string) $e);
115+
}
116+
117+
public function testToStringPacketEdited(): void
118+
{
119+
$e = new EventType(EventTypes::PACKET_EDITED);
120+
$this->assertSame('Packet Edited', (string) $e);
121+
}
122+
123+
public function testToStringDocumentDeleted(): void
124+
{
125+
$e = new EventType(EventTypes::DOCUMENT_DELETED);
126+
$this->assertSame('Document Deleted', (string) $e);
127+
}
128+
129+
public function testToStringCommentCreatedOnPacket(): void
130+
{
131+
$e = new EventType(EventTypes::COMMENT_CREATED_PACKET);
132+
$this->assertSame('Comment Created on Packet', (string) $e);
133+
}
134+
135+
public function testToStringCommentEditedOnDocument(): void
136+
{
137+
$e = new EventType(EventTypes::COMMENT_EDITED_DOCUMENT);
138+
$this->assertSame('Comment Edited on Document', (string) $e);
139+
}
140+
141+
public function testToStringCommentDeletedOnServer(): void
142+
{
143+
$e = new EventType(EventTypes::COMMENT_DELETED_SERVER);
144+
$this->assertSame('Comment Deleted on Server', (string) $e);
145+
}
146+
147+
public function testToStringServerCreated(): void
148+
{
149+
$e = new EventType(EventTypes::SERVER_CREATED);
150+
$this->assertSame('Server Created', (string) $e);
151+
}
152+
153+
public function testToStringSlackUnfurl(): void
154+
{
155+
$e = new EventType(EventTypes::SLACK_UNFURL);
156+
$this->assertSame('Slack Unfurl', (string) $e);
157+
}
158+
159+
public function testToStringUnknownIdThrows(): void
160+
{
161+
$this->expectException(UnexpectedValueException::class);
162+
$e = new EventType(99999);
163+
(string) $e;
164+
}
165+
}

0 commit comments

Comments
 (0)