Crud\Test\TestCase\Action\EditActionTest::testActionPostValidationErrors PHP Method

testActionPostValidationErrors() public method

Test POST with validation errors
    public function testActionPostValidationErrors()
    {
        $this->_eventManager->on('Dispatcher.invokeController', ['priority' => 1000], function ($event) {
            $this->_controller->Flash = $this->getMockBuilder('Cake\\Controller\\Component\\FlashComponent')->setMethods(['set'])->disableOriginalConstructor()->getMock();
            $this->_controller->Flash->expects($this->once())->method('set')->with('Could not update blog', ['element' => 'default', 'params' => ['class' => 'message error', 'original' => 'Could not update blog'], 'key' => 'flash']);
            $this->_subscribeToEvents($this->_controller);
            $this->_controller->Blogs->validator()->requirePresence('name')->add('name', ['length' => ['rule' => ['minLength', 10], 'message' => 'Name need to be at least 10 characters long']]);
        });
        $this->put('/blogs/edit/1', ['name' => 'Hello', 'body' => 'Pretty hot body']);
        $this->assertEvents(['beforeFind', 'afterFind', 'beforeSave', 'afterSave', 'setFlash', 'beforeRender']);
        $this->assertFalse($this->_subject->success);
        $this->assertFalse($this->_subject->created);
        $expected = '<div class="error-message">Name need to be at least 10 characters long</div>';
        $this->assertContains($expected, $this->_response->body(), 'Could not find validation error in HTML');
    }