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
92 $this->session = M::mock(
'Symfony\Component\HttpFoundation\Session\SessionInterface');
95 $container = M::mock(
'Container');
97 $this->
menu = M::mock(Menu::class);
98 $this->twigEnvironment = M::mock(
'\Twig_Environment');
99 $this->logger = M::mock(
'Monolog\Logger');
101 $container->shouldReceive(
'get')->with(
'ui.component.menu')->andReturn($this->
menu);
102 $container->shouldReceive(
'get')->with(
'ui.component.micromenu')->andReturn($this->microMenu);
103 $container->shouldReceive(
'get')->with(
'twig.environment')->andReturn($this->twigEnvironment);
104 $container->shouldReceive(
'get')->with(
'logger')->andReturn($this->logger);
105 $container->shouldReceive(
'get')->with(
'session')->andReturn($this->session);
106 $this->container = $container;
107 $GLOBALS[
'container'] = $container;
112 protected function tearDown() :
void
117 public function testGetName()
119 assertThat($this->plugin->getName(), is($this->name));
122 public function testGetTitle()
124 assertThat($this->plugin->getTitle(), is(nullValue()));
127 $this->plugin =
new TestPlugin($this->name, array(TestPlugin::TITLE => $title));
129 assertThat($this->plugin->getTitle(), is($title));
132 public function testGetPermission()
141 public function testIsRequiresLogin()
143 $this->assertTrue($this->plugin->isRequiresLogin());
145 $this->plugin =
new TestPlugin($this->name, array(TestPlugin::REQUIRES_LOGIN =>
false));
147 $this->assertFalse($this->plugin->isRequiresLogin());
150 public function testGetPluginLevel()
152 assertThat($this->plugin->getPluginLevel(), is(10));
154 $this->plugin =
new TestPlugin($this->name, array(TestPlugin::LEVEL => 5));
156 assertThat($this->plugin->getPluginLevel(), is(5));
159 public function testGetDependencies()
161 assertThat($this->plugin->getDependency(), is(emptyArray()));
163 $dependencies = array(
'foo',
'bar');
164 $this->plugin =
new TestPlugin($this->name, array(TestPlugin::DEPENDENCIES => $dependencies));
166 assertThat($this->plugin->getDependency(), is($dependencies));
169 public function testGetInitOrder()
171 assertThat($this->plugin->getInitOrder(), is(0));
173 $this->plugin =
new TestPlugin($this->name, array(TestPlugin::INIT_ORDER => 15));
175 assertThat($this->plugin->getInitOrder(), is(15));
178 public function testExceptionWhenLoginIsRequired()
180 $this->expectException(Exception::class);
181 $this->expectExceptionMessage(
"not allowed without login");
182 $this->plugin->getResponse();
185 public function testSessionIsWrappedInRequest()
187 $this->logger->shouldReceive(
"debug")->once()->with(startsWith(
"handle request in"));
189 $this->plugin =
new TestPlugin($this->name, array(TestPlugin::REQUIRES_LOGIN =>
false));
191 $this->plugin->getResponse();
193 $request = $this->plugin->getTestRequest();
195 assertThat($request->getSession(), is($this->session));
198 public function testIsLoggedIn()
201 unset($_SESSION[
'User']);
202 assertThat($this->plugin->isLoggedIn(), is(equalTo(
false)));
203 $_SESSION[
'User'] =
'Default User';
204 assertThat($this->plugin->isLoggedIn(), is(equalTo(
false)));
205 $_SESSION[
'User'] =
'resU tlaufeD';
206 assertThat($this->plugin->isLoggedIn(), is(equalTo(
true)));
207 $this->addToAssertionCount(3);
Contains the constants and helpers for authentication of user.
int response
Is a response expected from the scheduler.