Browse Source

fix a pile of test fails

still some to go
AD7six 11 years ago
parent
commit
28e468d9ce

+ 3 - 3
src/Template/Bake/Controller/Action/add.ctp

@@ -31,8 +31,8 @@
 		}
 <%
 		$associations = array_merge(
-			$this->Bake->aliasExtractor($modelObj, 'belongsTo'),
-			$this->Bake->aliasExtractor($modelObj, 'belongsToMany')
+			$this->Bake->aliasExtractor($modelObj, 'BelongsTo'),
+			$this->Bake->aliasExtractor($modelObj, 'BelongsToMany')
 		);
 		foreach ($associations as $assoc):
 			$association = $modelObj->association($assoc);
@@ -44,5 +44,5 @@
 			$compact[] = "'$otherPlural'";
 		endforeach;
 %>
-		$this->set(compact(" <%= join(', ', $compact) %> "));
+		$this->set(compact(<%= join(', ', $compact) %>));
 	}

+ 6 - 10
src/Template/Bake/Controller/Action/edit.ctp

@@ -13,8 +13,8 @@
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
 
-$belongsTo = $this->Bake->aliasExtractor($modelObj, 'belongsTo');
-$belongsToMany = $this->Bake->aliasExtractor($modelObj, 'belongsToMany');
+$belongsTo = $this->Bake->aliasExtractor($modelObj, 'BelongsTo');
+$belongsToMany = $this->Bake->aliasExtractor($modelObj, 'BelongsToMany');
 %>
 <% $compact = ["'" . $singularName . "'"]; %>
 /**
@@ -26,7 +26,7 @@ $belongsToMany = $this->Bake->aliasExtractor($modelObj, 'belongsToMany');
  */
 	public function edit($id = null) {
 		$<%= $singularName %> = $this-><%= $currentModelName %>->get($id, [
-			'contain' => [<%= $this->Bake->stringifyList($belongsToMany, ['indent' => 4]) %>]
+			'contain' => [<%= $this->Bake->stringifyList($belongsToMany, ['indent' => false]) %>]
 		]);
 		if ($this->request->is(['patch', 'post', 'put'])) {
 			$<%= $singularName %> = $this-><%= $currentModelName %>->patchEntity($<%= $singularName %>, $this->request->data);
@@ -38,19 +38,15 @@ $belongsToMany = $this->Bake->aliasExtractor($modelObj, 'belongsToMany');
 			}
 		}
 <%
-		$associations = array_merge(
-			$this->Bake->aliasExtractor($modelObj, 'belongsTo'),
-			$this->Bake->aliasExtractor($modelObj, 'belongsToMany')
-		);
-		foreach ($associations as $assoc):
+		foreach (array_merge($belongsTo, $belongsToMany) as $assoc):
 			$association = $modelObj->association($assoc);
 			$otherName = $association->target()->alias();
 			$otherPlural = $this->_variableName($otherName);
 %>
 		$<%= $otherPlural %> = $this-><%= $currentModelName %>-><%= $otherName %>->find('list');
 <%
-			$compact[] = "'<%= $otherPlural %>'";
+			$compact[] = "'$otherPlural'";
 		endforeach;
 %>
-		$this->set(compact(" <%= join(', ', $compact) %> "));
+		$this->set(compact(<%= join(', ', $compact) %>));
 	}

+ 2 - 2
src/Template/Bake/Controller/Action/index.ctp

@@ -19,10 +19,10 @@
  * @return void
  */
 	public function index() {
-<% $belongsTo = $this->Bake->aliasExtractor($modelObj, 'belongsTo'); %>
+<% $belongsTo = $this->Bake->aliasExtractor($modelObj, 'BelongsTo'); %>
 <% if ($belongsTo): %>
 		$this->paginate = [
-			'contain' => [<%= $this->Bake->stringifyList($belongsTo, ['indent' => 4]) %>]
+			'contain' => [<%= $this->Bake->stringifyList($belongsTo, ['indent' => false]) %>]
 		];
 <% endif; %>
 		$this->set('<%= $pluralName %>', $this->paginate($this-><%= $currentModelName %>));

+ 3 - 3
src/Template/Bake/Controller/Action/view.ctp

@@ -13,8 +13,8 @@
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
 $allAssociations = array_merge(
-	$this->Bake->aliasExtractor($modelObj, 'belongsTo'),
-	$this->Bake->aliasExtractor($modelObj, 'belongsToMany'),
+	$this->Bake->aliasExtractor($modelObj, 'BelongsTo'),
+	$this->Bake->aliasExtractor($modelObj, 'BelongsToMany'),
 	$this->Bake->aliasExtractor($modelObj, 'HasOne'),
 	$this->Bake->aliasExtractor($modelObj, 'HasMany')
 );
@@ -28,7 +28,7 @@ $allAssociations = array_merge(
  */
 	public function view($id = null) {
 		$<%= $singularName%> = $this-><%= $currentModelName %>->get($id, [
-			'contain' => [<%= $this->Bake->stringifyList($allAssociations, ['indent' => 4]) %>]
+			'contain' => [<%= $this->Bake->stringifyList($allAssociations, ['indent' => false]) %>]
 		]);
 		$this->set('<%= $singularName %>', $<%= $singularName %>);
 	}

+ 2 - 0
src/Template/Bake/Controller/actions.ctp

@@ -4,3 +4,5 @@ foreach($actions as $action) {
 	$out[] = trim($this->render('/Controller/Action/' . $action, false));
 }
 echo implode("\n\n", $out);
+%>
+

+ 1 - 1
src/Template/Bake/Model/entity.ctp

@@ -43,6 +43,6 @@ class <%= $name %> extends Entity {
  *
  * @var array
  */
-	protected $_hidden = [<%= $this->Bake->stringifyList($hidden)];
+	protected $_hidden = [<%= $this->Bake->stringifyList($hidden) %>];
 <% endif %>
 }

+ 2 - 2
src/Template/Bake/Model/table.ctp

@@ -41,7 +41,7 @@ class <%= $name %>Table extends Table {
 <% endif %>
 <% if (!empty($primaryKey)): %>
 <% if (count($primaryKey) > 1): %>
-		$this->primaryKey([<%= $this->Bake->stringifyList($(array)$primaryKey, ['indent' => false]) %>]);
+		$this->primaryKey([<%= $this->Bake->stringifyList((array)$primaryKey, ['indent' => false]) %>]);
 <% else: %>
 		$this->primaryKey('<%= current((array)$primaryKey) %>');
 <% endif %>
@@ -51,7 +51,7 @@ class <%= $name %>Table extends Table {
 <% endforeach %>
 <% foreach ($associations as $type => $assocs): %>
 <% foreach ($assocs as $assoc): %>
-		$this-><%= $type %>('<%= $assoc['alias'] %>', [<?% $this->Bake->stringifyList($assoc, ['indent' => 3]) %>]);
+		$this-><%= $type %>('<%= $assoc['alias'] %>', [<%= $this->Bake->stringifyList($assoc, ['indent' => 3]) %>]);
 <% endforeach %>
 <% endforeach %>
 	}

+ 42 - 47
src/Template/Bake/Template/view.ctp

@@ -49,24 +49,24 @@ $groupedFields = collection($fields)
 	->toArray();
 
 $groupedFields += ['number' => [], 'string' => [], 'boolean' => [], 'date' => [], 'text' => []];
+$pk = "\$$singularVar->{$primaryKey[0]}";
 %>
 <div class="actions columns large-2 medium-3">
-	<h3><%= "<%= __('Actions') %>" %></h3>
+	<h3><?= __('Actions') ?></h3>
 	<ul class="side-nav">
+		<li><?= $this->Html->link(__('Edit <%= $singularHumanName %>'), ['action' => 'edit', <%= $pk %>]) ?> </li>
+		<li><?= $this->Form->postLink(__('Delete <%= $singularHumanName %>'), ['action' => 'delete', <%= $pk %>], ['confirm' => __('Are you sure you want to delete # <%= 0 %>?', <%= $pk %>)]) ?> </li>
+		<li><?= $this->Html->link(__('List <%= $pluralHumanName %>'), ['action' => 'index']) ?> </li>
+		<li><?= $this->Html->link(__('New <%= $singularHumanName %>'), ['action' => 'add']) ?> </li>
 <%
-	$pk = "\$<%= $singularVar %>-><%= $primaryKey[0] %>";
-
-	echo "\t\t<li><%= \$this->Html->link(__('Edit " . $singularHumanName . "'), ['action' => 'edit', <%= $pk %>]) %> </li>\n";
-	echo "\t\t<li><%= \$this->Form->postLink(__('Delete " . $singularHumanName . "'), ['action' => 'delete', <%= $pk %>], ['confirm' => __('Are you sure you want to delete # <%= 0 %>?', <%= $pk %>)]) %> </li>\n";
-	echo "\t\t<li><%= \$this->Html->link(__('List " . $pluralHumanName . "'), ['action' => 'index']) %> </li>\n";
-	echo "\t\t<li><%= \$this->Html->link(__('New " . $singularHumanName . "'), ['action' => 'add']) %> </li>\n";
-
 	$done = [];
 	foreach ($associations as $type => $data) {
 		foreach ($data as $alias => $details) {
 			if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
-				echo "\t\t<li><%= \$this->Html->link(__('List " . $this->_pluralHumanName($alias) . "'), ['controller' => '<%= $details['controller'] %>', 'action' => 'index']) %> </li>\n";
-				echo "\t\t<li><%= \$this->Html->link(__('New " . Inflector::humanize(Inflector::singularize(Inflector::underscore($alias))) . "'), ['controller' => '<%= $details['controller'] %>', 'action' => 'add']) %> </li>\n";
+%>
+		<li><?= $this->Html->link(__('List <%= $this->_pluralHumanName($alias) %>'), ['controller' => '<%= $details['controller'] %>', 'action' => 'index']) ?> </li>
+		<li><?= $this->Html->link(__('New <%= Inflector::humanize(Inflector::singularize(Inflector::underscore($alias))) %>'), ['controller' => '<%= $details['controller'] %>', 'action' => 'add']) ?> </li>
+<%
 				$done[] = $details['controller'];
 			}
 		}
@@ -75,7 +75,7 @@ $groupedFields += ['number' => [], 'string' => [], 'boolean' => [], 'date' => []
 	</ul>
 </div>
 <div class="<%= $pluralVar %> view large-10 medium-9 columns">
-	<h2><%= "<%= h(\$<%= $singularVar %>-><%= $displayField %>) %>"; %></h2>
+	<h2><?= h($<%= $singularVar %>-><%= $displayField %>) ?></h2>
 	<div class="row">
 <% if ($groupedFields['string']) : %>
 		<div class="large-5 columns strings">
@@ -83,11 +83,11 @@ $groupedFields += ['number' => [], 'string' => [], 'boolean' => [], 'date' => []
 <% if (isset($associationFields[$field])) :
 			$details = $associationFields[$field];
 %>
-			<h6 class="subheader"><%= "<%= __('" . Inflector::humanize($details['property']) . "') %>" %></h6>
-			<p><%= "<%= \$<%= $singularVar %>->has('<%= $details['property'] %>') ? \$this->Html->link(\$<%= $singularVar %>-><%= $details['property'] %>-><%= $details['displayField'] %>, ['controller' => '<%= $details['controller'] %>', 'action' => 'view', \$<%= $singularVar %>-><%= $details['property'] %>-><%= $details['primaryKey'][0] %>]) : '' %>" %></p>
+			<h6 class="subheader"><?= __('<%= Inflector::humanize($details['property']) %>') ?></h6>
+			<p><?= $<%= $singularVar %>->has('<%= $details['property'] %>') ? $this->Html->link($<%= $singularVar %>-><%= $details['property'] %>-><%= $details['displayField'] %>, ['controller' => '<%= $details['controller'] %>', 'action' => 'view', $<%= $singularVar %>-><%= $details['property'] %>-><%= $details['primaryKey'][0] %>]) : '' %>" ?></p>
 <% else : %>
-			<h6 class="subheader"><%= "<%= __('" . Inflector::humanize($field) . "') %>" %></h6>
-			<p><%= "<%= h(\$<%= $singularVar %>-><%= $field %>) %>" %></p>
+			<h6 class="subheader"><?= __('<%= Inflector::humanize($field) %>') ?></h6>
+			<p><?= h($<%= $singularVar %>-><%= $field %>) ?></p>
 <% endif; %>
 <% endforeach; %>
 		</div>
@@ -95,8 +95,8 @@ $groupedFields += ['number' => [], 'string' => [], 'boolean' => [], 'date' => []
 <% if ($groupedFields['number']) : %>
 		<div class="large-2 large-offset-1 columns numbers end">
 <% foreach ($groupedFields['number'] as $field) : %>
-			<h6 class="subheader"><%= "<%= __('" . Inflector::humanize($field) . "') %>" %></h6>
-			<p><%= "<%= \$this->Number->format(\$<%= $singularVar %>-><%= $field %>) %>" %></p>
+			<h6 class="subheader"><?= __('<%= Inflector::humanize($field) %>') ?></h6>
+			<p><?= $this->Number->format($<%= $singularVar %>-><%= $field %>) ?></p>
 <% endforeach; %>
 		</div>
 <% endif; %>
@@ -104,15 +104,15 @@ $groupedFields += ['number' => [], 'string' => [], 'boolean' => [], 'date' => []
 		<div class="large-2 columns dates end">
 <% foreach ($groupedFields['date'] as $field) : %>
 			<h6 class="subheader"><%= "<%= __('" . Inflector::humanize($field) . "') %>" %></h6>
-			<p><%= "<%= h(\$<%= $singularVar %>-><%= $field %>) %>" %></p>
+			<p><?= h($<%= $singularVar %>-><%= $field %>) ?></p>
 <% endforeach; %>
 		</div>
 <% endif; %>
 <% if ($groupedFields['boolean']) : %>
 		<div class="large-2 columns booleans end">
 <% foreach ($groupedFields['boolean'] as $field) : %>
-			<h6 class="subheader"><%= "<%= __('" . Inflector::humanize($field) . "') %>" %></h6>
-			<p><%= "<%= \$<%= $singularVar %>-><%= $field %> ? __('Yes') : __('No'); %>" %></p>
+			<h6 class="subheader"><?= __('<%= Inflector::humanize($field) %>') ?></h6>
+			<p><?= $<%= $singularVar %>-><%= $field %> ? __('Yes') : __('No'); ?></p>
 <% endforeach; %>
 		</div>
 <% endif; %>
@@ -121,8 +121,8 @@ $groupedFields += ['number' => [], 'string' => [], 'boolean' => [], 'date' => []
 <% foreach ($groupedFields['text'] as $field) : %>
 	<div class="row texts">
 		<div class="columns large-9">
-			<h6 class="subheader"><%= "<%= __('" . Inflector::humanize($field) . "') %>" %></h6>
-			<%= "<%= \$this->Text->autoParagraph(h(\$<%= $singularVar %>-><%= $field %>)); %>"; %>
+			<h6 class="subheader"><?= __('<$= Inflector::humanize($field) %>') ?></h6>
+			<?= $this->Text->autoParagraph(h($<%= $singularVar %>-><%= $field %>)); ?>
 
 		</div>
 	</div>
@@ -137,37 +137,32 @@ foreach ($relations as $alias => $details):
 	%>
 <div class="related row">
 	<div class="column large-12">
-	<h4 class="subheader"><%= "<%= __('Related " . $otherPluralHumanName . "') %>"; %></h4>
-	<%= "<% if (!empty(\$<%= $singularVar %>-><%= $details['property'] %>)): %>\n"; %>
+	<h4 class="subheader"><?= __('Related <%= $otherPluralHumanName %>') ?></h4>
+	<?php if (!empty($<%= $singularVar %>-><%= $details['property'] %>)): ?>
 	<table cellpadding="0" cellspacing="0">
 		<tr>
-<%
-			foreach ($details['fields'] as $field) {
-				echo "\t\t\t<th><%= __('" . Inflector::humanize($field) . "') %></th>\n";
-			}
-%>
-			<th class="actions"><%= "<%= __('Actions') %>"; %></th>
+<% foreach ($details['fields'] as $field): %>
+			<th><?= __('<%= Inflector::humanize($field) %>') ?></th>
+<% endforeach; %>
+			<th class="actions"><?= __('Actions') ?></th>
 		</tr>
-<%
-echo "\t\t<% foreach (\$<%= $singularVar %>-><%= $details['property'] %> as \$<%= $otherSingularVar %>): %>\n";
-		echo "\t\t<tr>\n";
-			foreach ($details['fields'] as $field) {
-				echo "\t\t\t<td><%= h(\$<%= $otherSingularVar %>-><%= $field %>) %></td>\n";
-			}
-
-			$otherPk = "\$<%= $otherSingularVar %>-><%= $details['primaryKey'][0] %>";
+		<?php foreach ($<%= $singularVar %>-><%= $details['property'] %> as $<%= $otherSingularVar %>): ?>
+		<tr>
+			<% foreach ($details['fields'] as $field): %>
+			<td><?= h($<%= $otherSingularVar %>-><%= $field %>) ?></td>
+			<% endforeach; %>
 
-			echo "\t\t\t<td class=\"actions\">\n";
-			echo "\t\t\t\t<%= \$this->Html->link(__('View'), ['controller' => '<%= $details['controller'] %>', 'action' => 'view', <%= $otherPk %>]) %>\n";
-			echo "\t\t\t\t<%= \$this->Html->link(__('Edit'), ['controller' => '<%= $details['controller'] %>', 'action' => 'edit', <%= $otherPk %>]) %>\n";
-			echo "\t\t\t\t<%= \$this->Form->postLink(__('Delete'), ['controller' => '<%= $details['controller'] %>', 'action' => 'delete', <%= $otherPk %>], ['confirm' => __('Are you sure you want to delete # <%= 0 %>?', <%= $otherPk %>)]) %>\n";
-			echo "\t\t\t</td>\n";
-		echo "\t\t</tr>\n";
+			<% $otherPk = "\${$otherSingularVar}->{$details['primaryKey'][0]}"; %>
+			<td class="actions">
+				<?= $this->Html->link(__('View'), ['controller' => '<%= $details['controller'] %>', 'action' => 'view', <%= $otherPk %>]) %>\n";
+				<?= $this->Html->link(__('Edit'), ['controller' => '<%= $details['controller'] %>', 'action' => 'edit', <%= $otherPk %>]) %>\n";
+				<?= $this->Form->postLink(__('Delete'), ['controller' => '<%= $details['controller'] %>', 'action' => 'delete', <%= $otherPk %>], ['confirm' => __('Are you sure you want to delete # <%= 0 %>?', <%= $otherPk %>)]) %>\n";
+			</td>
+		</tr>
 
-echo "\t\t<% endforeach; %>\n";
-%>
+		<?php endforeach; ?>
 	</table>
-<%= "\t<% endif; %>\n"; %>
+	<?php endif; ?>
 	</div>
 </div>
 <% endforeach; %>

+ 2 - 0
src/View/BakeView.php

@@ -14,10 +14,12 @@
  */
 namespace Cake\View;
 
+use Cake\Core\ConventionsTrait;
 use Cake\Utility\Inflector;
 
 class BakeView extends View {
 
+	use ConventionsTrait;
 /**
  * An array of names of built-in helpers to include.
  *

+ 1 - 1
tests/TestCase/Shell/Task/SimpleBakeTaskTest.php

@@ -54,7 +54,7 @@ class SimpleBakeTaskTest extends TestCase {
 
 		$this->Task->expects($this->any())
 			->method('template')
-			->will($this->returnValue('behavior'));
+			->will($this->returnValue('Model/behavior'));
 
 		$this->Task->expects($this->any())
 			->method('fileName')

+ 0 - 1
tests/bake_compare/Controller/Actions.ctp

@@ -1,4 +1,3 @@
-
 /**
  * Index method
  *