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
|
<?php
namespace Illuminate\Tests\Support;
use Illuminate\Support\MessageBag;
use Illuminate\Support\ViewErrorBag;
use PHPUnit\Framework\TestCase;
class SupportViewErrorBagTest extends TestCase
{
public function testHasBagTrue()
{
$viewErrorBag = new ViewErrorBag;
$viewErrorBag->put('default', new MessageBag(['msg1', 'msg2']));
$this->assertTrue($viewErrorBag->hasBag());
}
public function testHasBagFalse()
{
$viewErrorBag = new ViewErrorBag;
$this->assertFalse($viewErrorBag->hasBag());
}
public function testGet()
{
$messageBag = new MessageBag;
$viewErrorBag = new ViewErrorBag;
$viewErrorBag = $viewErrorBag->put('default', $messageBag);
$this->assertEquals($messageBag, $viewErrorBag->getBag('default'));
}
public function testGetBagWithNew()
{
$viewErrorBag = new ViewErrorBag;
$this->assertInstanceOf(MessageBag::class, $viewErrorBag->getBag('default'));
}
public function testGetBags()
{
$messageBag1 = new MessageBag;
$messageBag2 = new MessageBag;
$viewErrorBag = new ViewErrorBag;
$viewErrorBag->put('default', $messageBag1);
$viewErrorBag->put('default2', $messageBag2);
$this->assertEquals([
'default' => $messageBag1,
'default2' => $messageBag2,
], $viewErrorBag->getBags());
}
public function testPut()
{
$messageBag = new MessageBag;
$viewErrorBag = new ViewErrorBag;
$viewErrorBag = $viewErrorBag->put('default', $messageBag);
$this->assertEquals(['default' => $messageBag], $viewErrorBag->getBags());
}
public function testAnyTrue()
{
$viewErrorBag = new ViewErrorBag;
$viewErrorBag->put('default', new MessageBag(['message']));
$this->assertTrue($viewErrorBag->any());
}
public function testAnyFalse()
{
$viewErrorBag = new ViewErrorBag;
$viewErrorBag->put('default', new MessageBag);
$this->assertFalse($viewErrorBag->any());
}
public function testAnyFalseWithEmptyErrorBag()
{
$viewErrorBag = new ViewErrorBag;
$this->assertFalse($viewErrorBag->any());
}
public function testCount()
{
$viewErrorBag = new ViewErrorBag;
$viewErrorBag->put('default', new MessageBag(['message', 'second']));
$this->assertCount(2, $viewErrorBag);
}
public function testCountWithNoMessagesInMessageBag()
{
$viewErrorBag = new ViewErrorBag;
$viewErrorBag->put('default', new MessageBag);
$this->assertCount(0, $viewErrorBag);
}
public function testCountWithNoMessageBags()
{
$viewErrorBag = new ViewErrorBag;
$this->assertCount(0, $viewErrorBag);
}
public function testDynamicCallToDefaultMessageBag()
{
$viewErrorBag = new ViewErrorBag;
$viewErrorBag->put('default', new MessageBag(['message', 'second']));
$this->assertEquals(['message', 'second'], $viewErrorBag->all());
}
public function testDynamicallyGetBag()
{
$messageBag = new MessageBag;
$viewErrorBag = new ViewErrorBag;
$viewErrorBag = $viewErrorBag->put('default', $messageBag);
$this->assertEquals($messageBag, $viewErrorBag->default);
}
public function testDynamicallyPutBag()
{
$messageBag = new MessageBag;
$viewErrorBag = new ViewErrorBag;
$viewErrorBag->default2 = $messageBag;
$this->assertEquals(['default2' => $messageBag], $viewErrorBag->getBags());
}
public function testToString()
{
$viewErrorBag = new ViewErrorBag;
$viewErrorBag = $viewErrorBag->put('default', new MessageBag(['message' => 'content']));
$this->assertSame('{"message":["content"]}', (string) $viewErrorBag);
}
}
|