Пример #1
0
 /**
  * Test setting Wordpress roles and should return Symfony roles
  */
 public function testWordpressRoles()
 {
     $wordpressRoles = array('author');
     $user = new User();
     $user->setWordpressRoles($wordpressRoles);
     $this->assertEquals(array('ROLE_WP_AUTHOR'), $user->getRoles());
 }
 /**
  * Test setting Wordpress roles and should return Symfony roles.
  */
 public function testWordpressRoles()
 {
     $wordpressRoles = ['author'];
     $user = new User();
     $user->setWordpressRoles($wordpressRoles);
     $this->assertEquals(['ROLE_WP_AUTHOR'], $user->getRoles());
 }
 /**
  * Test entity getters & setters
  */
 public function testGettersSetters()
 {
     $entity = new UserMeta();
     $user = new User();
     $user->setDisplayName('display name');
     $entity->setUser($user);
     $entity->setKey('fake key');
     $entity->setValue('fake value');
     $this->assertEquals('display name', $entity->getUser()->getDisplayName());
     $this->assertEquals('fake key', $entity->getKey());
     $this->assertEquals('fake value', $entity->getValue());
 }
 /**
  * Test onKernelResponse() & checkAuthentication() methods with a user logged in
  *
  * Should sets user token in security context if session key 'token' exists
  */
 public function testOnKernelRequestUserLogged()
 {
     // Fake Wordpress application to return a user logged in identifier
     $this->listener->expects($this->any())->method('getWordpressLoggedIdentifier')->will($this->returnValue(1));
     // Set up a request mock to give to GetResponseEvent class below
     $request = $this->getMock('\\Symfony\\Component\\HttpFoundation\\Request');
     $request->expects($this->any())->method('getSession')->will($this->returnValue($this->getSession()));
     $getResponseEvent = new GetResponseEvent($this->getMock('\\Symfony\\Component\\HttpKernel\\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST);
     // Run onKernelRequest() method
     $this->assertEquals(null, $this->securityContext->getToken(), 'Should returns no token');
     $user = new User();
     $token = new UsernamePasswordToken($user, $user->getPass(), 'secured_area', $user->getRoles());
     $getResponseEvent->getRequest()->getSession()->set('token', $token);
     $this->listener->onKernelRequest($getResponseEvent);
     $this->assertEquals($token, $this->securityContext->getToken(), 'Should returns previous token initialized');
 }
 /**
  * Test entity getters & setters
  */
 public function testGettersSetters()
 {
     $entity = new Comment();
     $entity->setAgent('agent');
     $entity->setApproved('approved');
     $entity->setAuthor('author');
     $entity->setAuthorEmail('*****@*****.**');
     $entity->setAuthorIp('1.2.3.4');
     $entity->setAuthorUrl('http://author.com');
     $entity->setContent('content');
     $date = new \DateTime();
     $entity->setDate($date);
     $entity->setDateGmt($date);
     $entity->setKarma(2);
     $parent = new Comment();
     $parent->setContent('parent content');
     $entity->setParent($parent);
     $post = new Post();
     $post->setTitle('post title');
     $entity->setPost($post);
     $entity->setType('type');
     $user = new User();
     $user->setDisplayName('author name');
     $entity->setUser($user);
     $this->assertEquals('agent', $entity->getAgent());
     $this->assertEquals('approved', $entity->getApproved());
     $this->assertEquals('author', $entity->getAuthor());
     $this->assertEquals('*****@*****.**', $entity->getAuthorEmail());
     $this->assertEquals('1.2.3.4', $entity->getAuthorIp());
     $this->assertEquals('http://author.com', $entity->getAuthorUrl());
     $this->assertEquals('content', $entity->getContent());
     $this->assertEquals($date, $entity->getDate());
     $this->assertEquals($date, $entity->getDateGmt());
     $this->assertEquals(2, $entity->getKarma());
     $this->assertEquals('parent content', $entity->getParent()->getContent());
     $this->assertEquals('post title', $entity->getPost()->getTitle());
     $this->assertEquals('type', $entity->getType());
     $this->assertEquals('author name', $entity->getUser()->getDisplayName());
 }
 /**
  * Test entity getters & setters.
  */
 public function testGettersSetters()
 {
     $entity = new Post();
     $user = new User();
     $user->setDisplayName('author name');
     $entity->setAuthor($user);
     $entity->setCommentCount(5);
     $entity->setCommentStatus('approved');
     $entity->setContent('post content');
     $entity->setContentFiltered('post content filtered');
     $date = new \DateTime();
     $entity->setDate($date);
     $entity->setDateGmt($date);
     $entity->setExcerpt('excerpt');
     $entity->setGuid('guid');
     $entity->setMenuOrder(2);
     $meta1 = new PostMeta();
     $meta1->setKey('meta key');
     $meta1->setValue('meta value');
     $meta1->setPost($entity);
     $collection = new ArrayCollection();
     $collection->add($meta1);
     $entity->setMetas($collection);
     $entity->setMimeType('text/html');
     $entity->setModified($date);
     $entity->setModifiedGmt($date);
     $entity->setName('post name');
     $parent = new Post();
     $parent->setTitle('parent post title');
     $entity->setParent($parent);
     $entity->setPassword('password');
     $entity->setPinged('pinged');
     $entity->setPingStatus('done');
     $entity->setStatus('published');
     $entity->setTitle('post title');
     $entity->setToPing('to ping');
     $entity->setType('post type');
     $this->assertEquals('author name', $entity->getAuthor()->getDisplayName());
     $this->assertEquals(5, $entity->getCommentCount());
     $this->assertEquals('approved', $entity->getCommentStatus());
     $this->assertEquals('post content', $entity->getContent());
     $this->assertEquals('post content filtered', $entity->getContentFiltered());
     $this->assertEquals($date, $entity->getDate());
     $this->assertEquals($date, $entity->getDateGmt());
     $this->assertEquals('excerpt', $entity->getExcerpt());
     $this->assertEquals('guid', $entity->getGuid());
     $this->assertEquals(2, $entity->getMenuOrder());
     $this->assertEquals($collection, $entity->getMetas());
     $this->assertEquals('text/html', $entity->getMimeType());
     $this->assertEquals($date, $entity->getModified());
     $this->assertEquals($date, $entity->getModifiedGmt());
     $this->assertEquals('post name', $entity->getName());
     $this->assertEquals('parent post title', $entity->getParent()->getTitle());
     $this->assertEquals('password', $entity->getPassword());
     $this->assertEquals('pinged', $entity->getPinged());
     $this->assertEquals('done', $entity->getPingStatus());
     $this->assertEquals('published', $entity->getStatus());
     $this->assertEquals('post title', $entity->getTitle());
     $this->assertEquals('to ping', $entity->getToPing());
     $this->assertEquals('post type', $entity->getType());
 }
 /**
  * Test onKernelResponse() & checkAuthentication() methods with a user logged in
  * and Wordpress catchall route is loaded (Wordpress should not be loaded).
  *
  * Should sets user token in security context if session key 'token' exists
  */
 public function testOnKernelRequestUserLoggedAndCatchallRoute()
 {
     // Fake Wordpress application to return a user logged in identifier
     $this->listener->expects($this->any())->method('getWordpressLoggedIdentifier')->will($this->returnValue(1));
     $user = new User();
     $token = new UsernamePasswordToken($user, $user->getPass(), 'secured_area', $user->getRoles());
     // Set up a request mock to give to GetResponseEvent class below
     $session = $this->getMock('\\Symfony\\Component\\HttpFoundation\\Session\\Session');
     $session->expects($this->any())->method('getName')->will($this->returnValue('session_test'));
     $session->expects($this->any())->method('has')->with($this->equalTo('token'))->will($this->returnValue(true));
     $session->expects($this->any())->method('get')->with($this->equalTo('token'))->will($this->returnValue($token));
     $request = new Request();
     $request->setSession($session);
     $request->attributes->set('_route', 'ekino_wordpress_catchall');
     $request->cookies->set($request->getSession()->getName(), true);
     // Ensure Wordpress is loaded as route is not the catch all route.
     $this->wordpress->expects($this->never())->method('loadWordpress');
     $getResponseEvent = new GetResponseEvent($this->getMock('\\Symfony\\Component\\HttpKernel\\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST);
     // Run onKernelRequest() method
     $this->assertEquals(null, $this->tokenStorage->getToken(), 'Should returns no token');
     $this->listener->onKernelRequest($getResponseEvent);
     $this->assertEquals($token, $this->tokenStorage->getToken(), 'Should returns previous token initialized');
 }