public function assertRestfulRoutesFor($controller_name, $options = array()) { $options['options'] = isset($options['options']) ? $options['options'] : array(); $options['options']['controller'] = isset($options['options']['controller']) ? $options['controller'] : $controller_name; if (!empty($options['shallow'])) { $options['shallow_options'] = isset($options['shallow_options']) ? $options['shallow_options'] : array(); $options['shallow_options']['controller'] = $options['options']['controller']; } else { $options['shallow_options'] = $options['options']; } $add_action = AkResource::getResourcePathNameFor('add', 'add'); $edit_action = AkResource::getResourcePathNameFor('edit', 'edit'); if (!empty($options['path_names'])) { if (isset($options['path_names']['add'])) { $add_action = $options['path_names']['add']; } if (isset($options['path_names']['edit'])) { $edit_action = $options['path_names']['edit']; } } $options['path_prefix'] = isset($options['path_prefix']) ? $options['path_prefix'] : ''; $path = isset($options['as']) ? $options['as'] : $controller_name; $collection_path = '/' . $options['path_prefix'] . $path; $shallow_path = '/' . (isset($options['shallow']) ? @$options['module'] : $options['path_prefix']) . $path; $member_path = $shallow_path . '/1'; $add_path = $collection_path . '/' . $add_action; $edit_member_path = $member_path . '/' . $edit_action; $formatted_edit_member_path = $member_path . '/' . $edit_action . '.xml'; if (!empty($options['options'])) { $this->assertRouting($collection_path, array_merge($options['options'], array('action' => 'index'))); $this->assertRouting($add_path, array_merge($options['options'], array('action' => 'add'))); $this->assertRouting($collection_path . '.xml', array_merge($options['options'], array('action' => 'index', 'format' => 'xml'))); $this->assertRouting($add_path . '.xml', array_merge($options['options'], array('action' => 'add', 'format' => 'xml'))); } if (!empty($options['shallow_options'])) { $this->assertRouting($member_path, array_merge($options['shallow_options'], array('action' => 'show', 'id' => 1))); $this->assertRouting($edit_member_path, array_merge($options['shallow_options'], array('action' => 'edit', 'id' => 1))); $this->assertRouting($member_path . '.xml', array_merge($options['shallow_options'], array('action' => 'show', 'id' => 1, 'format' => 'xml'))); $this->assertRouting($formatted_edit_member_path, array_merge($options['shallow_options'], array('action' => 'edit', 'id' => 1, 'format' => 'xml'))); } $this->assertRecognizes(array_merge($options['options'], array('action' => 'index', 'controller' => $controller_name)), array('path' => $collection_path, 'method' => 'get')); $this->assertRecognizes(array_merge($options['options'], array('action' => 'add', 'controller' => $controller_name)), array('path' => $add_path, 'method' => 'get')); $this->assertRecognizes(array_merge($options['options'], array('action' => 'create', 'controller' => $controller_name)), array('path' => $collection_path, 'method' => 'post')); $this->assertRecognizes(array_merge($options['shallow_options'], array('action' => 'show', 'controller' => $controller_name, 'id' => 1)), array('path' => $member_path, 'method' => 'get')); $this->assertRecognizes(array_merge($options['shallow_options'], array('action' => 'edit', 'controller' => $controller_name, 'id' => 1)), array('path' => $edit_member_path, 'method' => 'get')); $this->assertRecognizes(array_merge($options['shallow_options'], array('action' => 'update', 'controller' => $controller_name, 'id' => 1)), array('path' => $member_path, 'method' => 'put')); $this->assertRecognizes(array_merge($options['shallow_options'], array('action' => 'destroy', 'controller' => $controller_name, 'id' => 1)), array('path' => $member_path, 'method' => 'delete')); $this->assertRecognizes(array_merge($options['options'], array('action' => 'index', 'controller' => $controller_name, 'format' => 'xml')), array('path' => $collection_path . '.xml', 'method' => 'get')); $this->assertRecognizes(array_merge($options['options'], array('action' => 'add', 'controller' => $controller_name, 'format' => 'xml')), array('path' => $add_path . '.xml', 'method' => 'get')); $this->assertRecognizes(array_merge($options['options'], array('action' => 'create', 'controller' => $controller_name, 'format' => 'xml')), array('path' => $collection_path . '.xml', 'method' => 'post')); $this->assertRecognizes(array_merge($options['shallow_options'], array('action' => 'show', 'controller' => $controller_name, 'id' => 1, 'format' => 'xml')), array('path' => $member_path . '.xml', 'method' => 'get')); $this->assertRecognizes(array_merge($options['shallow_options'], array('action' => 'edit', 'controller' => $controller_name, 'id' => 1, 'format' => 'xml')), array('path' => $formatted_edit_member_path, 'method' => 'get')); $this->assertRecognizes(array_merge($options['shallow_options'], array('action' => 'update', 'controller' => $controller_name, 'id' => 1, 'format' => 'xml')), array('path' => $member_path . '.xml', 'method' => 'put')); $this->assertRecognizes(array_merge($options['shallow_options'], array('action' => 'destroy', 'controller' => $controller_name, 'id' => 1, 'format' => 'xml')), array('path' => $member_path . '.xml', 'method' => 'delete')); }