Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     $this->appMock = $this->getMock(\Magelight\App::class, [], [], '', false);
     \Magelight\App::forgeMock($this->appMock);
     $this->dbMock = $this->getMock(\Magelight\Db\Common\Adapter::class, [], [], '', false);
     $this->appMock->expects($this->any())->method('db')->with(App::DEFAULT_INDEX)->will($this->returnValue($this->dbMock));
     $this->dbMock->expects($this->any())->method('getType')->will($this->returnValue(\Magelight\Db\Common\Adapter::TYPE_MYSQL));
     $this->ormMock = $this->getMock(\Magelight\Db\Mysql\Orm::class, [], [], '', false);
     \Magelight\Db\Mysql\Orm::forgeMock($this->ormMock);
     $this->ormMock->expects($this->once())->method('create')->with(['arg1' => 'value1'], false);
     $this->model = Model::forge(['arg1' => 'value1']);
 }
Ejemplo n.º 2
0
 public function testForwardController()
 {
     $this->controller->init();
     $this->appMock->expects($this->once())->method('getCurrentAction')->will($this->returnValue([['module' => 'Module1', 'controller' => 'index', 'action' => 'index']]));
     $this->appMock->expects($this->once())->method('dispatchAction')->with(['module' => 'Module1', 'controller' => 'index', 'action' => 'forwarded']);
     $this->controller->forwardController('index', 'forwarded');
 }
Ejemplo n.º 3
0
 public function testSetSetupScriptExecuted()
 {
     $this->appMock->expects($this->any())->method('db')->will($this->returnValue($this->dbMock));
     $this->dbMock->expects($this->at(0))->method('execute')->with($this->matchesRegularExpression('/CREATE TABLE.*/'));
     $installer = \Magelight\Installer::forge();
     $this->dbMock->expects($this->at(0))->method('execute')->with($this->matches("INSERT INTO `" . $installer->getVersionTable() . "` (module_name, setup_script) VALUES (?, ?)"), ['Module1', 'setup-1.0.0.0.php']);
     $this->assertInstanceOf(\Magelight\Installer::class, $installer->setSetupScriptExecuted('Module1', 'setup-1.0.0.0.php'));
 }
Ejemplo n.º 4
0
 public function testLoadFromCacheMiss()
 {
     $appConfig = '<config><global>
         <app>
             <cache_modules_config>1</cache_modules_config>
         </app>
     </global></config>';
     $expectedConfig = new \SimpleXMLElement('<config><global>
         <app>
             <cache_modules_config>0</cache_modules_config>
             <framework_config_data>framework</framework_config_data>
             <app_module_config_data>app.domain</app_module_config_data>
             <bool_data_true>1</bool_data_true>
             <bool_data_false>0</bool_data_false>
             <int_data>123</int_data>
             <float_data>123.456</float_data>
             <array_data>
                 <node_1>data</node_1>
                 <node_2>data_node_2</node_2>
             </array_data>
             <string_data>some string</string_data>
             <config_with_attribute attribute_1="attribute_value">config_string</config_with_attribute>
         </app>
     </global></config>');
     $this->appMock->expects($this->once())->method('getAppDir')->will($this->returnValue('/app'));
     $this->appMock->expects($this->once())->method('getModuleDirectories')->will($this->returnValue(['/app/modules', '/framework/modules']));
     $this->configLoaderMock->expects($this->at(0))->method('loadConfig')->with('/app' . DS . 'etc' . DS . 'config.xml');
     $this->configLoaderMock->expects($this->at(1))->method('getConfig')->will($this->returnValue(new \SimpleXMLElement($appConfig)));
     $this->modulesMock->expects($this->any())->method('getActiveModules')->will($this->returnValue([['name' => 'Magelight_Module', 'path' => 'Magelight\\Module'], ['name' => 'App_Module', 'path' => 'App\\Module']]));
     $this->configLoaderMock->expects($this->any())->method('getModulesConfigFilePath')->will($this->returnValueMap([['/framework/modules', ['name' => 'Magelight_Module', 'path' => 'Magelight\\Module'], '/framework/modules/Magelight\\Module' . DS . 'etc' . DS . 'config.xml'], ['/app/modules', ['name' => 'Magelight_Module', 'path' => 'Magelight\\Module'], null], ['/framework/modules', ['name' => 'App_Module', 'path' => 'App\\Module'], null], ['/app/modules', ['name' => 'App_Module', 'path' => 'App\\Module'], '/app/modules/App\\Module' . DS . 'etc' . DS . 'config.xml']]));
     $this->configLoaderMock->expects($this->at(3))->method('loadConfig')->with('/framework/modules/Magelight\\Module' . DS . 'etc' . DS . 'config.xml');
     $this->configLoaderMock->expects($this->at(7))->method('loadConfig')->with('/app/modules/App\\Module' . DS . 'etc' . DS . 'config.xml');
     $this->configLoaderMock->expects($this->at(8))->method('getConfig')->will($this->returnValue($expectedConfig));
     $this->cacheAdapterMock->expects($this->once())->method('set')->with($this->config->buildCacheKey('modules_config'), $expectedConfig->asXML(), 3600);
     $this->config->load();
     $this->assertEquals('framework', $this->config->getConfigString('/global/app/framework_config_data'));
     $this->assertEquals('app.domain', $this->config->getConfigString('/global/app/app_module_config_data'));
     $this->assertTrue($this->config->getConfigBool('/global/app/bool_data_true'));
     $this->assertFalse($this->config->getConfigBool('/global/app/bool_data_false'));
     $this->assertInternalType('int', $this->config->getConfigInt('/global/app/int_data'));
     $this->assertEquals(123, $this->config->getConfigInt('/global/app/int_data'));
     $this->assertInternalType('float', $this->config->getConfigFloat('/global/app/float_data'));
     $this->assertEquals(123.456, $this->config->getConfigFloat('/global/app/float_data'));
     $this->assertInternalType('array', $this->config->getConfigArray('/global/app/array_data'));
     $this->assertEquals(['node_1' => 'data', 'node_2' => 'data_node_2'], $this->config->getConfigArray('/global/app/array_data'));
     $this->assertInternalType('string', $this->config->getConfigString('/global/app/string_data'));
     $this->assertEquals('some string', $this->config->getConfigString('/global/app/string_data'));
     $this->assertInternalType('string', $this->config->getConfigAttribute('/global/app/config_with_attribute', 'attribute_1'));
     $this->assertEquals('attribute_value', $this->config->getConfigAttribute('/global/app/config_with_attribute', 'attribute_1'));
     $this->assertInternalType('string', $this->config->getConfigString('/global/app/unexistent_node', 'default_value'));
     $this->assertEquals('default_value', $this->config->getConfigString('/global/app/unexistent_node', 'default_value'));
     $this->assertInternalType('array', $this->config->getConfigSet('/global/app'));
     $this->assertInternalType('string', $this->config->getConfigXmlString());
     $this->assertEquals($expectedConfig->asXML(), $this->config->getConfigXmlString());
 }