Beispiel #1
0
 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']);
 }
Beispiel #2
0
 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']);
 }
Beispiel #3
0
<?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}";
Beispiel #4
0
<?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];