public function testConstructSuccess()
 {
     $this->specify('Workflow source construct default', function () {
         $src = new WorkflowFileSource();
         expect($src->getClassMapByType(WorkflowFileSource::TYPE_WORKFLOW))->equals('raoul2000\\workflow\\base\\Workflow');
         expect($src->getClassMapByType(WorkflowFileSource::TYPE_STATUS))->equals('raoul2000\\workflow\\base\\Status');
         expect($src->getClassMapByType(WorkflowFileSource::TYPE_TRANSITION))->equals('raoul2000\\workflow\\base\\Transition');
         expect($src->getDefinitionCache())->equals(null);
         expect($src->getDefinitionLoader())->notNull();
     });
     $this->specify('Workflow source construct with class map', function () {
         $src = new WorkflowFileSource(['classMap' => [WorkflowFileSource::TYPE_WORKFLOW => 'my\\namespace\\Workflow', WorkflowFileSource::TYPE_STATUS => 'my\\namespace\\Status', WorkflowFileSource::TYPE_TRANSITION => 'my\\namespace\\Transition']]);
         expect($src->getClassMapByType(WorkflowFileSource::TYPE_WORKFLOW))->equals('my\\namespace\\Workflow');
         expect($src->getClassMapByType(WorkflowFileSource::TYPE_STATUS))->equals('my\\namespace\\Status');
         expect($src->getClassMapByType(WorkflowFileSource::TYPE_TRANSITION))->equals('my\\namespace\\Transition');
     });
     $this->specify('Workflow source construct with cache', function () {
         // initialized by array
         $src = new WorkflowFileSource(['definitionCache' => ['class' => 'yii\\caching\\FileCache']]);
         expect_that($src->getDefinitionCache() instanceof yii\caching\FileCache);
         // initialized by component ID
         Yii::$app->set('myCache', ['class' => 'yii\\caching\\FileCache']);
         $src = new WorkflowFileSource(['definitionCache' => 'myCache']);
         expect_that($src->getDefinitionCache() instanceof yii\caching\FileCache);
         // initialized by object
         $cache = Yii::$app->get('myCache');
         Yii::$app->set('myCache', ['class' => 'yii\\caching\\FileCache']);
         $src = new WorkflowFileSource(['definitionCache' => $cache]);
         expect_that($src->getDefinitionCache() instanceof yii\caching\FileCache);
     });
 }
Ejemplo n.º 2
0
 public function testLoginCorrect()
 {
     $this->_model = new LoginForm(['email' => '*****@*****.**', 'password' => '123123']);
     expect_that($this->_model->login());
     expect_not(Yii::$app->user->isGuest);
     expect($this->_model->errors)->hasntKey('password');
 }
Ejemplo n.º 3
0
 public function testIsSuperUser()
 {
     $authItem = new AuthItem();
     expect_not($authItem->isSuperUser());
     $authItem->name = User::ROLE_SUPERUSER;
     expect_that($authItem->isSuperUser());
 }
Ejemplo n.º 4
0
 public function testLoginCorrect()
 {
     $this->model = new LoginForm(['username' => 'demo', 'password' => 'demo']);
     expect_that($this->model->login());
     expect_not(\Yii::$app->user->isGuest);
     expect($this->model->errors)->hasntKey('password');
 }
Ejemplo n.º 5
0
 /**
  * @depends testFindUserByUsername
  */
 public function testValidateUser($user)
 {
     $user = User::findByUsername('admin');
     expect_that($user->validateAuthKey('test100key'));
     expect_not($user->validateAuthKey('test102key'));
     expect_that($user->validatePassword('admin'));
     expect_not($user->validatePassword('123456'));
 }
Ejemplo n.º 6
0
 public function testNotCorrectSignup()
 {
     $model = new SignupForm(['username' => 'troy.becker', 'email' => '*****@*****.**', 'password' => 'some_password']);
     expect_not($model->signup());
     expect_that($model->getErrors('username'));
     expect_that($model->getErrors('email'));
     expect($model->getFirstError('username'))->equals('This username has already been taken.');
     expect($model->getFirstError('email'))->equals('This email address has already been taken.');
 }
Ejemplo n.º 7
0
 /**
  * @depends testFindUserByUsername
  */
 public function testValidateUser()
 {
     /** @var User $user */
     $user = User::find()->where(['username' => 'neo'])->one();
     expect_that($user->validateAuthKey('neo'));
     expect_not($user->validateAuthKey('test102key'));
     //expect_that($user->validatePassword('neo'));
     //expect_not($user->validatePassword('123456'));
 }
 public function testRegister()
 {
     $this->provider->shouldReceive('mergeConfigFrom')->with(Mockery::type('string'), 'ray_emitter')->once();
     App::shouldReceive('singleton')->with('rayemitter.store', Mockery::on(function ($closure) {
         $result = $closure();
         expect_that($result);
         expect($result instanceof Store)->true();
         return true;
     }))->once();
     expect_not($this->provider->register());
 }
Ejemplo n.º 9
0
 public function testSuccess()
 {
     $user = User::findByEmail('*****@*****.**');
     expect_not($user->isConfirmed());
     $form = new ConfirmEmailForm();
     expect_that($form->validateToken($user->email_confirm_token));
     expect_that($form->confirmEmail());
     $user = User::findByEmail($user->email);
     expect($user->email_confirm_token)->isEmpty();
     expect_that($user->isConfirmed());
 }
Ejemplo n.º 10
0
 public function testWorkflowAccessorSuccess()
 {
     $src = new WorkflowFileSource();
     $src->addWorkflowDefinition('wid', ['initialStatusId' => 'A', 'status' => ['A' => ['label' => 'label A', 'transition' => ['B', 'C']], 'B' => [], 'C' => []]]);
     $w = $src->getWorkflow('wid');
     verify_that($w != null);
     $this->specify('initial status can be obtained through workflow', function () use($w) {
         expect_that($w->getInitialStatus() instanceof StatusInterface);
         expect_that($w->getInitialStatus()->getId() == $w->getInitialStatusId());
     });
 }
Ejemplo n.º 11
0
 public function testUpdate()
 {
     $user = $this->tester->grabFixture('user', 'user-2');
     $user->profile->full_name = 'Test';
     $user->profile->birth_day = '2001-01-02';
     expect_that($user->save());
     $user = $this->tester->grabFixture('user', 'user-2');
     expect($user)->isInstanceOf('app\\models\\User');
     expect($user->profile->full_name)->equals('Test');
     expect($user->profile->birth_day)->equals('2001-01-02');
 }
Ejemplo n.º 12
0
 public function testSuccess()
 {
     $user = $this->tester->grabFixture('user', 'user-1');
     $form = new ResetPasswordForm();
     $form->password = '******';
     expect_that($form->validateToken($user->password_reset_token));
     expect_that($form->resetPassword());
     $user = User::findByEmail($user->email);
     expect($user->password_reset_token)->isEmpty();
     expect_that($user->validatePassword('password-new'));
 }
Ejemplo n.º 13
0
 public function testCheckFakePermission()
 {
     $config = Yii::getAlias('@app/tests/_data/rbac/permissions.php');
     $auth = Yii::$app->authManager;
     $permission = $auth->createPermission('test');
     $auth->add($permission);
     expect_that($auth->getPermission('test'));
     $command = new RbacController('test', 'test');
     $command->path = $config;
     $command->beforeAction('test');
     $command->actionUp();
     expect_not($auth->getPermission('test'));
 }
 public function testSendEmailSuccessfully()
 {
     $userFixture = $this->tester->grabFixture('user', 0);
     $model = new PasswordResetRequestForm();
     $model->email = $userFixture['email'];
     $user = User::findOne(['password_reset_token' => $userFixture['password_reset_token']]);
     expect_that($model->sendEmail());
     expect_that($user->password_reset_token);
     $emailMessage = $this->tester->grabLastSentEmail();
     expect('valid email is sent', $emailMessage)->isInstanceOf('yii\\mail\\MessageInterface');
     expect($emailMessage->getTo())->hasKey($model->email);
     expect($emailMessage->getFrom())->hasKey(Yii::$app->params['supportEmail']);
 }
 public function testLeaveNewOnDelete()
 {
     $post = new Item06();
     $post->name = 'post name';
     $post->enterWorkflow();
     verify($post->save())->true();
     verify($post->getWorkflowStatus()->getId())->equals('Item06Workflow/new');
     $post->canLeaveWorkflow(true);
     Item06Behavior::$countBeforeLeaveNew = 0;
     Item06Behavior::$countAfterLeaveNew = 0;
     expect_that($post->delete());
     expect('the beforeLeaveNew has been called once', Item06Behavior::$countBeforeLeaveNew)->equals(1);
     expect('the afterLeaveNew has been called once', Item06Behavior::$countAfterLeaveNew)->equals(1);
 }
Ejemplo n.º 16
0
 public function testStatusEqualsSuccess()
 {
     $item = new Item04();
     expect_that($item->statusEquals());
     expect_that($item->statusEquals(null));
     expect_that($item->statusEquals(''));
     expect_that($item->statusEquals([]));
     expect_that($item->statusEquals(0));
     $item->sendToStatus('A');
     expect_that($item->statusEquals('A'));
     expect_that($item->statusEquals('Item04Workflow/A'));
     $itself = $item->getWorkflowStatus();
     expect_that($item->statusEquals($itself));
 }
Ejemplo n.º 17
0
 public function testSendEmail()
 {
     $model = new ContactForm();
     $model->attributes = ['name' => 'Tester', 'email' => '*****@*****.**', 'subject' => 'very important letter subject', 'body' => 'body of current message'];
     expect_that($model->sendEmail('*****@*****.**'));
     // using Yii2 module actions to check email was sent
     $this->tester->seeEmailIsSent();
     $emailMessage = $this->tester->grabLastSentEmail();
     expect('valid email is sent', $emailMessage)->isInstanceOf('yii\\mail\\MessageInterface');
     expect($emailMessage->getTo())->hasKey('*****@*****.**');
     expect($emailMessage->getFrom())->hasKey('*****@*****.**');
     expect($emailMessage->getSubject())->equals('very important letter subject');
     expect($emailMessage->toString())->contains('body of current message');
 }
 public function testSuccess()
 {
     $user = $this->tester->grabFixture('user', 'user-1');
     $form = new PasswordResetRequestForm();
     $form->email = '*****@*****.**';
     expect_that($form->validate());
     expect_that($form->sendEmail());
     $user = User::findOne(['password_reset_token' => $user->password_reset_token]);
     expect($user->password_reset_token)->notNull();
     $message = $this->tester->grabLastSentEmail();
     expect('valid email is sent', $message)->isInstanceOf('yii\\mail\\MessageInterface');
     expect($message->getTo())->hasKey($form->email);
     expect($message->getFrom())->hasKey('*****@*****.**');
 }
Ejemplo n.º 19
0
 public function testEmailIsSentOnContact()
 {
     /** @var ContactForm $model */
     $this->model = $this->getMockBuilder('app\\models\\ContactForm')->setMethods(['validate'])->getMock();
     $this->model->expects($this->once())->method('validate')->will($this->returnValue(true));
     $this->model->attributes = ['name' => 'Tester', 'email' => '*****@*****.**', 'subject' => 'very important letter subject', 'body' => 'body of current message'];
     expect_that($this->model->contact('*****@*****.**'));
     // using Yii2 module actions to check email was sent
     $this->tester->seeEmailIsSent();
     $emailMessage = $this->tester->grabLastSentEmail();
     expect('valid email is sent', $emailMessage)->isInstanceOf('yii\\mail\\MessageInterface');
     expect($emailMessage->getTo())->hasKey('*****@*****.**');
     expect($emailMessage->getFrom())->hasKey('*****@*****.**');
     expect($emailMessage->getSubject())->equals('very important letter subject');
     expect($emailMessage->toString())->contains('body of current message');
 }
Ejemplo n.º 20
0
 public function testSuccess()
 {
     $form = new SignupForm(['fullName' => 'Test', 'email' => '*****@*****.**', 'password' => 'test_password']);
     $user = $form->signup();
     expect($user)->isInstanceOf('app\\models\\User');
     expect_not($user->isConfirmed());
     expect($user->email)->equals('*****@*****.**');
     expect_that($user->validatePassword('test_password'));
     expect_that($form->sendEmail());
     $user = User::findByEmail('*****@*****.**');
     expect($user->profile->full_name)->equals('Test');
     $message = $this->tester->grabLastSentEmail();
     expect('valid email is sent', $message)->isInstanceOf('yii\\mail\\MessageInterface');
     expect($message->getTo())->hasKey($user->email);
     expect($message->getFrom())->hasKey('*****@*****.**');
 }
Ejemplo n.º 21
0
 public function testSetStatusAssignedSuccess()
 {
     $o = new Item08();
     $o->status = 'draft';
     $o->status_ex = 'success';
     expect_that($o->save());
     verify_that($o->status == 'Item08Workflow1/draft');
     verify_that($o->status_ex == 'Item08Workflow2/success');
     $o = new Item08();
     $o->status = 'draft';
     expect_that($o->save());
     verify_that($o->status == 'Item08Workflow1/draft');
     verify_that($o->status_ex == null);
     $o = new Item08();
     $o->status_ex = 'success';
     expect_that($o->save());
     verify_that($o->status == null);
     verify_that($o->status_ex == 'Item08Workflow2/success');
 }
 public function testLeaveWorkflowOnDelete()
 {
     $post = new Item06();
     $post->name = 'post name';
     $post->enterWorkflow();
     verify($post->save())->true();
     verify($post->getWorkflowStatus()->getId())->equals('Item06Workflow/new');
     Item06Behavior::$countLeaveWorkflow = 0;
     $post->canLeaveWorkflow(true);
     expect_that($post->delete());
     verify(Item06Behavior::$countLeaveWorkflow)->equals(1);
     $post = new Item06();
     $post->name = 'post name';
     $post->enterWorkflow();
     verify($post->save())->true();
     verify($post->getWorkflowStatus()->getId())->equals('Item06Workflow/new');
     $post->canLeaveWorkflow(false);
     // refuse leave workflow
     // Now, the handler attached to the beforeLeaveWorkflow Event (see Item06Behavior)
     // will invalidate the event and return false (preventing the DELETE operation)
     expect_not($post->delete());
 }
Ejemplo n.º 23
0
 public function testFindUserByUsername()
 {
     expect_that($user = User::find()->where(['username' => 'neozzz'])->one());
     expect_not(User::find()->where(['username' => 'neo'])->one());
 }
Ejemplo n.º 24
0
 public function testSuccess()
 {
     $form = new LoginForm(['email' => '*****@*****.**', 'password' => '123123']);
     expect_that($form->login());
     expect($form->errors)->isEmpty();
     expect_not(Yii::$app->user->isGuest);
 }
Ejemplo n.º 25
0
 public function testCountOptions()
 {
     $command = new CreateLocalConfigController('test', 'test');
     expect_that(is_array($command->options()));
     expect(count($command->options()))->equals(1);
 }
Ejemplo n.º 26
0
 public function testSuccess()
 {
     $form = new LoginForm(['username' => 'superuser', 'password' => 'fghfgh']);
     expect_that($form->login());
     expect($form->errors)->isEmpty();
     expect_not(Yii::$app->user->isGuest);
 }
Ejemplo n.º 27
0
 public function testExpectFunctions()
 {
     expect(12)->equals(12);
     expect_that(true);
     expect_not(false);
 }
Ejemplo n.º 28
0
 public function testStatusAccessorSuccess()
 {
     $this->src->addWorkflowDefinition('wid', ['initialStatusId' => 'A', 'status' => ['A' => ['label' => 'label A', 'transition' => ['B', 'C']], 'B' => [], 'C' => []]]);
     $w = $this->src->getWorkflow('wid');
     verify_that($w != null);
     $this->specify('transitions can be obtained through status', function () {
         $status = $this->src->getStatus('wid/A');
         expect_that($status != null);
         $tr = $status->getTransitions();
         expect_that(is_array($tr));
         expect(count($tr))->equals(2);
         $keys = array_keys($tr);
         expect($keys)->equals(['wid/B', 'wid/C']);
         expect_that($tr['wid/B'] instanceof TransitionInterface);
         expect_that($tr['wid/C'] instanceof TransitionInterface);
     });
     $this->specify('parent workflow can be obtained through status', function () {
         $status = $this->src->getStatus('wid/A');
         expect_that($status != null);
         $wrk = $status->getWorkflow();
         expect_that($wrk != null);
         verify_that($wrk instanceof WorkflowInterface);
         verify($wrk->getId())->equals('wid');
     });
 }
Ejemplo n.º 29
0
 public function testValidateFailsOnToStatus()
 {
     /** @var ActiveWorkflowBehavior|Item05 $model */
     $model = new Item05();
     $model->sendToStatus('Item05Workflow/new');
     $model->sendToStatus('Item05Workflow/correction');
     expect_that($model->getWorkflowStatus()->getId() == 'Item05Workflow/correction');
     $this->specify('model validation success on enter status "published" for attribute "author"', function () use($model) {
         $model->status = 'Item05Workflow/published';
         $model->tags = 'some tag';
         $model->author = null;
         verify('validation error', $model->validate())->false();
         verify('the model has errors', $model->hasErrors())->true();
         verify('the model has exactly one error', count($model->getErrors()) == 1)->true();
         verify('the correct error message is set', $model->getFirstError('author'))->equals('Author cannot be blank.');
     });
 }
 public function testResetCorrectToken()
 {
     $user = $this->tester->grabFixture('user', 0);
     $form = new ResetPasswordForm($user['password_reset_token']);
     expect_that($form->resetPassword());
 }