From 3d238902acede5e5e0e4bab7f5594a5f67147f41 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 20 Jun 2014 14:32:54 +0200 Subject: [PATCH] =?UTF-8?q?Complete=20AddressTest,=20highlight=20bug=20=09?= =?UTF-8?q?modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/A?= =?UTF-8?q?ction/AddressTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Tests/Action/AddressTest.php | 70 ++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/core/lib/Thelia/Tests/Action/AddressTest.php b/core/lib/Thelia/Tests/Action/AddressTest.php index 91101544c..7677e66d8 100644 --- a/core/lib/Thelia/Tests/Action/AddressTest.php +++ b/core/lib/Thelia/Tests/Action/AddressTest.php @@ -12,8 +12,11 @@ namespace Thelia\Tests\Action; +use Propel\Runtime\Propel; use Thelia\Action\Address; use Thelia\Core\Event\Address\AddressCreateOrUpdateEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Model\AddressQuery; use Thelia\Model\CustomerQuery; /** @@ -121,4 +124,71 @@ class AddressTest extends \PHPUnit_Framework_TestCase } + /** + * Bug found in Thelia 2.0.2 + */ + public function testUpdateDefaultAddress() + { + /** + * Disable propel cache in order to get a new instance of the + * active record in $updatedAddress + */ + Propel::disableInstancePooling(); + + /** + * Get a customer and it's default address + */ + $customer = CustomerQuery::create()->findOne(); + $defaultAddress = $customer->getDefaultAddress(); + $addressId = $defaultAddress->getId(); + + /** + * Try to update the address, and set the isDefault argument, + * that should keep this address as the default one. + */ + $addressEvent = new AddressCreateOrUpdateEvent( + "", + 1, + "Thelia modif", + "Thelia modif", + "cour des étoiles", + "rue des miracles", + "", + "63000", + "clermont-ferrand", + 64, + "0102030405", + "", + "", + 1 + ); + + $addressEvent->setAddress($defaultAddress); + $addressEvent->setDispatcher( + $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface") + ); + + /** + * Do the update + */ + $actionAddress = new Address(); + $actionAddress->update($addressEvent); + + $updatedAddress = AddressQuery::create() + ->findPk($addressId); + + /** + * This address should still be the default address + */ + $this->assertEquals( + 1, + $updatedAddress->getIsDefault() + ); + + /** + * Renable it after + */ + Propel::enableInstancePooling(); + } + }