Skip to content

Commit

Permalink
Merge pull request #1346 from nanasess/improve/forgotcontrollertest
Browse files Browse the repository at this point in the history
ForgotController のテストケース
  • Loading branch information
chihiro-adachi committed Dec 21, 2015
2 parents 6bf637f + db4fc5b commit 631f151
Showing 1 changed file with 130 additions and 0 deletions.
130 changes: 130 additions & 0 deletions tests/Eccube/Tests/Web/ForgotControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

namespace Eccube\Tests\Web;

use Symfony\Component\HttpKernel\Exception as HttpException;

class ForgotControllerTest extends AbstractWebTestCase
{
public function setUp()
{
parent::setUp();
$this->initializeMailCatcher();
}

public function tearDown()
{
$this->cleanUpMailCatcherMessages();
parent::tearDown();
}

public function testIndex()
{
$client = $this->createClient();
$crawler = $client->request('GET', $this->app->url('forgot'));

$this->expected = 'パスワードの再発行';
$this->actual = $crawler->filter('h1.page-heading')->text();
$this->verify();

$this->assertTrue($client->getResponse()->isSuccessful());
}

public function testIndexWithPostAndVerify()
{
$Customer = $this->createCustomer();
$BaseInfo = $this->app['eccube.repository.base_info']->get();
$client = $this->createClient();

// パスワード再発行リクエスト
$crawler = $client->request(
'POST',
$this->app->url('forgot'),
array(
'login_email' => $Customer->getEmail(),
'_token' => 'dummy'
)
);
$this->assertTrue($client->getResponse()->isRedirect($this->app->url('forgot_complete')));

$customer_id = $Customer->getId();

// メール受信確認
$Messages = $this->getMailCatcherMessages();
$Message = $this->getMailCatcherMessage($Messages[0]->id);
$this->expected = '[' . $BaseInfo->getShopName() . '] パスワード変更のご確認';
$this->actual = $Message->subject;
$this->verify();
$this->cleanUpMailCatcherMessages();

$OrigCustomer = $this->app['eccube.repository.customer']->find($customer_id);
$key = $OrigCustomer->getResetKey();

$this->assertEquals(1, preg_match('|http://localhost(.*)|', $this->parseMailCatcherSource($Message), $urls));
$forgot_path = trim($urls[1]);

// メール URL クリック
$crawler = $client->request(
'GET',
$forgot_path
);
$this->assertTrue($client->getResponse()->isSuccessful());

$this->expected = 'パスワード変更(完了ページ)';
$this->actual = $crawler->filter('h1.page-heading')->text();
$this->verify();

// 再発行メール受信確認
$Messages = $this->getMailCatcherMessages();
$Message = $this->getMailCatcherMessage($Messages[0]->id);
$this->expected = '[' . $BaseInfo->getShopName() . '] パスワード変更のお知らせ';
$this->actual = $Message->subject;
$this->verify();

$this->assertRegexp('/新しいパスワード:[a-zA-Z0-9]/u', $this->parseMailCatcherSource($Message));
}

public function testComplete()
{
$client = $this->createClient();
$crawler = $client->request('GET', $this->app->url('forgot_complete'));

$this->expected = 'パスワード発行メールの送信 完了';
$this->actual = $crawler->filter('h1.page-heading')->text();
$this->verify();

$this->assertTrue($client->getResponse()->isSuccessful());
}

public function testResetWithDenied()
{
$client = $this->createClient();
try {
$crawler = $client->request(
'GET',
'/forgot/reset/a___aaa'
);
$this->fail();
} catch (\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException $e) {
$this->expected = '不正なアクセスです。';
$this->actual = $e->getMessage();
}
$this->verify();
}

public function testResetWithNotFound()
{
$client = $this->createClient();
try {
$crawler = $client->request(
'GET',
'/forgot/reset/aaaa'
);
$this->fail();
} catch (\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e) {
$this->expected = '有効期限が切れているか、無効なURLです。';
$this->actual = $e->getMessage();
}
$this->verify();
}
}

0 comments on commit 631f151

Please sign in to comment.