PostValidatorTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Test\Unit;
  3. use Test\TestCase;
  4. use Web3\Validators\PostValidator;
  5. class PostValidatorTest extends TestCase
  6. {
  7. /**
  8. * validator
  9. *
  10. * @var \Web3\Validators\PostValidator
  11. */
  12. protected $validator;
  13. /**
  14. * setUp
  15. *
  16. * @return void
  17. */
  18. public function setUp()
  19. {
  20. parent::setUp();
  21. $this->validator = new PostValidator;
  22. }
  23. /**
  24. * testValidate
  25. *
  26. * @return void
  27. */
  28. public function testValidate()
  29. {
  30. $validator = $this->validator;
  31. $this->assertEquals(false, $validator->validate('hello web3.php'));
  32. $this->assertEquals(false, $validator->validate([]));
  33. $this->assertEquals(false, $validator->validate([
  34. 'from' => 'hello',
  35. ]));
  36. $this->assertEquals(false, $validator->validate([
  37. 'to' => 'hello',
  38. ]));
  39. $this->assertEquals(false, $validator->validate([
  40. 'from' => '0xeb0b54D62ec3f561C2eebdaebd92432126F0817579c102b062d1a6c1f2ed83e8121233',
  41. 'to' => '0xeb0b54D62ec3f561C2eebdaebd92432126F0817579c102b062d1a6c1f2ed83e8121233',
  42. ]));
  43. $this->assertEquals(false, $validator->validate([
  44. 'topics' => [
  45. '0xzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz',
  46. ]
  47. ]));
  48. $this->assertEquals(false, $validator->validate([
  49. 'topics' => [
  50. '0xzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz',
  51. ],
  52. 'payload' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
  53. ]));
  54. $this->assertEquals(false, $validator->validate([
  55. 'topics' => [
  56. '0xzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz',
  57. ],
  58. 'payload' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
  59. 'priority' => '0x1',
  60. ]));
  61. $this->assertEquals(true, $validator->validate([
  62. 'topics' => [
  63. '0xd46e8dd67c5d32be8058bb8eb970870f07244567', '0xd46e8dd67c5d32be8058bb8eb970870f07244567'
  64. ],
  65. 'payload' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
  66. 'priority' => '0x1',
  67. 'ttl' => '0x1',
  68. ]));
  69. $this->assertEquals(true, $validator->validate([
  70. 'from' => '0xeb0b54D62ec3f561C2eebdaebd92432126F0817579c102b062d1a6c1f2ed83e8121233',
  71. 'to' => '0xeb0b54D62ec3f561C2eebdaebd92432126F0817579c102b062d1a6c1f2ed83e8121233',
  72. 'topics' => [
  73. '0xd46e8dd67c5d32be8058bb8eb970870f07244567', '0xd46e8dd67c5d32be8058bb8eb970870f07244567'
  74. ],
  75. 'payload' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
  76. 'priority' => '0x1',
  77. 'ttl' => '0x1',
  78. ]));
  79. }
  80. }