ControllerProviderTest::testShowList PHP Метод

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

public testShowList ( )
    public function testShowList()
    {
        $library = $this->dataLibrary->createEmpty();
        $library->set('name', 'lib a');
        $this->dataLibrary->create($library);
        $entityBook1 = $this->dataBook->createEmpty();
        $entityBook1->set('title', 'titleA');
        $entityBook1->set('author', 'author');
        $entityBook1->set('pages', 111);
        $entityBook1->set('price', 3.99);
        $entityBook1->set('library', $library->get('id'));
        $this->dataBook->create($entityBook1);
        $entityBook1Id = $entityBook1->get('id');
        $entityBook2 = $this->dataBook->createEmpty();
        $entityBook2->set('title', 'titleB');
        $entityBook2->set('author', 'author');
        $entityBook2->set('pages', 111);
        $entityBook2->set('price', 3.99);
        $entityBook2->set('library', $library->get('id'));
        $this->dataBook->create($entityBook2);
        $library->set('libraryBook', [['id' => $entityBook1Id]]);
        $this->dataLibrary->update($library);
        $client = $this->createClient();
        $crawler = $client->request('GET', '/crud/foo');
        $this->assertTrue($client->getResponse()->isNotFound());
        $this->assertCount(1, $crawler->filter('html:contains("Entity not found")'));
        $crawler = $client->request('GET', '/crud/book');
        $this->assertTrue($client->getResponse()->isOk());
        $this->assertCount(1, $crawler->filter('html:contains("lib a")'));
        $this->assertCount(1, $crawler->filter('html:contains("titleA")'));
        $this->assertCount(1, $crawler->filter('html:contains("titleB")'));
        for ($i = 0; $i < 8; ++$i) {
            $entityBookA = $this->dataBook->createEmpty();
            $entityBookA->set('title', 'titleB' . $i);
            $entityBookA->set('author', 'author' . $i);
            $entityBookA->set('pages', 111);
            $entityBookA->set('price', 3.99);
            $entityBookA->set('library', $library->get('id'));
            $this->dataBook->create($entityBookA);
            sleep(1);
        }
        $this->dataBook->getDefinition()->setPageSize(5);
        $crawler = $client->request('GET', '/crud/book');
        $this->assertTrue($client->getResponse()->isOk());
        $this->assertCount(1, $crawler->filter('html:contains("titleA")'));
        $this->assertRegExp('/\\>1\\</', $client->getResponse()->getContent());
        $this->assertRegExp('/\\>2\\</', $client->getResponse()->getContent());
        $this->assertSame(strpos('>3<', $client->getResponse()->getContent()), false);
        $crawler = $client->request('GET', '/crud/book?crudPage=1');
        $this->assertTrue($client->getResponse()->isOk());
        $this->assertCount(1, $crawler->filter('html:contains("titleB3")'));
        $crawler = $client->request('GET', '/crud/book?crudPage=10');
        $this->assertTrue($client->getResponse()->isOk());
        $this->assertCount(1, $crawler->filter('html:contains("titleB3")'));
        $crawler = $client->request('GET', '/crud/book?crudFiltertitle=titleB');
        $this->assertTrue($client->getResponse()->isOk());
        $this->assertCount(1, $crawler->filter('html:contains("titleB")'));
        $this->assertCount(1, $crawler->filter('html:contains("titleB0")'));
        $this->assertCount(1, $crawler->filter('html:contains("titleB1")'));
        $this->assertCount(1, $crawler->filter('html:contains("titleB2")'));
        $this->assertCount(1, $crawler->filter('html:contains("titleB3")'));
        $library = $this->dataLibrary->createEmpty();
        $library->set('name', 'lib b1');
        $library->set('isOpenOnSundays', true);
        $this->dataLibrary->create($library);
        $library = $this->dataLibrary->createEmpty();
        $library->set('name', 'lib b2');
        $library->set('isOpenOnSundays', true);
        $this->dataLibrary->create($library);
        $crawler = $client->request('GET', '/crud/library?crudFilterisOpenOnSundays=true');
        $this->assertTrue($client->getResponse()->isOk());
        $this->assertCount(1, $crawler->filter('html:contains("lib b1")'));
        $this->assertCount(1, $crawler->filter('html:contains("lib b2")'));
        $this->assertCount(0, $crawler->filter('html:contains("lib a")'));
        $crawler = $client->request('GET', '/crud/library?crudFilterlibraryBook[]=' . $entityBook1Id);
        $this->assertTrue($client->getResponse()->isOk());
        $this->assertCount(1, $crawler->filter('html:contains("Total: 1")'));
        $this->assertCount(1, $crawler->filter('html:contains("lib a")'));
        $this->assertCount(0, $crawler->filter('html:contains("lib b1")'));
        $this->assertCount(0, $crawler->filter('html:contains("lib b2")'));
    }