コード例 #1
0
 public function testIndexアクションではページングの結果がpostsにセットされること()
 {
     $post = Fabricate::build('Post');
     $this->controller->Paginator->expects($this->once())->method('paginate')->will($this->returnValue($post->data));
     $vars = $this->testAction('/user/blog', ['method' => 'get', 'return' => 'vars']);
     $this->assertEquals($post->data, $vars['posts']);
 }
コード例 #2
0
ファイル: PostTest.php プロジェクト: eventargs/devblogapp
 /**
  * @dataProvider exampleValidationErrors
  */
 public function testバリデーションエラー($column, $value, $message)
 {
     //		$default = ['title'=>'タイトル','body'=>'本文'];
     //		$this->Post->create(array_merge($default,[$column=>$value]));
     $post = Fabricate::build('Post', [$column => $value]);
     $this->assertFalse($post->validates());
     $this->assertEquals([$message], $this->Post->validationErrors[$column]);
 }
コード例 #3
0
ファイル: PostTest.php プロジェクト: kobataka14/blogapp
 public function test一覧画面は特定ユーザーで5件新しい順である()
 {
     Fabricate::create('Post', 10, ['id' => false, 'title' => 'adminuser post', 'author_id' => '1']);
     Fabricate::create('Post', 10, ['id' => false, 'title' => 'user1 post', 'author_id' => '37i-9036514i9eoee1102920aououotel888']);
     $actual = $this->Post->find('all', $this->Post->getPaginateSettings('adminuser'));
     $this->assertCount(5, $actual);
     $this->assertEquals([10, 9, 8, 7, 6], Hash::extract($actual, '{n}.Post.id'));
     $this->assertEquals('adminuser post', $actual[0]['Post']['title']);
 }
コード例 #4
0
ファイル: PostTest.php プロジェクト: shibata-git/blogapp-1
 public function test一覧画面は特定ユーザで5件新しい順である()
 {
     Fabricate::create('Post', 10, ['id' => false, 'title' => 'adminuser post', 'author_id' => '1']);
     Fabricate::create('Post', 10, ['id' => false, 'title' => 'user1 post', 'author_id' => '37ea303a-3bdc-4251-b315-1316c0b300fa']);
     $actual = $this->Post->find('all', $this->Post->getPaginateSettings('adminuser'));
     $this->assertCount(5, $actual);
     $this->assertEquals([10, 9, 8, 7, 6], Hash::extract($actual, '{n}.Post.id'));
     $this->assertEquals('adminuser post', $actual[0]['Post']['title']);
 }
コード例 #5
0
 public function testIndexアクションではページングの結果がpostsにセットされること()
 {
     //		$data = [
     //			['Posts'=>['id'=>1,'title'=>'Title1', 'body'=>'Body1']],
     //		];
     $post = Fabricate::build('Post');
     $this->controller->Paginator->expects($this->once())->method('paginate')->will($this->returnValue($post->data));
     //paginateメソッドが返す値を$dataに設定。
     //テスト実行 testActionはcakephpのメソッド /user/blogにアクセスする。/hoge/fugaでもいい。te
     $vars = $this->testAction('/user/blog', ['method' => 'get', 'return' => 'vars']);
     //9
     //return => varsのところの補足
     /*
     vars:set()メソッドを使ってビューに渡された値を返却する、という意味
     view: レイアウトを覗いた部分のhtmlを返却
     contents: レイアウトを含めたhtmlを返却
     	     result: アクションがhtml描画でなく、returnで終了する場合の戻り値
     */
     $this->assertEquals($post->data, $vars['posts']);
 }
コード例 #6
0
ファイル: blog_posts_step.php プロジェクト: soda4708/blogapp
<?php

use Behat\Behat\Context\Step\Given, Behat\Behat\Context\Step\When, Behat\Behat\Context\Step\Then;
App::uses('Fabricate', 'Fabricate.Lib');
$steps->Given('/^"([^"]*)" としてログインしている$/', function ($world, $user) {
});
$steps->Given('/^記事が (\\d+) 件登録されている$/', function ($world, $num) {
    Fabricate::create('Post', $num, function ($data, $world) {
        return ['title' => $world->sequence('title', function ($i) {
            return "タイトル{$i}";
        })];
    });
});
$steps->When('/^自分の投稿を一覧表示する$/', function ($world) {
    return [new When('"' . Router::url(['controller' => 'posts', 'action' => 'index', 'user_account' => 'hoge']) . '" を表示している')];
});
$steps->Then('/^ページ (\\d+) に投稿が新しい順で (\\d+) 件表示されている$/', function ($world, $page, $count) {
    // アクティブなページ番号が異なればページ遷移する
    $active = $world->getSession()->getPage()->find('css', '.pagination .active a');
    if ($active && $page != $active->getText()) {
        $world->getSession()->getPage()->find('css', '.pagination')->clickLink($page);
    }
    // 記事の件数が期待通りか
    $world->assertSession()->elementsCount('css', 'article > section', $count);
    // 記事の一覧からタイトルを抽出する
    $titles = array_map(function ($section) {
        return $section->find('css', 'h1')->getText();
    }, $world->getSession()->getPage()->findAll('css', 'article > section'));
    // タイトルが降順かどうか
    $expect = array_chunk(array_map(function ($i) {
        return "タイトル{$i}";
コード例 #7
0
ファイル: PostTest.php プロジェクト: hysamyy/blogapp
 /**
  * @dataProvider exampleValidationErrors
  */
 public function testバリデーションエラー($column, $value, $message)
 {
     $post = Fabricate::build('Post', [$column => $value]);
     $this->assertFalse($post->validates());
     $this->assertEquals([$message], $this->Post->validationErrors[$column]);
 }
コード例 #8
0
ファイル: blog_posts_step.php プロジェクト: hayaei-mmg/phpDev
<?php

use Behat\Behat\Context\Step\Given, Behat\Behat\Context\Step\When, Behat\Behat\Context\Step\Then;
App::uses('Fabricate', 'Fabricate.Lib');
$steps->Given('/^"([^"]*)" としてログインしている$/', function ($world, $username) {
    $user = $world->getUser($username);
    return [new Given('"' . Router::url(['controller' => 'app_users', 'action' => 'login']) . '" を表示している'), new When('"Eメール" フィールドに "' . $user['email'] . '" と入力する'), new When('"パスワード" フィールドに "' . $user['password'] . '" と入力する'), new When('"ログイン" ボタンをクリックする')];
});
$steps->Given('/^"([^"]*)" の記事が (\\d+) 件登録されている$/', function ($world, $username, $num) {
    $user = $world->getUser($username);
    Fabricate::create('Post', $num, function ($data, $world) use($user) {
        return ['title' => $world->sequence('title', function ($i) {
            return "タイトル{$i}";
        }), 'author_id' => $user['id']];
    });
});
$steps->When('/^自分の投稿を一覧表示する$/', function ($world) {
    return [new When('"' . Router::url(['controller' => 'posts', 'action' => 'index', 'user_account' => 'testuser']) . '" を表示している')];
});
$steps->Then('/^ページ (\\d+) に投稿が新しい順で (\\d+) 件表示されている$/', function ($world, $page, $count) {
    $active = $world->getSession()->getPage()->find('css', '.pagination .active a');
    if ($active && $page != $active->getText()) {
        $world->getSession()->getPage()->find('css', '.pagination')->clickLink($page);
    }
    $world->assertSession()->elementsCount('css', 'article > section', $count);
    $titles = array_map(function ($section) {
        return $section->find('css', 'h1')->getText();
    }, $world->getSession()->getPage()->findAll('css', 'article > section'));
    $expect = array_chunk(array_map(function ($i) {
        return "タイトル{$i}";
    }, range($world->getModel('Post')->find('count'), 1)), 5)[$page - 1];
コード例 #9
0
ファイル: bootstrap.php プロジェクト: eventargs/devblogapp
<?php

App::uses('Fabricate', 'Fabricate.Lib');
Fabricate::config(function ($config) {
    $config->auto_validate = true;
});
コード例 #10
0
 /**
  * Only create model attributes array for association.
  *
  * @param mixed $association association name
  * @param int $recordCount count for creating.
  * @param mixed $callback callback or array can change fablicated data if you want to overwrite
  * @return array model attributes array.
  */
 public function association($association, $recordCount = 1, $callback = null)
 {
     if (!is_array($association)) {
         $association = [$association, 'association' => $association];
     }
     $attributes = Fabricate::association($association[0], $recordCount, $callback);
     if ($this->model) {
         $associations = $this->model->getAssociated();
         if (isset($associations[$association['association']]) && $associations[$association['association']] !== 'hasMany' && !empty($attributes)) {
             $attributes = $attributes[0];
         }
     }
     return $attributes;
 }