diff --git a/src/Controllers/LaravelResourceController.php b/src/Controllers/LaravelResourceController.php index 9624fd6..10bd78a 100644 --- a/src/Controllers/LaravelResourceController.php +++ b/src/Controllers/LaravelResourceController.php @@ -16,7 +16,9 @@ final class LaravelResourceController */ public function __invoke(Request $request) { - ob_end_clean(); + if (ini_get('output_buffering')) { + ob_clean(); + } $data = $request->only([ 'content', diff --git a/src/Enums/Format.php b/src/Enums/Format.php index cebbed1..b430480 100644 --- a/src/Enums/Format.php +++ b/src/Enums/Format.php @@ -30,7 +30,7 @@ final class Format extends Enum public const MMS = MmsFormat::class; public const PHONE_FORMAT = PhoneFormat::class; public const SNS_FORMAT = SmsFormat::class; - public const VCARD = VCardFormat::class; + public const V_CARD = VCardFormat::class; public const WIFI = WifiFormat::class; public const YOUTUBE = YoutubeFormat::class; } diff --git a/tests/unit/LaravelQrCodeFactoryTest.php b/tests/unit/LaravelQrCodeFactoryTest.php index 2208222..1a22812 100644 --- a/tests/unit/LaravelQrCodeFactoryTest.php +++ b/tests/unit/LaravelQrCodeFactoryTest.php @@ -1,6 +1,7 @@ assertEquals($qrCode->getText(), $content); + } + + public function testFactoryFormatBookMark() + { + $content = [ + 'title' => '2am. Technologies', + 'url' => 'https://2am.tech', + ]; + + $qrCode = LaravelQrCodeFactory::make( + $content, + Format::BOOK_MARK + ); + + $this->assertTrue( + str_contains($qrCode->getText(), 'MEBKM:TITLE:') + && str_contains($qrCode->getText(), ';URL:') + ); + } + + public function testFactoryFormatBtc() + { + $content = [ + 'name' => '2am. Technologies', + 'amount' => 1, + 'message' => 'unt test', + ]; + + $qrCode = LaravelQrCodeFactory::make( + $content, + Format::BTC + ); + + $this->assertTrue(str_contains($qrCode->getText(), 'bitcoin:')); + } + + public function testFactoryFormatGeo() + { + $content = [ + 'lat' => 100, + 'lng' => 100, + 'altitude' => 1, + ]; + + $qrCode = LaravelQrCodeFactory::make( + $content, + Format::GEO + ); + + $this->assertTrue(str_contains($qrCode->getText(), 'GEO:')); + } + + public function testFactoryFormatICal() + { + $content = [ + 'summary' => 'unit test', + 'startTimestamp' => 1702451054, + 'endTimestamp' => 1702454654, + ]; + + $qrCode = LaravelQrCodeFactory::make( + $content, + Format::I_CAL + ); + $content = $qrCode->getText(); + + $this->assertTrue( + str_contains($content, 'BEGIN:VEVENT') + && str_contains($content, 'SUMMARY:') + && str_contains($content, 'DTSTART:') + && str_contains($content, 'DTEND:') + && str_contains($content, 'END:VEVENT') + ); + } + + public function testFactoryFormatMailMessage() + { + $content = [ + 'subject' => 'unit test', + 'body' => 'unit test body', + 'email' => 'testing@2am.tech', + ]; + + $qrCode = LaravelQrCodeFactory::make( + $content, + Format::MAIL_MESSAGE + ); + $content = $qrCode->getText(); + + $this->assertTrue( + str_contains($content, 'MATMSG:TO:') + && str_contains($content, 'SUB:') + && str_contains($content, 'BODY:') + ); + } + + public function testFactoryFormatMailTo() + { + $content = [ + 'email' => 'testing@2am.tech', + ]; + + $qrCode = LaravelQrCodeFactory::make( + $content, + Format::MAIL_TO + ); + $content = $qrCode->getText(); + + $this->assertTrue(str_contains($content, 'MAILTO:')); + } + + public function testFactoryFormatMeCard() + { + $content = [ + 'firstName' => 'unit', + 'lastName' => 'testing', + 'nickName' => 'unit testing', + 'address' => 'saint monica st', + 'phone' => '1 1111 221', + 'videoPhone' => '1 111 121', + 'birthday' => '05/11/1990', + 'note' => '', + 'email' => 'testing@2am.tech', + ]; + + $qrCode = LaravelQrCodeFactory::make( + $content, + Format::ME_CARD + ); + $content = $qrCode->getText(); + + $this->assertTrue( + str_contains($content, 'MECARD:') + && str_contains($content, 'N:') + && str_contains($content, 'SOUND:') + && str_contains($content, 'TEL:') + && str_contains($content, 'TEL-AV:') + && str_contains($content, 'EMAIL:') + && str_contains($content, 'NOTE:') + && str_contains($content, 'BDAY:') + && str_contains($content, 'ADR:') + && str_contains($content, 'URL:') + && str_contains($content, 'NICKNAME:') + ); + } + + public function testFactoryFormatMms() + { + $content = [ + 'msg' => 'unit test', + 'phone' => '1 111 122', + + ]; + + $qrCode = LaravelQrCodeFactory::make( + $content, + Format::MMS + ); + $content = $qrCode->getText(); + + $this->assertTrue(str_contains($content, 'MMSTO:')); + } + + public function testFactoryFormatPhone() + { + $content = [ + 'phone' => '1 111 122', + ]; + + $qrCode = LaravelQrCodeFactory::make( + $content, + Format::PHONE_FORMAT + ); + $content = $qrCode->getText(); + + $this->assertTrue(str_contains($content, 'TEL:')); + } + + public function testFactoryFormatSms() + { + $content = [ + 'phone' => '1 111 122', + ]; + + $qrCode = LaravelQrCodeFactory::make( + $content, + Format::SNS_FORMAT + ); + $content = $qrCode->getText(); + + $this->assertTrue(str_contains($content, 'SMS:')); + } + + public function testFactoryFormatVCard() + { + $content = [ + 'name' => 'testing', + 'fullName' => 'unit testing', + ]; + + $qrCode = LaravelQrCodeFactory::make( + $content, + Format::V_CARD + ); + $content = $qrCode->getText(); + + $this->assertTrue( + str_contains($content, 'BEGIN:VCARD') + && str_contains($content, 'END:VCARD') + ); + } + + public function testFactoryFormatWifi() + { + $content = [ + 'authentication' => 'wpa2', + 'ssid' => 'unit-testing', + 'password' => 'xxxxxxxxxx', + ]; + + $qrCode = LaravelQrCodeFactory::make( + $content, + Format::WIFI + ); + $content = $qrCode->getText(); + + $this->assertTrue( + str_contains($content, 'WIFI:') + && str_contains($content, 'S:') + && str_contains($content, 'P:') + ); + } + + public function testFactoryFormatYoutube() + { + $content = [ + 'videoId' => '123456', + ]; + + $qrCode = LaravelQrCodeFactory::make( + $content, + Format::YOUTUBE + ); + $content = $qrCode->getText(); + + $this->assertTrue( + str_contains($content, 'youtube://') + ); + } + protected function normalizeString($string) { return str_replace(