diff --git a/ShowPulseBase.php b/ShowPulseBase.php index 1d63e1f..04b20d7 100644 --- a/ShowPulseBase.php +++ b/ShowPulseBase.php @@ -1,6 +1,10 @@ getWebsiteApiKey(); $worker->getFppStatus(); diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..484b3dc --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,23 @@ + + + + + tests + + + + + + . + + + diff --git a/tests/OptFppWwwCommonMock.php b/tests/OptFppWwwCommonMock.php new file mode 100644 index 0000000..4bf8251 --- /dev/null +++ b/tests/OptFppWwwCommonMock.php @@ -0,0 +1,66 @@ + $value) { + $settingsStr .= $key . " = \"" . $value . "\"\n"; + } + file_put_contents($filename, $settingsStr, LOCK_EX); +} + +function ReadSettingFromFile($settingName, $plugin = "") +{ + global $settingsFile; + global $settings; + $filename = $settingsFile; + + if ($plugin != "") { + $filename = "test" . "/plugin." . $plugin; + // $filename = $settings["configDirectory"] . "/plugin." . $plugin; + } + if (!file_exists($filename)) { + return false; + } + $fd = @fopen($filename, "r"); + $settingsStr = ""; + if ($fd) { + flock($fd, LOCK_SH); + $settingsStr = file_get_contents($filename); + flock($fd, LOCK_UN); + fclose($fd); + } + if (!empty($settingsStr)) { + if (preg_match("/^" . $settingName . "/m", $settingsStr)) { + $result = preg_match("/^" . $settingName . "\s*=(\s*\S*\w*)/m", $settingsStr, $output_array); + if ($result == 0) { + // error_log("The setting " . $settingName . " could not be found in " . $filename); + return false; + } + return trim($output_array[1], " \t\n\r\0\x0B\""); + } else { + // error_log("The setting " . $settingName . " could not be found in " . $filename); + return false; + } + } else { + error_log("The setting file:" . $filename . " could not be found."); + return false; + } +} + +function GetDirSetting($dir) +{ + return ""; +} \ No newline at end of file diff --git a/tests/ShowPulseSettingFormTest.php b/tests/ShowPulseSettingFormTest.php deleted file mode 100644 index b69d648..0000000 --- a/tests/ShowPulseSettingFormTest.php +++ /dev/null @@ -1,6 +0,0 @@ -assignMedia("Testing Title", "Demo Artist"); + $dto = new StatusDto(4, "test.fseq", "playing"); + $this->assertEquals("test.fseq", $dto->sequence); + } + + public function testConstructorWithSpecialCharacterSequence() + { + $dto = new StatusDto(0, 'test-flight_rainbow.fseq', 'playing'); + + $this->assertEquals('test-flight rainbow', $dto->song_title); + $this->assertEquals('test-flight_rainbow.fseq', $dto->sequence); + } + public function testConstructorWithErrors() + { + $dto = new StatusDto(5, 'testing.fseq', 'idle'); + + $this->assertEquals(5, $dto->warnings); + $this->assertNotEquals(10, $dto->warnings); + } + + public function testAssignMediaWithTitleAndArtist() + { + $dto = new StatusDto(0, "test.fseq", "playing"); + $dto->assignMedia("Foo", "Bar"); + + $this->assertEquals("Foo", $dto->song_title); + $this->assertEquals("Bar", $dto->song_artist); + } + + public function testAssignMediaWithTitleAndNoArtist() + { + $dto = new StatusDto(0, "test.fseq", "playing"); + + $dto->assignMedia("Foo"); + + $this->assertEquals("Foo", $dto->song_title); + $this->assertEquals(null, $dto->song_artist); + } + + public function testAssignMediaWithNoTitleNorArtist() + { + $dto = new StatusDto(0, "test.fseq", "playing"); + $this->assertEquals("test", $dto->song_title); } } \ No newline at end of file