1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
<?php
namespace Faker\Test\Provider;
use Faker\Provider\Company;
use Faker\Provider\Internet;
use Faker\Provider\Lorem;
use Faker\Provider\Person;
use Faker\Test\TestCase;
/**
* @group legacy
*/
final class InternetTest extends TestCase
{
/**
* @dataProvider localeDataProvider
*/
public function testEmailIsValid($locale)
{
$this->loadLocalProviders($locale);
self::assertNotFalse(filter_var($this->faker->email(), FILTER_VALIDATE_EMAIL));
}
/**
* @dataProvider localeDataProvider
*/
public function testUsernameIsValid($locale)
{
$this->loadLocalProviders($locale);
$pattern = '/^[A-Za-z0-9]+([._][A-Za-z0-9]+)*$/';
$username = $this->faker->username();
self::assertMatchesRegularExpression($pattern, $username);
}
/**
* @dataProvider localeDataProvider
*/
public function testDomainnameIsValid($locale)
{
$this->loadLocalProviders($locale);
$pattern = '/^[a-z]+(\.[a-z]+)+$/';
$domainName = $this->faker->domainName();
self::assertMatchesRegularExpression($pattern, $domainName);
}
/**
* @dataProvider localeDataProvider
*/
public function testDomainwordIsValid($locale)
{
$this->loadLocalProviders($locale);
$pattern = '/^[a-z]+$/';
$domainWord = $this->faker->domainWord();
self::assertMatchesRegularExpression($pattern, $domainWord);
}
public function loadLocalProviders($locale)
{
$this->loadLocalProvider($locale, 'Internet');
$this->loadLocalProvider($locale, 'Person');
$this->loadLocalProvider($locale, 'Company');
}
public function testPasswordIsValid()
{
self::assertMatchesRegularExpression('/^.{6}$/', $this->faker->password(6, 6));
}
public function testSlugIsValid()
{
$pattern = '/^[a-z0-9-]+$/';
$slug = $this->faker->slug();
self::assertSame(preg_match($pattern, $slug), 1);
}
public function testSlugWithoutVariableNbWordsProducesValidSlug()
{
$pattern = '/^[a-z0-9-]+$/';
$slug = $this->faker->slug(6, false);
self::assertSame(preg_match($pattern, $slug), 1);
}
public function testSlugWithoutVariableNbWordsProducesCorrectNumberOfNbWords()
{
$slug = $this->faker->slug(3, false);
self::assertCount(3, explode('-', $slug));
}
public function testSlugWithoutNbWordsIsEmpty()
{
$slug = $this->faker->slug(0);
self::assertSame('', $slug);
}
public function testUrlIsValid()
{
self::assertNotFalse(filter_var($this->faker->url(), FILTER_VALIDATE_URL));
}
public function testLocalIpv4()
{
self::assertNotFalse(filter_var($this->faker->localIpv4(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4));
}
public function testIpv4()
{
self::assertNotFalse(filter_var($this->faker->ipv4(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4));
}
public function testIpv4NotLocalNetwork()
{
self::assertDoesNotMatchRegularExpression('/\A0\./', $this->faker->ipv4());
}
public function testIpv4NotBroadcast()
{
self::assertNotEquals('255.255.255.255', $this->faker->ipv4());
}
public function testIpv6()
{
self::assertNotFalse(filter_var($this->faker->ipv6(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV6));
}
public function testMacAddress()
{
self::assertNotFalse(filter_var($this->faker->macAddress(), FILTER_VALIDATE_MAC));
}
protected function getProviders(): iterable
{
yield new Lorem($this->faker);
yield new Person($this->faker);
yield new Internet($this->faker);
yield new Company($this->faker);
}
}
|