/** * Tests the notEmpty method when passing a callback * * @return void */ public function testNotEmptyCallback() { $validator = new Validator(); $prevent = true; $validator->notEmpty('title', 'error message', function ($context) use(&$prevent) { $this->assertEquals([], $context['data']); $this->assertEquals([], $context['providers']); $this->assertFalse($context['newRecord']); return $prevent; }); $this->assertFalse($validator->isEmptyAllowed('title', false)); $prevent = false; $this->assertTrue($validator->isEmptyAllowed('title', false)); }
/** * Test interactions between notEmpty() and isAllowed(). * * @return void */ public function testNotEmptyAndIsAllowed() { $validator = new Validator(); $validator->allowEmpty('title')->notEmpty('title', 'Need it', 'update'); $this->assertTrue($validator->isEmptyAllowed('title', true)); $this->assertFalse($validator->isEmptyAllowed('title', false)); $validator->allowEmpty('title')->notEmpty('title'); $this->assertFalse($validator->isEmptyAllowed('title', true)); $this->assertFalse($validator->isEmptyAllowed('title', false)); $validator->notEmpty('title')->allowEmpty('title', 'create'); $this->assertTrue($validator->isEmptyAllowed('title', true)); $this->assertFalse($validator->isEmptyAllowed('title', false)); }