ControllerProviderTest::testCreate PHP Метод

testCreate() публичный Метод

public testCreate ( )
    public function testCreate()
    {
        $client = $this->createClient();
        $crawler = $client->request('GET', '/crud/foo/create');
        $this->assertTrue($client->getResponse()->isNotFound());
        $this->assertCount(1, $crawler->filter('html:contains("Entity not found")'));
        $crawler = $client->request('GET', '/crud/book/create');
        $this->assertTrue($client->getResponse()->isOk());
        $this->assertCount(1, $crawler->filter('html:contains("Submit")'));
        $this->assertCount(1, $crawler->filter('html:contains("Author")'));
        $this->assertCount(1, $crawler->filter('html:contains("Pages")'));
        $crawler = $client->request('POST', '/crud/book/create');
        $this->assertTrue($client->getResponse()->isOk());
        $this->assertCount(1, $crawler->filter('html:contains("Could not create, see the red marked fields.")'));
        $this->assertRegExp('/has-error/', $client->getResponse()->getContent());
        $library = $this->dataLibrary->createEmpty();
        $library->set('name', 'lib a');
        $this->dataLibrary->create($library);
        $file = __DIR__ . '/../test1.xml';
        $client->request('POST', '/crud/book/create', ['title' => 'title', 'author' => 'author', 'pages' => 111, 'price' => 3.99, 'library' => $library->get('id'), 'secondLibrary' => ''], ['cover' => new UploadedFile($file, 'test1.xml', 'application/xml', filesize($file), null, true)]);
        $this->assertTrue($client->getResponse()->isRedirect('/crud/book/1'));
        $crawler = $client->followRedirect();
        $this->assertTrue($client->getResponse()->isOk());
        $this->assertCount(1, $crawler->filter('html:contains("Book created with id ")'));
        $books = $this->dataBook->listEntries();
        $this->assertCount(1, $books);
        $this->fileProcessorHandle->createFile->once()->called();
        $this->fileProcessorHandle->updateFile->never()->called();
        $this->fileProcessorHandle->deleteFile->never()->called();
        $this->fileProcessorHandle->renderFile->never()->called();
        // Canceling events
        $before = function (Entity $entity) {
            return false;
        };
        $this->dataBook->pushEvent('before', 'create', $before);
        $client->request('POST', '/crud/book/create', ['title' => 'title', 'author' => 'author', 'pages' => 111, 'price' => 3.99, 'library' => $library->get('id')], ['cover' => new UploadedFile($file, 'test1.xml', 'application/xml', filesize($file), null, true)]);
        $this->assertTrue($client->getResponse()->isOk());
        $this->assertRegExp('/Could not create\\./', $client->getResponse()->getContent());
        $this->dataBook->popEvent('before', 'create');
        $this->dataBook->pushEvent('before', 'createFiles', $before);
        $client->request('POST', '/crud/book/create', ['title' => 'title', 'author' => 'author', 'pages' => 111, 'price' => 3.99, 'library' => $library->get('id')], ['cover' => new UploadedFile($file, 'test1.xml', 'application/xml', filesize($file), null, true)]);
        $this->assertTrue($client->getResponse()->isOk());
        $this->assertRegExp('/Could not create\\./', $client->getResponse()->getContent());
        $this->dataBook->popEvent('before', 'createFiles');
    }