Permalink
Browse files

Added functional tests

  • Loading branch information...
1 parent 3913e91 commit bdc5e397cf35241cdbf2b08f143c61c64a024144 @mgiagnoni committed Mar 10, 2012
View
@@ -2,3 +2,6 @@ phpunit.xml
vendor
composer.phar
composer.lock
+Tests/autoload.php
+Tests/Functional/App/cache
+Tests/Functional/App/logs
@@ -0,0 +1,112 @@
+<?php
+
+/*
+ * This file is part of the LyraAdminBundle package.
+ *
+ * Copyright 2011 Massimo Giagnoni <gimassimo@gmail.com>
+ *
+ * This source file is subject to the MIT license. Full copyright and license
+ * information are in the LICENSE file distributed with this source code.
+ */
+
+namespace Lyra\AdminBundle\Tests\Fixture\Bundle\Product\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+use Doctrine\Common\Collections\ArrayCollection;
+
+/**
+ * Lyra\AdminBundle\Tests\Fixture\Bundle\Product\Entity\Product
+ *
+ * @ORM\Table()
+ * @ORM\Entity()
+ */
+class Product
+{
+ /**
+ * @var integer $id
+ *
+ * @ORM\Column(name="id", type="integer")
+ * @ORM\Id
+ * @ORM\GeneratedValue(strategy="AUTO")
+ */
+ private $id;
+
+ /**
+ * @var string $name
+ *
+ * @ORM\Column(name="name", type="string", length=255)
+ */
+ private $name;
+
+ /**
+ * @var float $price
+ *
+ * @ORM\Column(name="price", type="float")
+ */
+ private $price;
+
+ /**
+ * @ORM\Column(name="description", type="text", nullable=true)
+ */
+ private $description;
+
+ /**
+ * Get id
+ *
+ * @return integer
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * Set name
+ *
+ * @param string $name
+ */
+ public function setName($name)
+ {
+ $this->name = $name;
+ }
+
+ /**
+ * Get name
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * Set price
+ *
+ * @param float $price
+ */
+ public function setPrice($price)
+ {
+ $this->price = $price;
+ }
+
+ /**
+ * Get price
+ *
+ * @return float
+ */
+ public function getPrice()
+ {
+ return $this->price;
+ }
+
+ public function getDescription()
+ {
+ return $this->description;
+ }
+
+ public function setDescription($description)
+ {
+ $this->description = $description;
+ }
+}
@@ -0,0 +1,18 @@
+<?php
+
+/*
+ * This file is part of the LyraAdminBundle package.
+ *
+ * Copyright 2011 Massimo Giagnoni <gimassimo@gmail.com>
+ *
+ * This source file is subject to the MIT license. Full copyright and license
+ * information are in the LICENSE file distributed with this source code.
+ */
+
+namespace Lyra\AdminBundle\Tests\Fixture\Bundle\Product;
+
+use Symfony\Component\HttpKernel\Bundle\Bundle;
+
+class ProductBundle extends Bundle
+{
+}
@@ -0,0 +1,89 @@
+<?php
+
+/*
+ * This file is part of the LyraAdminBundle package.
+ *
+ * Copyright 2011 Massimo Giagnoni <gimassimo@gmail.com>
+ *
+ * This source file is subject to the MIT license. Full copyright and license
+ * information are in the LICENSE file distributed with this source code.
+ */
+
+namespace Lyra\AdminBundle\Tests\Functional;
+
+use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
+
+class AdminControllerTest extends WebTestCase
+{
+ public function testIndex()
+ {
+ $client = static::createClient();
+ $container = $client->getContainer();
+ $manager = $container->get('lyra_admin.product.model_manager');
+
+ // Empty list
+ $crawler = $client->request('GET', '/admin/product/list');
+ $this->assertTrue($crawler->filter('td.no-records')->count() == 1);
+
+ // Add records
+ $product = $manager->create();
+ $product->setName('test');
+ $product->setDescription('description');
+ $product->setPrice('3.576');
+ $manager->save($product);
+
+ $product = $manager->create();
+ $product->setName('test2');
+ $product->setDescription('description2');
+ $product->setPrice('1.23');
+ $manager->save($product);
+
+ $crawler = $client->reload();
+
+ // List headers
+ $attrs = $crawler->filter('table.ly-list th')->extract('class');
+ // $attrs[0] is batch select box
+ $this->assertEquals('sorted-asc col-name string', $attrs[1]);
+ $this->assertEquals('col-description text', $attrs[2]);
+ $this->assertEquals('sortable col-price float', $attrs[3]);
+
+ // Sort links
+ $this->assertTrue($crawler->filter('table.ly-list th.col-description a')->count() == 0);
+ $href = $crawler->filter('table.ly-list th.col-name a')->attr('href');
+ $this->assertRegexp('#name\/desc#', $href);
+ $href = $crawler->filter('table.ly-list th.col-price a')->attr('href');
+ $this->assertRegexp('#price\/asc#', $href);
+
+ // Check order
+ $values = $crawler->filter('table.ly-list tbody tr')->children()->extract('_text');
+ $this->assertEquals('test', trim($values[1]));
+
+ // Sort list by price
+ $link = $crawler->selectLink('Price')->link();
+ $crawler = $client->click($link);
+
+ // List headers
+ $attrs = $crawler->filter('table.ly-list th')->extract('class');
+ // Column name
+ $this->assertRegexp('#sortable#', $attrs[1]);
+ // Column price
+ $this->assertRegexp('#sorted-asc#', $attrs[3]);
+
+ // Check order
+ $values = $crawler->filter('table.ly-list tbody tr')->children()->extract('_text');
+ $this->assertEquals('test2', trim($values[1]));
+ }
+
+ protected function setup()
+ {
+ $client = static::createClient();
+ $container = $client->getContainer();
+ $em = $container->get('doctrine')->getEntityManager();
+ $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
+ $schemaTool->dropDatabase('lyra_test');
+ $metadatas = $em->getMetadataFactory()->getAllMetadata();
+ if (!empty($metadatas)) {
+ $schemaTool->createSchema($metadatas);
+ }
+ }
+}
@@ -0,0 +1,37 @@
+<?php
+
+/*
+ * This file is part of the LyraAdminBundle package.
+ *
+ * Copyright 2011 Massimo Giagnoni <gimassimo@gmail.com>
+ *
+ * This source file is subject to the MIT license. Full copyright and license
+ * information are in the LICENSE file distributed with this source code.
+ */
+
+use Symfony\Component\HttpKernel\Kernel;
+use Symfony\Component\Config\Loader\LoaderInterface;
+
+class AppKernel extends Kernel
+{
+ public function registerBundles()
+ {
+ $bundles = array(
+ new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
+ new Symfony\Bundle\SecurityBundle\SecurityBundle(),
+ new Symfony\Bundle\TwigBundle\TwigBundle(),
+ new Symfony\Bundle\DoctrineBundle\DoctrineBundle(),
+ new Lyra\AdminBundle\LyraAdminBundle(),
+
+ // dummy bundle for tests
+ new Lyra\AdminBundle\Tests\Fixture\Bundle\Product\ProductBundle(),
+ );
+
+ return $bundles;
+ }
+
+ public function registerContainerConfiguration(LoaderInterface $loader)
+ {
+ $loader->load(__DIR__.'/config.yml');
+ }
+}
@@ -0,0 +1,47 @@
+imports:
+ - { resource: security.yml }
+
+framework:
+ secret: secret
+ charset: UTF-8
+ test: ~
+ router: { resource: "%kernel.root_dir%/routing.yml" }
+ form: true
+ csrf_protection: true
+ validation: { enable_annotations: true }
+ templating: { engines: ['twig'] }
+ session:
+ auto_start: false
+ storage_id: session.storage.filesystem
+
+doctrine:
+ dbal:
+ driver: pdo_mysql
+ host: localhost
+ dbname: lyra_test
+ user: lyra_test
+ password: lyra
+ charset: UTF8
+
+ orm:
+ auto_generate_proxy_classes: %kernel.debug%
+ #auto_mapping: true
+ entity_managers:
+ default:
+ mappings:
+ ProductBundle: {type: annotation}
+
+lyra_admin:
+ models:
+ product:
+ class: Lyra\AdminBundle\Tests\Fixture\Bundle\Product\Entity\Product
+ list:
+ default_sort:
+ column: name
+ columns:
+ name: ~
+ description:
+ sortable: false
+ price:
+ format: '%.2f'
+
@@ -0,0 +1,2 @@
+LyraAdminBundle:
+ resource: "@LyraAdminBundle/Resources/config/routing.yml"
@@ -0,0 +1,13 @@
+security:
+ firewalls:
+ test:
+ pattern: ^/
+ anonymous: ~
+ http_basic:
+ realm: "Secured Area"
+ providers:
+ in_memory:
+ users:
+ admin: { password: admin, roles: 'ROLE_ADMIN' }
+ encoders:
+ Symfony\Component\Security\Core\User\User: plaintext
View
@@ -2,6 +2,7 @@
<phpunit bootstrap="./Tests/bootstrap.php" color="true">
<php>
<!-- <server name="SYMFONY" value="/path/to/symfony" /> -->
+ <server name="KERNEL_DIR" value="Tests/Functional/App" />
</php>
<testsuites>
<testsuite name="LyraAdminBundle Test Suite">

0 comments on commit bdc5e39

Please sign in to comment.