diff --git a/.gitignore b/.gitignore index 6730d3983..2ac02e93b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ +composer.phar phpunit.xml Tests/autoload.php - -vendor/* +Tests/Functional/app/Behat/nginx.conf +Tests/Functional/web/bundles +vendor diff --git a/.travis.yml b/.travis.yml index bf65d2cca..9330f48f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,19 @@ php: - 5.4 before_script: - - curl -s http://getcomposer.org/installer | php - - php composer.phar install --install-suggests --quiet + - export DISPLAY=:99.0 && sh -e /etc/init.d/xvfb start + - wget --quiet -O sahi.zip http://sourceforge.net/projects/sahi/files/sahi-v35/20110719/sahi_20110719.zip/download && unzip -qq sahi.zip + - export SAHI_HOME=sahi && sh sahi/bin/sahi.sh > /dev/null & + - curl --silent http://getcomposer.org/installer | php > /dev/null && php composer.phar install --install-suggests --quiet + - sudo apt-get -qq install nginx > /dev/null 2>&1 + - nginx -v && sudo nginx -c app/Behat/nginx.conf.dist -p ./Tests/Functional + - for file in `find /home/vagrant/.phpenv -name 'xdebug.ini'`; do echo "xdebug.max_nesting_level=200" >> $file; done; + - php-cgi -b 127.0.0.1:9000 & + - ./Tests/Functional/app/console assets:install --symlink Tests/Functional/web > /dev/null && ./Tests/Functional/app/console doctrine:database:drop --force > /dev/null && ./Tests/Functional/app/console doctrine:database:create > /dev/null && ./Tests/Functional/app/console doctrine:schema:create + +script: ./run_tests.sh notifications: email: - friendsofsymfony-dev@googlegroups.com - - tim+build@nagel.com.au \ No newline at end of file + - tim+build@nagel.com.au diff --git a/EventListener/ThreadPermalinkListener.php b/EventListener/ThreadPermalinkListener.php index 3d93b9928..0b71d2fd2 100644 --- a/EventListener/ThreadPermalinkListener.php +++ b/EventListener/ThreadPermalinkListener.php @@ -15,8 +15,8 @@ use FOS\CommentBundle\Event\ThreadEvent; use FOS\CommentBundle\Model\ThreadInterface; use FOS\CommentBundle\Model\ThreadManagerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpFoundation\Request; /** * Responsible for setting a permalink for each new Thread object. @@ -26,18 +26,18 @@ class ThreadPermalinkListener implements EventSubscriberInterface { /** - * @var Request + * @var ContainerInterface */ - protected $request; + protected $container; /** * Constructor. * - * @param Request $request + * @param ContainerInterface $container */ - public function __construct(Request $request) + public function __construct(ContainerInterface $container) { - $this->request = $request; + $this->container = $container; } /** @@ -47,8 +47,12 @@ public function __construct(Request $request) */ public function onThreadCreate(ThreadEvent $event) { + if (!$this->container->isScopeActive('request')) { + return; + } + $thread = $event->getThread(); - $thread->setPermalink($this->request->getUri()); + $thread->setPermalink($this->container->get('request')->getUri()); } static public function getSubscribedEvents() diff --git a/Features/Context/FeatureContext.php b/Features/Context/FeatureContext.php new file mode 100644 index 000000000..774328bbd --- /dev/null +++ b/Features/Context/FeatureContext.php @@ -0,0 +1,36 @@ +getThreadManager()->findThreadById($id); + if (!$thread) { + $thread = $this->getThreadManager()->createThread($id); + } + + $thread->setPermalink($link); + + $this->getThreadManager()->saveThread($thread); + } + + /** + * @return \FOS\CommentBundle\Model\ThreadManagerInterface + */ + private function getThreadManager() + { + return $this->getContainer()->get('fos_comment.manager.thread'); + } +} \ No newline at end of file diff --git a/Features/EmbedThread.feature b/Features/EmbedThread.feature new file mode 100644 index 000000000..14236bef8 --- /dev/null +++ b/Features/EmbedThread.feature @@ -0,0 +1,20 @@ +Feature: Embed a thread on a page + +Background: + Given I have a thread identified by "test" with a link of "test" + +Scenario: Embed a thread inline + When I go to "inline/test" + Then I should see a "#fos_comment_thread[data-thread=test]" element + +@javascript +Scenario: Embed a thread async + When I go to "async/test" + Then I should see a "#fos_comment_thread[data-thread=test]" element + +@javascript +Scenario: Reply to a thread + When I go to "async/test" + And I fill in "fos_comment_comment_body" with "I am replying to a comment" + And I press "fos_comment_comment_new_submit" + Then I should see "I am replying to a comment" in the ".fos_comment_comment_body" element \ No newline at end of file diff --git a/Resources/assets/js/comments.js b/Resources/assets/js/comments.js index 14d544394..4128ffd9e 100644 --- a/Resources/assets/js/comments.js +++ b/Resources/assets/js/comments.js @@ -96,6 +96,7 @@ {permalink: encodeURIComponent(permalink)}, function(data) { FOS_COMMENT.thread_container.html(data); + FOS_COMMENT.thread_container.attr('data-thread', identifier); } ); }, diff --git a/Resources/config/events.xml b/Resources/config/events.xml index 69a543703..c97c9f721 100644 --- a/Resources/config/events.xml +++ b/Resources/config/events.xml @@ -24,8 +24,8 @@ - - + + diff --git a/Resources/doc/11-running_the_test_suite.md b/Resources/doc/11-running_the_test_suite.md index 5710071d2..06b71a853 100644 --- a/Resources/doc/11-running_the_test_suite.md +++ b/Resources/doc/11-running_the_test_suite.md @@ -25,8 +25,8 @@ Functional tests have more dependencies. * vendors set up by [Composer](http://getcomposer.org) * `php composer.phar install --install-suggests` - * [Node.js](http://nodejs.org/) - * [Zombie.js](https://github.com/assaf/zombie) + * Sahi + * A browser supported by Sahi (headless or otherwise) * A webserver with ability to parse PHP * Once vendors are installed, a few commands must be run to set up the environment * ./Tests/Functional/app/console assets:install --symlink Tests/Functional/web diff --git a/Tests/Entity/CommentManagerTest.php b/Tests/Entity/CommentManagerTest.php index 5616f120e..b7ae247be 100644 --- a/Tests/Entity/CommentManagerTest.php +++ b/Tests/Entity/CommentManagerTest.php @@ -29,6 +29,10 @@ class CommentManagerTest extends \PHPUnit_Framework_TestCase public function setUp() { + if (!class_exists('Doctrine\\ORM\\EntityManager')) { + $this->markTestSkipped('Doctrine ORM not installed'); + } + $this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') ->disableOriginalConstructor() diff --git a/Tests/Entity/ThreadManagerTest.php b/Tests/Entity/ThreadManagerTest.php index 59edb06a3..032ba8405 100644 --- a/Tests/Entity/ThreadManagerTest.php +++ b/Tests/Entity/ThreadManagerTest.php @@ -28,6 +28,10 @@ class ThreadManagerTest extends \PHPUnit_Framework_TestCase public function setUp() { + if (!class_exists('Doctrine\\ORM\\EntityManager')) { + $this->markTestSkipped('Doctrine ORM not installed'); + } + $this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') ->disableOriginalConstructor() diff --git a/Tests/Entity/VoteManagerTest.php b/Tests/Entity/VoteManagerTest.php index cd36b6c41..4cbc60c0d 100644 --- a/Tests/Entity/VoteManagerTest.php +++ b/Tests/Entity/VoteManagerTest.php @@ -28,6 +28,10 @@ class VoteManagerTest extends \PHPUnit_Framework_TestCase public function setUp() { + if (!class_exists('Doctrine\\ORM\\EntityManager')) { + $this->markTestSkipped('Doctrine ORM not installed'); + } + $this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') ->disableOriginalConstructor() diff --git a/Tests/Functional/Bundle/CommentBundle/Controller/CommentController.php b/Tests/Functional/Bundle/CommentBundle/Controller/CommentController.php index 63e591a79..136b92bd9 100644 --- a/Tests/Functional/Bundle/CommentBundle/Controller/CommentController.php +++ b/Tests/Functional/Bundle/CommentBundle/Controller/CommentController.php @@ -44,10 +44,7 @@ public function inlineAction(Request $request, $id) return $this->render('CommentBundle:Comment:inline.html.twig', array( 'comments' => $comments, - 'displayDepth' => null, - 'sorter' => null, 'thread' => $thread, - 'view' => 'tree', )); } } diff --git a/Tests/Functional/Bundle/CommentBundle/Entity/Comment.php b/Tests/Functional/Bundle/CommentBundle/Entity/Comment.php index f2ce89aed..37c2ddcab 100644 --- a/Tests/Functional/Bundle/CommentBundle/Entity/Comment.php +++ b/Tests/Functional/Bundle/CommentBundle/Entity/Comment.php @@ -42,7 +42,7 @@ class Comment extends BaseComment implements SignedCommentInterface, VotableComm protected $thread; /** - * @ORM\Column(type="string") + * @ORM\Column(type="string", nullable=true) * @var string */ protected $author; diff --git a/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/async.html.twig b/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/async.html.twig index f90de584e..01a9420dc 100644 --- a/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/async.html.twig +++ b/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/async.html.twig @@ -1,5 +1,6 @@ {% extends "::base.html.twig"%} {% block body %} + {% include 'FOSCommentBundle:Thread:async.html.twig' with { 'id': id } %} {% endblock body %} diff --git a/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/inline.html.twig b/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/inline.html.twig index 3b8ba8bc7..18e096476 100644 --- a/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/inline.html.twig +++ b/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/inline.html.twig @@ -1,19 +1,17 @@ {% extends "::base.html.twig" %} {% block body %} -
+
{% include 'FOSCommentBundle:Thread:comments.html.twig' with { 'comments': comments, - 'displayDepth': displayDepth, - 'sorter': sorter, - 'thread': thread, - 'view': view + 'thread': thread } %} {% endblock body %} {% block javascript %} {% javascripts '@FOSCommentBundle/Resources/assets/js/comments.js' %} +