public function testGetFkName()
 {
     $tableName = 'table';
     $refTable = 'ref_table';
     $columnName = 'columnName';
     $refColumnName = 'refColumnName';
     $this->connection->expects($this->once())->method('getForeignKeyName')->with($tableName, $columnName, $refTable, $refColumnName)->will($this->returnValue('fkName'));
     $this->assertEquals('fkName', $this->setup->getFkName($tableName, $columnName, $refTable, $refColumnName));
 }
 public function setUp()
 {
     $this->setUpMock = $this->getMock('Magento\\Setup\\Module\\Setup', [], [], '', false);
     $this->dbAdapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->setUpMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->dbAdapterMock));
     $this->setUpMock->expects($this->any())->method('getTable')->will($this->returnCallback(function ($table) {
         return $table;
     }));
     $this->encryptor = $this->getMockBuilder('Magento\\Framework\\Encryption\\EncryptorInterface')->getMockForAbstractClass();
     $data = [AdminAccount::KEY_FIRST_NAME => 'John', AdminAccount::KEY_LAST_NAME => 'Doe', AdminAccount::KEY_EMAIL => '*****@*****.**', AdminAccount::KEY_PASSWORD => '123123q', AdminAccount::KEY_USER => 'admin'];
     $this->adminAccount = new AdminAccount($this->setUpMock, $this->encryptor, $data);
 }
 public function setUp()
 {
     $this->setUpMock = $this->getMock('Magento\\Setup\\Module\\Setup', [], [], '', false);
     $this->dbAdapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->setUpMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->dbAdapterMock));
     $this->setUpMock->expects($this->any())->method('getTable')->will($this->returnCallback(function ($table) {
         return $table;
     }));
     $this->randomMock = $this->getMock('Magento\\Framework\\Math\\Random');
     $this->randomMock->expects($this->any())->method('getRandomString')->will($this->returnValue('salt'));
     $data = [AdminAccount::KEY_FIRST_NAME => 'John', AdminAccount::KEY_LAST_NAME => 'Doe', AdminAccount::KEY_EMAIL => '*****@*****.**', AdminAccount::KEY_PASSWORD => '123123q', AdminAccount::KEY_USERNAME => 'admin'];
     $this->adminAccount = new AdminAccount($this->setUpMock, $this->randomMock, $data);
 }
 /**
  * Constructor
  *
  * @param LoggerInterface $log
  * @param ModuleListInterface $moduleList
  * @param SetupFileResolver $fileResolver
  * @param string $moduleName
  * @param \Magento\Framework\App\Resource $resource
  * @param string $connectionName
  */
 public function __construct(LoggerInterface $log, ModuleListInterface $moduleList, SetupFileResolver $fileResolver, $moduleName, \Magento\Framework\App\Resource $resource, $connectionName = SetupInterface::DEFAULT_SETUP_CONNECTION)
 {
     parent::__construct($resource, $connectionName);
     $this->logger = $log;
     $this->fileResolver = $fileResolver;
     $this->moduleConfig = $moduleList->getOne($moduleName);
     $this->resource = new Resource($resource);
     $this->resourceName = $this->fileResolver->getResourceCode($moduleName);
 }
 /**
  * Gets the "Administrators" role id, the special role created by data fixture in Authorization module.
  *
  * @return int The id of the Administrators role
  * @throws \Exception If Administrators role not found or problem connecting with database.
  */
 private function retrieveAdministratorsRoleId()
 {
     // Get Administrators role id to use as parent_id
     $administratorsRoleData = ['parent_id' => 0, 'tree_level' => 1, 'role_type' => Group::ROLE_TYPE, 'user_id' => 0, 'user_type' => UserContextInterface::USER_TYPE_ADMIN, 'role_name' => 'Administrators'];
     $result = $this->setup->getConnection()->fetchRow('SELECT * FROM ' . $this->setup->getTable('authorization_role') . ' ' . 'WHERE parent_id = :parent_id AND tree_level = :tree_level AND role_type = :role_type AND ' . 'user_id = :user_id AND user_type = :user_type AND role_name = :role_name', $administratorsRoleData);
     if (empty($result)) {
         throw new \Exception('No Administrators role was found, data fixture needs to be run');
     } else {
         // Found at least one, use first
         return $result['role_id'];
     }
 }