PHP Classes

File: tests/Unit/DataTypes/TextTest.php

Recommend this page to a friend!
  Packages of Amirreza Ebrahimi   HeroQR Powerful PHP QR Code Library to generate PNG, SVG, PDF, Logos Ready to Use with Laravel   tests/Unit/DataTypes/TextTest.php   Download  
File: tests/Unit/DataTypes/TextTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: HeroQR Powerful PHP QR Code Library to generate PNG, SVG, PDF, Logos Ready to Use with Laravel
Generate QR code images in several formats
Author: By
Last change: Update of tests/Unit/DataTypes/TextTest.php
Date: 6 months ago
Size: 1,177 bytes
 

Contents

Class file image Download
<?php

namespace HeroQR\Tests\Unit\DataTypes;

use
HeroQR\DataTypes\Text;
use
PHPUnit\Framework\{Attributes\DataProvider, Attributes\Test, TestCase};

/**
 * Class TextTest
 * Tests the Text class.
 */
class TextTest extends TestCase
{
   
/**
     * Test validating text with various inputs
     */
    #[Test]
    #[DataProvider('textProvider')]
   
public function validateText(string $text, bool $expected): void
   
{
       
$this->assertSame($expected, Text::validate($text), 'Text validation failed for: ' . $text);
    }

   
/**
     * Provides a list of text inputs and expected validation result
     */
   
public static function textProvider(): array
    {
        return [
           
'Valid text without unsafe content' => ['Example Test | ??? ???', true],
           
'Text with script tag (XSS attack)' => ["<script>alert('XSS');</script>", false],
           
'Text with SQL injection patterns' => ['SELECT * FROM users WHERE id = 1; --', false],
           
'Text with both script tag and SQL injection' => ["<script>alert('XSS');</script>SELECT * FROM users WHERE id = 1; --", false],
        ];
    }
}