diff --git a/.phpunit.cache/test-results b/.phpunit.cache/test-results new file mode 100644 index 0000000..a620c2a --- /dev/null +++ b/.phpunit.cache/test-results @@ -0,0 +1 @@ +{"version":1,"defects":{"TelegramTest::testSendMessageReturnsArrayOnSuccess":8,"TelegramTest::testSendMessageReturnsFalseOnFailure":8},"times":[]} \ No newline at end of file diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 0000000..8b6de9c --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +{"version":1,"defects":{"TelegramTest::testSendMessageReturnsArrayOnSuccess":8,"TelegramTest::testSendMessageReturnsFalseOnFailure":8,"DatabaseTest::testConnection":8,"DatabaseTest::testQuery":8,"DJTest::testLoadFromId":8,"DJTest::testLoadFromSlug":8},"times":{"TelegramTest::testSendMessageReturnsArrayOnSuccess":0.001,"TelegramTest::testSendMessageReturnsFalseOnFailure":0.001,"DatabaseTest::testConnection":0.007,"DatabaseTest::testQuery":0.002,"DJTest::testLoadFromId":0.001,"DJTest::testLoadFromSlug":0.001}} \ No newline at end of file diff --git a/classes/CustomCDN.php b/classes/CustomCDN.php index 152f937..52ed71f 100644 --- a/classes/CustomCDN.php +++ b/classes/CustomCDN.php @@ -1,5 +1,7 @@ updated = $dj['lastupdated']; } - $this->load_dj_mixes(); + $this->load_dj_mixes(); return true; } else { @@ -136,6 +138,22 @@ class DJ } } + private function load_dj_mixes(): void + { + $stmt = $this->db->prepare("SELECT * FROM mix WHERE dj1 = ? OR dj2 = ? OR dj3 = ?"); + $stmt->bind_param("iii", $this->id, $this->id, $this->id); + $stmt->execute(); + $result = $stmt->get_result(); + $mixes = []; + while ($mix = $result->fetch_assoc()) { + $mixes[] = $mix; + } + $stmt->close(); + $this->mixes = $mixes; + + + } + private function load_from_slug(): bool { $socials = []; @@ -209,22 +227,6 @@ class DJ return $this->claimed; } - private function load_dj_mixes(): void - { - $stmt = $this->db->prepare("SELECT * FROM mix WHERE dj1 = ? OR dj2 = ? OR dj3 = ?"); - $stmt->bind_param("iii", $this->id, $this->id, $this->id); - $stmt->execute(); - $result = $stmt->get_result(); - $mixes = []; - while ($mix = $result->fetch_assoc()) { - $mixes[] = $mix; - } - $stmt->close(); - $this->mixes = $mixes; - - - } - public function get_dj_mixes() { return $this->mixes; diff --git a/classes/DJs.php b/classes/DJs.php index 636238e..f5aabe9 100644 --- a/classes/DJs.php +++ b/classes/DJs.php @@ -1,5 +1,6 @@ 8.5.1.0" + }, + "autoload": { + "psr-4": { + "DJMixHosting\\": "classes/" + } } } \ No newline at end of file diff --git a/contact.php b/contact.php index cb07d74..ea161dd 100644 --- a/contact.php +++ b/contact.php @@ -1,6 +1,8 @@ "; +// Dump the autoload class map +print_r(Composer\Autoload\ClassLoader::getRegisteredLoaders()); +echo ""; \ No newline at end of file diff --git a/dj.php b/dj.php index 9e0b6c0..256e914 100644 --- a/dj.php +++ b/dj.php @@ -1,10 +1,12 @@ @@ -29,30 +37,30 @@ require_once 'includes/header.php'; ?> -
-
-
-
-
-
-
-
-
- - -
-
- - -
- -
+
+
+
+
+
+
+
+
+
+ + +
+
+ + +
+ +
+
-
-
+ \ No newline at end of file diff --git a/mix.php b/mix.php index ae39f25..dd74ec3 100644 --- a/mix.php +++ b/mix.php @@ -1,9 +1,12 @@ -
-
-
-
- +
+
+
+
+ +
-
- get_nonzero_mixshows(); - $count = 0; - foreach ($mixshows as $mixshow) { - card_output($count, $mixshow, $locale); - echo '' . $locale['view'] . ''; - echo '
'; - echo '
'; - echo '
'; - if ($count % 4 == 3) { + $mixshows = $mixshows->get_nonzero_mixshows(); + $count = 0; + foreach ($mixshows as $mixshow) { + card_output($count, $mixshow, $locale); + echo '' . $locale['view'] . ''; echo ''; + echo ''; + echo ''; + if ($count % 4 == 3) { + echo ''; + } + $count++; } - $count++; - } - ?> + ?> - -
+ + \ No newline at end of file diff --git a/tests/DJTest.php b/tests/DJTest.php new file mode 100644 index 0000000..035d837 --- /dev/null +++ b/tests/DJTest.php @@ -0,0 +1,110 @@ +mockDb = $this->createMock(mysqli::class); + $this->mockStmt = $this->createMock(mysqli_stmt::class); + $this->mockResult = $this->createMock(mysqli_result::class); + } + + public function testLoadFromId() + { + $djData = [ + 'id' => 1, + 'name' => 'Test DJ', + 'bio' => 'This is a test bio', + 'slug' => 'test-dj', + 'img' => '/djs/test-dj.png', + 'email' => 'test@example.com', + 'facebook_url' => 'http://facebook.com/testdj', + 'instagram_url' => 'http://instagram.com/testdj', + 'twitter_url' => 'http://twitter.com/testdj', + 'active' => 1, + 'created' => '2021-01-01 00:00:00', + 'lastupdated' => '2021-01-01 00:00:00', + 'claimed_by' => null, + ]; + + // Mock the prepared statement and its behavior + $this->mockStmt->method('bind_param')->willReturn(true); + $this->mockStmt->method('execute')->willReturn(true); + $this->mockStmt->method('get_result')->willReturn($this->mockResult); + $this->mockResult->method('fetch_assoc')->willReturn($djData); + + // Mock the DB connection to return the mock statement + $this->mockDb->method('prepare')->willReturn($this->mockStmt); + + // Instantiate the DJ class with a valid ID and the mocked DB connection + $this->dj = new DJ(1, $this->mockDb); + + // Assertions to verify that the DJ object is correctly built + $this->assertEquals(1, $this->dj->get_id()); + $this->assertEquals('Test DJ', $this->dj->get_name()); + $this->assertEquals('This is a test bio', $this->dj->get_bio()); + $this->assertEquals('test-dj', $this->dj->get_slug()); + $this->assertEquals('https://cdn.utahsdjs.com/test-dj.png', $this->dj->get_img()); + $this->assertEquals('test@example.com', $this->dj->get_email()); + $this->assertTrue($this->dj->get_active()); + $this->assertEquals('2021-01-01 00:00:00', $this->dj->get_created()); + $this->assertEquals('2021-01-01 00:00:00', $this->dj->get_updated()); + $this->assertFalse($this->dj->get_claimed()); + } + + public function testLoadFromSlug() + { + $djData = [ + 'id' => 1, + 'name' => 'Test DJ', + 'bio' => 'This is a test bio', + 'slug' => 'test-dj', + 'img' => '/djs/test-dj.png', + 'email' => 'test@example.com', + 'facebook_url' => 'http://facebook.com/testdj', + 'instagram_url' => 'http://instagram.com/testdj', + 'twitter_url' => 'http://twitter.com/testdj', + 'active' => 1, + 'created' => '2021-01-01 00:00:00', + 'lastupdated' => '2021-01-01 00:00:00', + 'claimed_by' => null, + ]; + + // Mock the prepared statement and its behavior + $this->mockStmt->method('bind_param')->willReturn(true); + $this->mockStmt->method('execute')->willReturn(true); + $this->mockStmt->method('get_result')->willReturn($this->mockResult); + $this->mockResult->method('fetch_assoc')->willReturn($djData); + + // Mock the DB connection to return the mock statement + $this->mockDb->method('prepare')->willReturn($this->mockStmt); + + // Instantiate the DJ class with a valid slug and the mocked DB connection + $this->dj = new DJ('test-dj', $this->mockDb); + + // Assertions to verify that the DJ object is correctly built + $this->assertEquals(1, $this->dj->get_id()); + $this->assertEquals('Test DJ', $this->dj->get_name()); + $this->assertEquals('This is a test bio', $this->dj->get_bio()); + $this->assertEquals('test-dj', $this->dj->get_slug()); + $this->assertEquals('https://cdn.utahsdjs.com/test-dj.png', $this->dj->get_img()); + $this->assertEquals('test@example.com', $this->dj->get_email()); + $this->assertTrue($this->dj->get_active()); + $this->assertEquals('2021-01-01 00:00:00', $this->dj->get_created()); + $this->assertEquals('2021-01-01 00:00:00', $this->dj->get_updated()); + $this->assertFalse($this->dj->get_claimed()); + } +} diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php new file mode 100644 index 0000000..04d6099 --- /dev/null +++ b/tests/DatabaseTest.php @@ -0,0 +1,56 @@ +config = [ + 'database' => [ + 'host' => 'localhost', + 'user' => 'test_user', + 'pass' => 'test_password', + 'db' => 'test_database', + 'port' => 3306 + ] + ]; + } + + public function testConnection() + { + // Create an instance of Database + $db = new Database($this->config); + + // Check if the connection is successfully established + $this->assertInstanceOf(mysqli::class, $db); + $this->assertEquals(0, $db->connect_errno, "Database connection error: " . $db->connect_error); + } + + public function testQuery() + { + // Create an instance of Database + $db = new Database($this->config); + + // Execute a simple query + $result = $db->query('SELECT 1 AS value'); + $this->assertNotFalse($result, "Query failed: " . $db->error); + + $row = $result->fetch_assoc(); + $this->assertEquals(1, $row['value'], "Query did not return the correct value"); + } + + protected function tearDown(): void + { + // Close the database connection if it's still open + if (isset($db) && $db instanceof mysqli) { + $db->close(); + } + } +} diff --git a/tests/TelegramTest.php b/tests/TelegramTest.php new file mode 100644 index 0000000..fbc4fa7 --- /dev/null +++ b/tests/TelegramTest.php @@ -0,0 +1,36 @@ + true, 'result' => 'Message sent']); + $this->telegram->method('sendMessage')->willReturn($expectedResult); + + $result = $this->telegram->send_message('Hello, world!'); + $this->assertIsArray($result); + $this->assertEquals(['ok' => true, 'result' => 'Message sent'], $result); + } + + public function testSendMessageReturnsFalseOnFailure() + { + $this->telegram->method('sendMessage')->willReturn(false); + + $result = $this->telegram->send_message('Hello, world!'); + $this->assertFalse($result); + } + + protected function setUp(): void + { + $this->telegram = $this->getMockBuilder(Telegram::class)->setConstructorArgs([$this->token, $this->chatId])->onlyMethods(['sendMessage'])->getMock(); + } +}