public function testInjectControllerReset() { $controller = Controller_ExtJS_Admin_Job_Factory::createController($this->_context, 'Default'); Controller_ExtJS_Admin_Job_Factory::injectController('Controller_ExtJS_Admin_Job_Default', $controller); Controller_ExtJS_Admin_Job_Factory::injectController('Controller_ExtJS_Admin_Job_Default', null); $new = Controller_ExtJS_Admin_Job_Factory::createController($this->_context, 'Default'); $this->assertNotSame($controller, $new); }
/** * Creates a new job to export a file. * * @param stdClass $params Object containing the properties, e.g. the list of catalog IDs */ public function createJob(stdClass $params) { $this->_checkParams($params, array('site', 'items')); $this->_setLocale($params->site); $context = $this->_getContext(); $items = (array) $params->items; $lang = property_exists($params, 'lang') ? (array) $params->lang : array(); $languages = !empty($lang) ? implode($lang, '-') : 'all'; $result = (object) array('site' => $params->site, 'items' => array((object) array('job.label' => 'Catalog text export: ' . $languages, 'job.method' => 'Catalog_Export_Text.exportFile', 'job.parameter' => array('site' => $params->site, 'items' => $items, 'lang' => $params->lang), 'job.status' => 1))); $jobController = Controller_ExtJS_Admin_Job_Factory::createController($context); $jobController->saveItems($result); return array('items' => $items, 'success' => true); }
public function testRun() { $context = TestHelper::getContext(); $arcavias = TestHelper::getArcavias(); $name = 'ControllerJobsAdminJobDefaultRun'; $context->getConfig()->set('classes/job/manager/name', $name); $context->getConfig()->set('classes/controller/extjs/admin/job/name', $name); MAdmin_Job_Manager_Factory::injectManager('MAdmin_Job_Manager_' . $name, $this->_jobManagerStub); $adminJobCntlStub = $this->getMockBuilder('Controller_ExtJS_Admin_Job_Default')->setMethods(array('deleteItem'))->setConstructorArgs(array($context))->getMock(); Controller_ExtJS_Admin_Job_Factory::injectController('Controller_ExtJS_Admin_Job_' . $name, $adminJobCntlStub); $adminJobCntlStub->expects($this->once())->method('deleteItem')->will($this->returnValue(array('number' => 42))); $this->_jobManagerStub->expects($this->atLeastOnce())->method('searchItems')->will($this->onConsecutiveCalls(array($this->_jobItemStub), array())); $this->_jobManagerStub->expects($this->once())->method('saveItem'); $this->_jobItemStub->expects($this->atLeastOnce())->method('getMethod')->will($this->returnValue('Admin_Job.deleteItem')); $this->_jobItemStub->expects($this->once())->method('setResult')->with($this->equalTo(array('number' => 42))); $this->_jobItemStub->expects($this->once())->method('setStatus')->with($this->equalTo(-1)); $object = new Controller_Jobs_Admin_Job_Default($context, $arcavias); $object->run(); }
/** * Uploads a XLS file with all attribute texts. * * @param stdClass $params Object containing the properties */ public function uploadFile(stdClass $params) { $this->_checkParams($params, array('site')); $this->_setLocale($params->site); if (($fileinfo = reset($_FILES)) === false) { throw new Controller_ExtJS_Exception('No file was uploaded'); } $config = $this->_getContext()->getConfig(); /** controller/extjs/attribute/import/text/default/uploaddir * Upload directory for text files that should be imported * * The upload directory must be an absolute path. Avoid a trailing slash * at the end of the upload directory string! * * @param string Absolute path including a leading slash * @since 2014.03 * @category Developer */ $dir = $config->get('controller/extjs/attribute/import/text/default/uploaddir', 'uploads'); /** controller/extjs/attribute/import/text/default/enablecheck * Enables checking uploaded files if they are valid and not part of an attack * * This configuration option is for unit testing only! Please don't disable * the checks for uploaded files in production environments as this * would give attackers the possibility to infiltrate your installation! * * @param boolean True to enable, false to disable * @since 2014.03 * @category Developer */ if ($config->get('controller/extjs/attribute/import/text/default/enablecheck', true)) { $this->_checkFileUpload($fileinfo['tmp_name'], $fileinfo['error']); } $fileext = pathinfo($fileinfo['name'], PATHINFO_EXTENSION); $dest = $dir . DIRECTORY_SEPARATOR . md5($fileinfo['name'] . time() . getmypid()) . '.' . $fileext; if (rename($fileinfo['tmp_name'], $dest) !== true) { $msg = sprintf('Uploaded file could not be moved to upload directory "%1$s"', $dir); throw new Controller_ExtJS_Exception($msg); } /** controller/extjs/attribute/import/text/default/fileperms * File permissions used when storing uploaded files * * The representation of the permissions is in octal notation (using 0-7) * with a leading zero. The first number after the leading zero are the * permissions for the web server creating the directory, the second is * for the primary group of the web server and the last number represents * the permissions for everyone else. * * You should use 0660 or 0600 for the permissions as the web server needs * to manage the files. The group permissions are important if you plan * to upload files directly via FTP or by other means because then the * web server needs to be able to read and manage those files. In this * case use 0660 as permissions, otherwise you can limit them to 0600. * * A more detailed description of the meaning of the Unix file permission * bits can be found in the Wikipedia article about * {@link https://en.wikipedia.org/wiki/File_system_permissions#Numeric_notation file system permissions} * * @param integer Octal Unix permission representation * @since 2014.03 * @category Developer */ $perms = $config->get('controller/extjs/attribute/import/text/default/fileperms', 0660); if (chmod($dest, $perms) !== true) { $msg = sprintf('Could not set permissions "%1$s" for file "%2$s"', $perms, $dest); throw new Controller_ExtJS_Exception($msg); } $result = (object) array('site' => $params->site, 'items' => array((object) array('job.label' => 'Attribute text import: ' . $fileinfo['name'], 'job.method' => 'Attribute_Import_Text.importFile', 'job.parameter' => array('site' => $params->site, 'items' => $dest), 'job.status' => 1))); $jobController = Controller_ExtJS_Admin_Job_Factory::createController($this->_getContext()); $jobController->saveItems($result); return array('items' => $dest, 'success' => true); }
protected function setUp() { $context = TestHelper::getContext(); $controller = Controller_ExtJS_Admin_Job_Factory::createController($context); $this->_object = new Controller_ExtJS_Common_Decorator_Example($context, $controller); }
public function testUploadFile() { $config = $this->_context->getConfig(); $config->set('controller/extjs/coupon/code/default/uploaddir', './tmp'); $config->set('controller/extjs/coupon/code/default/enablecheck', false); $cntlMock = $this->getMockBuilder('Controller_ExtJS_Admin_Job_Default')->setMethods(array('saveItems'))->setConstructorArgs(array($this->_context))->getMock(); $cntlMock->expects($this->once())->method('saveItems'); $name = 'ControllerExtJSCouponCodeDefaultRun'; $this->_context->getConfig()->set('classes/controller/extjs/admin/job/name', $name); Controller_ExtJS_Admin_Job_Factory::injectController('Controller_ExtJS_Admin_Job_' . $name, $cntlMock); $testfiledir = __DIR__ . DIRECTORY_SEPARATOR . 'testfiles' . DIRECTORY_SEPARATOR; exec(sprintf('cp -r %1$s %2$s', escapeshellarg($testfiledir) . '*', escapeshellarg($this->_testdir))); $_FILES['unittest'] = array('name' => 'coupon.zip', 'tmp_name' => $this->_testdir . DIRECTORY_SEPARATOR . 'coupon.zip', 'error' => UPLOAD_ERR_OK); $params = new stdClass(); $params->items = $this->_testdir . DIRECTORY_SEPARATOR . 'coupon.zip'; $params->site = $this->_context->getLocale()->getSite()->getCode(); $params->couponid = '-1'; $result = $this->_object->uploadFile($params); $this->assertTrue(file_exists($result['items'])); unlink($result['items']); }
public function testFactoryExceptionWrongInterface() { $this->setExpectedException('Controller_ExtJS_Exception'); Controller_ExtJS_Admin_Job_Factory::createController(TestHelper::getContext(), 'Factory'); }
public function testUploadFile() { $jobController = Controller_ExtJS_Admin_Job_Factory::createController($this->_context); $testfiledir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'testfiles' . DIRECTORY_SEPARATOR; exec(sprintf('cp -r %1$s %2$s', escapeshellarg($testfiledir) . '*', escapeshellarg($this->_testdir))); $_FILES['unittest'] = array('name' => 'file.txt', 'tmp_name' => $this->_testfile, 'error' => UPLOAD_ERR_OK); $params = new stdClass(); $params->items = $this->_testfile; $params->site = $this->_context->getLocale()->getSite()->getCode(); $result = $this->_object->uploadFile($params); $this->assertTrue(file_exists($result['items'])); unlink($result['items']); $params = (object) array('site' => 'unittest', 'condition' => (object) array('&&' => array(0 => (object) array('~=' => (object) array('job.label' => 'file.txt'))))); $result = $jobController->searchItems($params); $this->assertEquals(1, count($result['items'])); $deleteParams = (object) array('site' => 'unittest', 'items' => $result['items'][0]->{'job.id'}); $jobController->deleteItems($deleteParams); $result = $jobController->searchItems($params); $this->assertEquals(0, count($result['items'])); }