/** * Logs in as a customer by customer id and store id * * @param int $customerId * @param string|int|null $storeId * * @return EcomDev_PHPUnit_Mock_Proxy */ public function helperCustomerSession($customerId, $storeId = null) { $customerSessionMock = TestHelper::invoke('mockSession', 'customer/session', array('renewSession')); if ($storeId === null) { $storeId = TestUtil::app()->getAnyStoreView()->getCode(); } TestUtil::setCurrentStore($storeId); $customerSessionMock->loginById($customerId); return $customerSessionMock; }
/** * Start session as guest. * * @param string|int|null $storeId * * @return EcomDev_PHPUnit_Mock_Proxy */ public function helperGuestSession($storeId = null) { $guestSessionMock = TestHelper::invoke('mockSession', 'core/session', array('renewSession')); /** @var Mage_Core_Model_Session $session */ $session = $guestSessionMock->getMock(); $_GET[$session->getSessionIdQueryParam()] = $session->getSessionId(); // some action need that (loginPost, ...) if ($storeId === null) { $storeId = TestUtil::app()->getAnyStoreView()->getCode(); } TestUtil::setCurrentStore($storeId); return $guestSessionMock; }
/** * Discard applied scope models * * @param array[] $data * @param string $key * @param EcomDev_PHPUnit_Model_FixtureInterface $fixture * * @return EcomDev_PHPUnit_Model_Fixture_Processor_Scope */ public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture) { if ($fixture->getStorageData(self::STORAGE_KEY) === null) { return $this; } EcomDev_PHPUnit_Test_Case_Util::app()->disableEvents(); $scope = array_reverse($fixture->getStorageData(self::STORAGE_KEY)); foreach ($scope as $models) { foreach ($models as $model) { $model->delete(); } } $fixture->setStorageData(self::STORAGE_KEY, null); EcomDev_PHPUnit_Test_Case_Util::app()->getCache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array(Mage_Core_Model_Store::CACHE_TAG, Mage_Core_Model_Store_Group::CACHE_TAG, Mage_Core_Model_Website::CACHE_TAG)); EcomDev_PHPUnit_Test_Case_Util::app()->enableEvents(); EcomDev_PHPUnit_Test_Case_Util::app()->reinitStores(); return $this; }
/** * Sets back old singletons after tests * * @param array[] $data * @param string $key * @param EcomDev_PHPUnit_Model_FixtureInterface $fixture * * @return EcomDev_PHPUnit_Model_Fixture_ProcessorInterface */ public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture) { if ($fixture->getStorageData(self::STORAGE_KEY) === null) { return $this; } $oldRegistry = $fixture->getStorageData(self::STORAGE_KEY); foreach ($oldRegistry as $key => $value) { // Set old value to registry EcomDev_PHPUnit_Test_Case_Util::app()->replaceRegistry($key, $value); } $fixture->setStorageData(self::STORAGE_KEY, null); return $this; }
/** * Returns app for test case, created for type hinting * in the test case code * * @return EcomDev_PHPUnit_Model_App */ public static function app() { return TestUtil::app(); }
/** * clears the config cache in the specified store. * @param mixed $store a code, id, or model of a magento storm * @return null */ public function clearStoreConfigCache($store = null) { $store = EcomDev_PHPUnit_Test_Case_Util::app()->getStore($store); EcomDev_Utils_Reflection::setRestrictedPropertyValue($store, '_configCache', []); }
/** * Discard applied cache options * * @param array[] $data * @param string $key * @param EcomDev_PHPUnit_Model_FixtureInterface $fixture * * @return EcomDev_PHPUnit_Model_Fixture_Processor_Cache */ public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture) { EcomDev_PHPUnit_Test_Case_Util::app()->setCacheOptions($fixture->getStorageData(self::STORAGE_KEY)); return $this; }