public function testConfig() { $oldConfig = Libraries::get('li3_facebook'); Libraries::remove('li3_facebook'); Libraries::add('li3_facebook'); FacebookProxy::$_autoConfigure = false; FacebookProxy::__init(); $this->assertEqual(FacebookProxy::config(), array(), 'config should be empty.'); $this->assertEqual(FacebookProxy::config(array()), array(), 'config should be empty.'); //check ignoring FacebookProxy::reset(); $result = FacebookProxy::config(array('foo')); $this->assertTrue($result, array(), 'config should return true'); $this->assertIdentical(FacebookProxy::config(), array(), 'config should be empty'); //check ingoring vs. existing but unset associations FacebookProxy::reset(); $result = FacebookProxy::config(array('appId')); $this->assertTrue($result, array(), 'config should return true'); $this->assertIdentical(FacebookProxy::config(), array(), 'config should be empty'); //check valid Settings FacebookProxy::reset(); $sampleConfig = array('appId' => 'hello'); $result = FacebookProxy::config($sampleConfig); $this->assertTrue($result, 'config should return true'); $this->assertIdentical(FacebookProxy::config(), $sampleConfig, 'config should not be empty'); //check vs. complete Settings FacebookProxy::reset(); $result = FacebookProxy::config($this->_mockDefaults); $this->assertTrue($result, 'config should return true'); $this->assertIdentical(FacebookProxy::config(), $this->_mockDefaults, 'config should not be empty'); Libraries::remove('li3_facebook'); Libraries::add('li3_facebook', $oldConfig); //FaceBookProxy::foo(); //die(print_r(array($result,FacebookProxy::config()),true)); }
public function tearDown() { $_SERVER = $this->_backup['_SERVER']; chdir($this->_backup['cwd']); Libraries::remove('library_test'); unset($this->library, $this->request); }
public function tearDown() { Mocker::overwriteFunction(false); $_SERVER = $this->_backup['_SERVER']; chdir($this->_backup['cwd']); Libraries::remove('library_test'); unset($this->library, $this->request); }
public function tearDown() { foreach ($this->_superglobals as $varname) { $GLOBALS[$varname] = $this->_env[$varname]; } Libraries::remove('app'); Libraries::add($this->_library['name'], $this->_library); $this->_cleanUp(); }
public function testEmptyConfig() { $oldConfig = Libraries::get('li3_facebook'); $subject = new Facebook(); //disable validation inside the proxy FacebookProxy::$_validateConfiguration = false; Libraries::remove('li3_facebook'); Libraries::add('li3_facebook'); $this->expectException('Configuration: `appId` should be set'); $this->assertTrue($subject->check($this->request)); Libraries::remove('li3_facebook'); Libraries::add('li3_facebook', $oldConfig); }
/** * Tests the addition and removal of default libraries. * * @return void */ public function testLibraryAddRemove() { $lithium = Libraries::get('lithium'); $this->assertFalse(empty($lithium)); $app = Libraries::get('app'); $this->assertFalse(empty($app)); Libraries::remove(array('lithium', 'app')); $result = Libraries::get('lithium'); $this->assertTrue(empty($result)); $result = Libraries::get('app'); $this->assertTrue(empty($result)); $result = Libraries::add('lithium', array('bootstrap' => null) + $lithium); $this->assertEqual($lithium, $result); $result = Libraries::add('app', array('bootstrap' => null) + $app); $this->assertEqual(array('bootstrap' => null) + $app, $result); }
public function testGetLibraryWebroot() { $this->assertTrue(is_dir(Media::webroot(true))); $this->assertNull(Media::webroot('foobar')); Libraries::add('foobar', array('path' => __DIR__, 'webroot' => __DIR__)); $this->assertEqual(__DIR__, Media::webroot('foobar')); Libraries::remove('foobar'); }
public function testGetLibraryWebroot() { $this->assertNull(Media::webroot('foobar')); Libraries::add('foobar', array('path' => __DIR__, 'webroot' => __DIR__)); $this->assertEqual(__DIR__, Media::webroot('foobar')); Libraries::remove('foobar'); $resources = Libraries::get(true, 'resources'); $webroot = "{$resources}/media_test/webroot"; $this->skipIf(!is_writable($resources), "Cannot write test app to resources directory."); if (!is_dir($webroot)) { mkdir($webroot, 0777, true); } Libraries::add('media_test', array('path' => "{$resources}/media_test")); $this->assertFileExists(Media::webroot('media_test')); Libraries::remove('media_test'); rmdir($webroot); }
public function testPathWithCustomDirectoryName() { $testApp = Libraries::get(true, 'resources') . '/tmp/tests/custom_dir'; $testDir = $testApp . '/tests/cases/models'; mkdir($testDir, 0777, true); Libraries::add('test_app', array('path' => $testApp)); $request = new Request(array('env' => array('working' => $testApp))); $command = new Test(array('request' => $request, 'classes' => $this->classes)); $expected = 'test_app\\tests\\cases\\models'; $result = $command->invokeMethod('_path', array('tests\\cases\\models')); $this->assertIdentical($expected, $result); Libraries::remove('test_app'); $this->_cleanUp(); }
public function testContextWithElementRenderingOptions() { $tmpDir = realpath(Libraries::get(true, 'resources') . '/tmp'); $this->skipIf(!is_writable($tmpDir), "Can't write to resources directory."); $testApp = $tmpDir . '/tests/test_app'; $viewDir = $testApp . '/views'; mkdir($viewDir . '/elements', 0777, true); Libraries::add('test_app', array('path' => $testApp)); $testApp2 = $tmpDir . '/tests/test_app2'; $viewDir2 = $testApp2 . '/views'; mkdir($viewDir2 . '/elements', 0777, true); Libraries::add('test_app2', array('path' => $testApp2)); $body = "<?php "; $body .= "echo \$this->_render('element', 'element2', array(), "; $body .= "array('library' => 'test_app2'));"; $body .= "echo \$this->_render('element', 'element1');"; $body .= "?>"; file_put_contents($viewDir . '/template.html.php', $body); file_put_contents($viewDir . '/elements/element1.html.php', 'element1'); file_put_contents($viewDir2 . '/elements/element2.html.php', 'element2'); $view = new View(array('compile' => false, 'paths' => array('template' => '{:library}/views/{:template}.html.php', 'element' => '{:library}/views/elements/{:template}.html.php', 'layout' => false))); $options = array('template' => 'template', 'library' => 'test_app'); $result = $view->render('all', array(), $options); $this->assertIdentical('element2element1', $result); $body = "<?php "; $body .= "echo \$this->_render('element', 'element1');"; $body .= "echo \$this->_render('element', 'element2', array(), "; $body .= "array('library' => 'test_app2'));"; $body .= "?>"; file_put_contents($viewDir . '/template.html.php', $body); $result = $view->render('all', array(), $options); $this->assertIdentical('element1element2', $result); Libraries::remove('test_app'); Libraries::remove('test_app2'); $this->_cleanUp(); }
/** * Tests that non-prefixed (poorly named or structured) libraries can still be added. * * @return void */ public function testAddNonPrefixedLibrary() { $tmpDir = realpath(Libraries::get(true, 'resources') . '/tmp'); $this->skipIf(!is_writable($tmpDir), "Can't write to resources directory."); $fakeDir = $tmpDir . '/fake'; $fake = "<?php class Fake {} ?>"; $fakeFilename = $fakeDir . '/fake.php'; mkdir($fakeDir, 0777, true); file_put_contents($fakeFilename, $fake); Libraries::add('bad', array('prefix' => false, 'path' => $fakeDir, 'transform' => function ($class, $config) { return ''; })); Libraries::add('fake', array('path' => $fakeDir, 'includePath' => true, 'prefix' => false, 'transform' => function ($class, $config) { return $config['path'] . '/' . Inflector::underscore($class) . '.php'; })); $this->assertFalse(class_exists('Fake', false)); $this->assertTrue(class_exists('Fake')); unlink($fakeFilename); rmdir($fakeDir); Libraries::remove('fake'); }
public function testElementRenderingOptions() { $tmpDir = realpath(Libraries::get(true, 'resources') . '/tmp'); $this->skipIf(!is_writable($tmpDir), "Can't write to resources directory."); $testApp = $tmpDir . '/tests/test_app'; $viewDir = $testApp . '/views'; mkdir($viewDir, 0777, true); Libraries::add('test_app', array('path' => $testApp)); $body = '<?php echo isset($this->_options[$option]) ? $this->_options[$option] : ""; ?>'; $template = $viewDir . '/template.html.php'; file_put_contents($template, $body); $view = new View(array('paths' => array('template' => '{:library}/views/{:template}.html.php', 'layout' => false))); $options = array('template' => 'template', 'library' => 'test_app'); $result = $view->render('all', array('option' => 'custom'), $options); $this->assertIdentical('', $result); $result = $view->render('all', array('option' => 'library'), $options); $this->assertIdentical('test_app', $result); $options = array('template' => 'template', 'library' => 'test_app', 'custom' => 'custom option'); $result = $view->render('all', array('option' => 'custom'), $options); $this->assertIdentical('custom option', $result); $result = $view->render('all', array('option' => 'library'), $options); $this->assertIdentical('test_app', $result); Libraries::remove('test_app'); $this->_cleanUp(); }
public function testAsset() { $result = Media::asset('foo/bar'); $this->assertEqual(LITHIUM_APP_PATH . '/mails/_assets/foo/bar', $result); Libraries::add('foo', array('path' => '/a/path')); $result = Media::asset('foo/bar', array('library' => 'foo')); $this->assertEqual('/a/path/mails/_assets/foo/bar', $result); Libraries::remove('foo'); $result = Media::asset('/foo/bar'); $this->assertEqual('/foo/bar', $result); $result = Media::asset('http://example.com/foo/bar'); $this->assertEqual('http://example.com/foo/bar', $result); $result = Media::asset('foo/bar', array('check' => true)); $this->assertFalse($result); }
public function testMultiLibraryAssetPaths() { $result = Media::asset('path/file', 'js', array('library' => 'app', 'base' => '/app/base')); $expected = '/app/base/js/path/file.js'; $this->assertEqual($expected, $result); Libraries::add('plugin', array('li3_foo_blog' => array('path' => LITHIUM_APP_PATH . '/libraries/plugins/blog', 'bootstrap' => false, 'route' => false))); $result = Media::asset('path/file', 'js', array('library' => 'li3_foo_blog', 'base' => '/app/base')); $expected = '/app/base/blog/js/path/file.js'; $this->assertEqual($expected, $result); Libraries::remove('li3_foo_blog'); }