Browse Source

Added tests for ConfigureEvent, ConfigureQueryEvent and PersistenceEvent

Andrej Hudec 11 years ago
parent
commit
8f0e8bd183

+ 2 - 2
Event/AdminEventExtension.php

@@ -3,7 +3,7 @@
 /*
 /*
  * This file is part of the Sonata package.
  * This file is part of the Sonata package.
  *
  *
- * (c) 2010-2011 Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  *
  *
  * For the full copyright and license information, please view the LICENSE
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  * file that was distributed with this source code.
@@ -119,4 +119,4 @@ class AdminEventExtension extends AdminExtension
     {
     {
         $this->eventDispatcher->dispatch('sonata.admin.event.persistence.post_remove', new PersistenceEvent($admin, $object, PersistenceEvent::TYPE_POST_REMOVE));
         $this->eventDispatcher->dispatch('sonata.admin.event.persistence.post_remove', new PersistenceEvent($admin, $object, PersistenceEvent::TYPE_POST_REMOVE));
     }
     }
-}
+}

+ 2 - 2
Event/ConfigureEvent.php

@@ -3,7 +3,7 @@
 /*
 /*
  * This file is part of the Sonata package.
  * This file is part of the Sonata package.
  *
  *
- * (c) 2010-2011 Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  *
  *
  * For the full copyright and license information, please view the LICENSE
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  * file that was distributed with this source code.
@@ -75,4 +75,4 @@ class ConfigureEvent extends Event
     {
     {
         return $this->mapper;
         return $this->mapper;
     }
     }
-}
+}

+ 2 - 2
Event/ConfigureQueryEvent.php

@@ -3,7 +3,7 @@
 /*
 /*
  * This file is part of the Sonata package.
  * This file is part of the Sonata package.
  *
  *
- * (c) 2010-2011 Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  *
  *
  * For the full copyright and license information, please view the LICENSE
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  * file that was distributed with this source code.
@@ -67,4 +67,4 @@ class ConfigureQueryEvent extends Event
     {
     {
         return $this->proxyQuery;
         return $this->proxyQuery;
     }
     }
-}
+}

+ 2 - 3
Event/PersistenceEvent.php

@@ -3,7 +3,7 @@
 /*
 /*
  * This file is part of the Sonata package.
  * This file is part of the Sonata package.
  *
  *
- * (c) 2010-2011 Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  *
  *
  * For the full copyright and license information, please view the LICENSE
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  * file that was distributed with this source code.
@@ -14,7 +14,6 @@ namespace Sonata\AdminBundle\Event;
 use Sonata\AdminBundle\Admin\AdminInterface;
 use Sonata\AdminBundle\Admin\AdminInterface;
 use Symfony\Component\EventDispatcher\Event;
 use Symfony\Component\EventDispatcher\Event;
 
 
-
 /**
 /**
  * This event is sent by hook:
  * This event is sent by hook:
  *   - preUpdate | postUpdate
  *   - preUpdate | postUpdate
@@ -76,4 +75,4 @@ class PersistenceEvent extends Event
     {
     {
         return $this->type;
         return $this->type;
     }
     }
-}
+}

+ 65 - 0
Tests/Event/ConfigureEventTest.php

@@ -0,0 +1,65 @@
+<?php
+
+/*
+ * This file is part of the Sonata package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sonata\AdminBundle\Tests\Event;
+
+use Sonata\AdminBundle\Admin\AdminInterface;
+use Sonata\AdminBundle\Mapper\BaseMapper;
+use Sonata\AdminBundle\Event\ConfigureEvent;
+
+class ConfigureEventTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * @var ConfigureEvent
+     */
+    private $event;
+
+    /**
+     * @var AdminInterface
+     */
+    private $admin;
+
+    /**
+     * @var BaseMapper
+     */
+    private $mapper;
+
+    protected function setUp()
+    {
+        $this->admin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');
+        $this->mapper = $this->getMockBuilder('Sonata\AdminBundle\Mapper\BaseMapper')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $this->event = new ConfigureEvent($this->admin, $this->mapper, 'Foo');
+    }
+
+    public function testGetType()
+    {
+        $this->assertEquals('Foo', $this->event->getType());
+    }
+
+    public function testGetAdmin()
+    {
+        $result = $this->event->getAdmin();
+
+        $this->assertInstanceOf('Sonata\AdminBundle\Admin\AdminInterface', $result);
+        $this->assertEquals($this->admin, $result);
+    }
+
+    public function testGetMapper()
+    {
+        $result = $this->event->getMapper();
+
+        $this->assertInstanceOf('Sonata\AdminBundle\Mapper\BaseMapper', $result);
+        $this->assertEquals($this->mapper, $result);
+    }
+}

+ 63 - 0
Tests/Event/ConfigureQueryEventTest.php

@@ -0,0 +1,63 @@
+<?php
+
+/*
+ * This file is part of the Sonata package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sonata\AdminBundle\Tests\Event;
+
+use Sonata\AdminBundle\Admin\AdminInterface;
+use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
+use Sonata\AdminBundle\Event\ConfigureQueryEvent;
+
+class ConfigureQueryEventTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * @var ConfigureQueryEvent
+     */
+    private $event;
+
+    /**
+     * @var AdminInterface
+     */
+    private $admin;
+
+    /**
+     * @var ProxyQueryInterface
+     */
+    private $proxyQuery;
+
+    protected function setUp()
+    {
+        $this->admin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');
+        $this->proxyQuery = $this->getMock('Sonata\AdminBundle\Datagrid\ProxyQueryInterface');
+
+        $this->event = new ConfigureQueryEvent($this->admin, $this->proxyQuery, 'Foo');
+    }
+
+    public function testGetContext()
+    {
+        $this->assertEquals('Foo', $this->event->getContext());
+    }
+
+    public function testGetAdmin()
+    {
+        $result = $this->event->getAdmin();
+
+        $this->assertInstanceOf('Sonata\AdminBundle\Admin\AdminInterface', $result);
+        $this->assertEquals($this->admin, $result);
+    }
+
+    public function testGetProxyQuery()
+    {
+        $result = $this->event->getProxyQuery();
+
+        $this->assertInstanceOf('Sonata\AdminBundle\Datagrid\ProxyQueryInterface', $result);
+        $this->assertEquals($this->proxyQuery, $result);
+    }
+}

+ 59 - 0
Tests/Event/PersistenceEventTest.php

@@ -0,0 +1,59 @@
+<?php
+
+/*
+ * This file is part of the Sonata package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sonata\AdminBundle\Tests\Event;
+
+use Sonata\AdminBundle\Admin\AdminInterface;
+use Sonata\AdminBundle\Event\PersistenceEvent;
+
+class PersistenceEventTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * @var PersistenceEvent
+     */
+    private $event;
+
+    /**
+     * @var AdminInterface
+     */
+    private $admin;
+
+    /**
+     * @var mixed
+     */
+    private $object;
+
+    protected function setUp()
+    {
+        $this->admin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');
+        $this->object = new \stdClass();
+
+        $this->event = new PersistenceEvent($this->admin, $this->object, 'Foo');
+    }
+
+    public function testGetType()
+    {
+        $this->assertEquals('Foo', $this->event->getType());
+    }
+
+    public function testGetAdmin()
+    {
+        $result = $this->event->getAdmin();
+
+        $this->assertInstanceOf('Sonata\AdminBundle\Admin\AdminInterface', $result);
+        $this->assertEquals($this->admin, $result);
+    }
+
+    public function testGetObject()
+    {
+        $this->assertEquals($this->object, $this->event->getObject());
+    }
+}