public function testWrongPermsPut()
 {
     // We need a customer user without regions to test permissions
     $this->loginByUserId(\App_Test_PHPUnit_Framework_TestCase::PROVIDER_COMMERCIAL_API_ID, $this->_authType);
     // Mock EnumeratedService to return empty enum
     $factory = new App_Test_PHPUnit_Mock_Factory();
     $mock = $factory->buildSingleton('\\Application\\Model\\Mapper\\EnumeratedMapper', array('listServiceProviderRegion' => $this->returnValue(array())));
     // Update customer
     $data = array('endCustomerData' => array('customFieldName_1' => 'aaa'));
     $this->put($this->_controllerUrl . '/' . $this->_itemId, array(), $data);
     $this->assertInstanceOf('\\Application\\Exceptions\\PermissionException', $this->getException());
     // Undo EnumeratedService mock
     $mock->undo();
 }
示例#2
0
 public function getMongoMock($class)
 {
     // Get routes
     $parts = explode('\\', $class);
     $n = count($parts);
     $path = implode(DIRECTORY_SEPARATOR, array($this->_getMocksPath(), $parts[$n - 2], $parts[$n - 1]));
     // Get model class
     $instance = $class::getInstance();
     $modelClass = $instance->getModelClassResult();
     // Get methods
     $methods = array();
     $handle = opendir($path);
     if ($handle) {
         while (false !== ($entry = readdir($handle))) {
             // Valid formats:
             // - findOneById.json
             // - findOneById-Ok.json
             // - findOneById-Ko.json
             $dot = strpos($entry, '.');
             $ok = strpos($entry, '-Ok');
             $ko = strpos($entry, '-Ko');
             // Get method
             $pos = $ok ? $ok : ($ko ?: $dot);
             $method = substr($entry, 0, $pos);
             // Get data
             $data = file_get_contents($path . DIRECTORY_SEPARATOR . $entry);
             $data = json_decode($data);
             $methods[$method] = $this->returnValue(new $modelClass($data));
         }
         closedir($handle);
     }
     // Mock class
     $factory = new \App_Test_PHPUnit_Mock_Factory();
     return $factory->buildSingleton($class, $methods);
 }