8 namespace Fossology\Lib\Plugin;
16 use Symfony\Component\DependencyInjection\Container;
17 use Symfony\Component\HttpFoundation\Request;
18 use Symfony\Component\HttpFoundation\Response;
19 use Symfony\Component\HttpFoundation\Session\Session;
30 public function __construct($title, $parameters = array())
32 parent::__construct($title, $parameters);
41 protected function handle(Request $request)
43 $this->request = $request;
45 return $this->response;
53 return $this->request;
61 return $this->response;
67 private $name =
"<name>";
73 private $twigEnvironment;
90 protected function setUp() :
void
94 $this->session = M::mock(
'Symfony\Component\HttpFoundation\Session\SessionInterface');
97 $container = M::mock(
'Container');
99 $this->
menu = M::mock(Menu::class);
100 $this->twigEnvironment = M::mock(
'\Twig_Environment');
101 $this->logger = M::mock(
'Monolog\Logger');
103 $container->shouldReceive(
'get')->with(
'ui.component.menu')->andReturn($this->
menu);
104 $container->shouldReceive(
'get')->with(
'ui.component.micromenu')->andReturn($this->microMenu);
105 $container->shouldReceive(
'get')->with(
'twig.environment')->andReturn($this->twigEnvironment);
106 $container->shouldReceive(
'get')->with(
'logger')->andReturn($this->logger);
107 $container->shouldReceive(
'get')->with(
'session')->andReturn($this->session);
108 $this->container = $container;
109 $GLOBALS[
'container'] = $container;
114 protected function tearDown() :
void
119 public function testGetName()
121 assertThat($this->plugin->getName(), is($this->name));
124 public function testGetTitle()
126 assertThat($this->plugin->getTitle(), is(nullValue()));
129 $this->plugin =
new TestPlugin($this->name, array(TestPlugin::TITLE => $title));
131 assertThat($this->plugin->getTitle(), is($title));
134 public function testGetPermission()
143 public function testIsRequiresLogin()
145 $this->assertTrue($this->plugin->isRequiresLogin());
147 $this->plugin =
new TestPlugin($this->name, array(TestPlugin::REQUIRES_LOGIN =>
false));
149 $this->assertFalse($this->plugin->isRequiresLogin());
152 public function testGetPluginLevel()
154 assertThat($this->plugin->getPluginLevel(), is(10));
156 $this->plugin =
new TestPlugin($this->name, array(TestPlugin::LEVEL => 5));
158 assertThat($this->plugin->getPluginLevel(), is(5));
161 public function testGetDependencies()
163 assertThat($this->plugin->getDependency(), is(emptyArray()));
165 $dependencies = array(
'foo',
'bar');
166 $this->plugin =
new TestPlugin($this->name, array(TestPlugin::DEPENDENCIES => $dependencies));
168 assertThat($this->plugin->getDependency(), is($dependencies));
171 public function testGetInitOrder()
173 assertThat($this->plugin->getInitOrder(), is(0));
175 $this->plugin =
new TestPlugin($this->name, array(TestPlugin::INIT_ORDER => 15));
177 assertThat($this->plugin->getInitOrder(), is(15));
180 public function testExceptionWhenLoginIsRequired()
182 $this->expectException(Exception::class);
183 $this->expectExceptionMessage(
"not allowed without login");
184 $this->plugin->getResponse();
187 public function testSessionIsWrappedInRequest()
189 $this->logger->shouldReceive(
"debug")->once()->with(startsWith(
"handle request in"));
191 $this->plugin =
new TestPlugin($this->name, array(TestPlugin::REQUIRES_LOGIN =>
false));
193 $this->plugin->getResponse();
195 $request = $this->plugin->getTestRequest();
197 assertThat($request->getSession(), is($this->session));
200 public function testIsLoggedIn()
203 unset($_SESSION[
'User']);
204 assertThat($this->plugin->isLoggedIn(), is(equalTo(
false)));
205 $_SESSION[
'User'] =
'Default User';
206 assertThat($this->plugin->isLoggedIn(), is(equalTo(
false)));
207 $_SESSION[
'User'] =
'resU tlaufeD';
208 assertThat($this->plugin->isLoggedIn(), is(equalTo(
true)));
209 $this->addToAssertionCount(3);
Contains the constants and helpers for authentication of user.
int response
Is a response expected from the scheduler.